Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
91ee810a
Commit
91ee810a
authored
Jul 24, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
c1709bea
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
181 additions
and
0 deletions
+181
-0
Indexer.php
lib/Doctrine/Search/Indexer.php
+59
-0
Dir.php
lib/Doctrine/Search/Indexer/Dir.php
+47
-0
Exception.php
lib/Doctrine/Search/Indexer/Exception.php
+34
-0
Parser.php
lib/Doctrine/Search/Parser.php
+41
-0
No files found.
lib/Doctrine/Search/Indexer.php
View file @
91ee810a
...
...
@@ -32,5 +32,64 @@
*/
class
Doctrine_Search_Indexer
{
public
function
indexDirectory
(
$dir
)
{
if
(
!
file_exists
(
$dir
))
{
throw
new
Doctrine_Search_Indexer_Exception
(
'Unknown directory '
.
$dir
);
}
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
$q
=
new
Doctrine_Query
();
$q
->
delete
()
->
from
(
'Doctrine_Search_File f'
)
->
where
(
'f.url LIKE ?'
,
array
(
$dir
.
'%'
))
->
execute
();
// clear the index
$q
=
new
Doctrine_Query
();
$q
->
delete
()
->
from
(
'Doctrine_Search_File_Index i'
)
->
where
(
'i.foreign_id = ?'
)
->
execute
();
$conn
=
Doctrine_Manager
::
connection
();
$coll
=
new
Doctrine_Collection
(
'Doctrine_Search_File'
);
foreach
(
$it
as
$file
)
{
$coll
[]
->
url
=
$file
->
getFilePath
();
}
$coll
->
save
();
foreach
(
$coll
as
$record
)
{
$this
->
updateIndex
(
$record
);
}
}
public
function
updateIndex
(
Doctrine_Record
$record
)
{
$fields
=
array
(
'url'
,
'content'
);
$class
=
'Doctrine_Search_File_Index'
;
foreach
(
$fields
as
$field
)
{
$data
=
$record
->
get
(
$field
);
$terms
=
$this
->
analyze
(
$data
);
foreach
(
$terms
as
$pos
=>
$term
)
{
$index
=
new
$class
();
$index
->
keyword
=
$term
;
$index
->
position
=
$pos
;
$index
->
field
=
$field
;
$index
->
$name
=
$record
;
$index
->
save
();
}
}
}
}
lib/Doctrine/Search/Indexer/Dir.php
0 → 100644
View file @
91ee810a
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Search_Indexer_Dir
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Search_Indexer_Dir
{
public
function
add
(
$dir
)
{
if
(
!
file_exists
(
$dir
))
{
throw
new
Doctrine_Search_Indexer_Exception
(
'Unknown directory '
.
$dir
);
}
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
$this
->
indexFile
(
$file
);
}
}
}
lib/Doctrine/Search/Indexer/Exception.php
0 → 100644
View file @
91ee810a
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Search_Indexer
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Search_Indexer_Exception
extends
Doctrine_Search_Exception
{
}
lib/Doctrine/Search/Parser.php
0 → 100644
View file @
91ee810a
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Search_Parser_Standard
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Search_Parser
{
public
function
parse
(
$file
)
{
$contents
=
file_get_contents
(
$file
);
return
array
(
'url'
=>
$file
,
'contents'
=>
$contents
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment