Commit 9b18cd42e3a679534da26b7110294735924bb4ea
1 parent
92286ccb
The PHP Lucene should now work as an alternative to the Java Lucene.
Committed by: Megan Watson
Showing
1 changed file
with
38 additions
and
20 deletions
search2/indexing/indexers/PHPLuceneIndexer.inc.php
| @@ -7,31 +7,31 @@ | @@ -7,31 +7,31 @@ | ||
| 7 | * Document Management Made Simple | 7 | * Document Management Made Simple |
| 8 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. | 8 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. |
| 9 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 9 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 10 | - * | 10 | + * |
| 11 | * This program is free software; you can redistribute it and/or modify it under | 11 | * This program is free software; you can redistribute it and/or modify it under |
| 12 | * the terms of the GNU General Public License version 3 as published by the | 12 | * the terms of the GNU General Public License version 3 as published by the |
| 13 | * Free Software Foundation. | 13 | * Free Software Foundation. |
| 14 | - * | 14 | + * |
| 15 | * This program is distributed in the hope that it will be useful, but WITHOUT | 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 18 | * details. | 18 | * details. |
| 19 | - * | 19 | + * |
| 20 | * You should have received a copy of the GNU General Public License | 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | - * | ||
| 23 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | 22 | + * |
| 23 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | ||
| 24 | * California 94120-7775, or email info@knowledgetree.com. | 24 | * California 94120-7775, or email info@knowledgetree.com. |
| 25 | - * | 25 | + * |
| 26 | * The interactive user interfaces in modified source and object code versions | 26 | * The interactive user interfaces in modified source and object code versions |
| 27 | * of this program must display Appropriate Legal Notices, as required under | 27 | * of this program must display Appropriate Legal Notices, as required under |
| 28 | * Section 5 of the GNU General Public License version 3. | 28 | * Section 5 of the GNU General Public License version 3. |
| 29 | - * | 29 | + * |
| 30 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 30 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 31 | * these Appropriate Legal Notices must retain the display of the "Powered by | 31 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 32 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 32 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 33 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 33 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 34 | - * must display the words "Powered by KnowledgeTree" and retain the original | 34 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 35 | * copyright notice. | 35 | * copyright notice. |
| 36 | * Contributor( s): ______________________________________ | 36 | * Contributor( s): ______________________________________ |
| 37 | * | 37 | * |
| @@ -67,9 +67,13 @@ class PHPLuceneIndexer extends Indexer | @@ -67,9 +67,13 @@ class PHPLuceneIndexer extends Indexer | ||
| 67 | } | 67 | } |
| 68 | catch(Exception $ex) | 68 | catch(Exception $ex) |
| 69 | { | 69 | { |
| 70 | - $this->lucene = null; | ||
| 71 | - if (!$catchException) | ||
| 72 | - throw $ex; | 70 | + if($ex->getMessage() == "Index doesn't exists in the specified directory."){ |
| 71 | + $this->lucene = new Zend_Search_Lucene($indexPath, true); | ||
| 72 | + }else { | ||
| 73 | + $this->lucene = null; | ||
| 74 | + if (!$catchException) | ||
| 75 | + throw $ex; | ||
| 76 | + } | ||
| 73 | } | 77 | } |
| 74 | } | 78 | } |
| 75 | 79 | ||
| @@ -94,13 +98,16 @@ class PHPLuceneIndexer extends Indexer | @@ -94,13 +98,16 @@ class PHPLuceneIndexer extends Indexer | ||
| 94 | */ | 98 | */ |
| 95 | private function addDocument($docid, $content, $discussion, $title, $version) | 99 | private function addDocument($docid, $content, $discussion, $title, $version) |
| 96 | { | 100 | { |
| 97 | - $doc = new Zend_Search_Lucene_Document(); | ||
| 98 | - $doc->addField(Zend_Search_Lucene_Field::Text('DocumentID', PHPLuceneIndexer::longToString($docid))); | ||
| 99 | - $doc->addField(Zend_Search_Lucene_Field::Text('Content', $content, 'UTF-8')); | ||
| 100 | - $doc->addField(Zend_Search_Lucene_Field::Text('Discussion', $discussion, 'UTF-8')); | ||
| 101 | - $doc->addField(Zend_Search_Lucene_Field::Text('Title', $title, 'UTF-8')); | ||
| 102 | - $doc->addField(Zend_Search_Lucene_Field::Text('Version', $version, 'UTF-8')); | ||
| 103 | - $this->lucene->addDocument($doc); | 101 | + $teaser = substr($content, 0, 250); |
| 102 | + | ||
| 103 | + $doc = new Zend_Search_Lucene_Document(); | ||
| 104 | + $doc->addField(Zend_Search_Lucene_Field::Text('DocumentID', PHPLuceneIndexer::longToString($docid))); | ||
| 105 | + $doc->addField(Zend_Search_Lucene_Field::Text('Content', $content, 'UTF-8')); | ||
| 106 | + $doc->addField(Zend_Search_Lucene_Field::unStored('Discussion', $discussion, 'UTF-8')); | ||
| 107 | + $doc->addField(Zend_Search_Lucene_Field::Text('Title', $title, 'UTF-8')); | ||
| 108 | + $doc->addField(Zend_Search_Lucene_Field::Text('Version', $version, 'UTF-8')); | ||
| 109 | + $doc->addField(Zend_Search_Lucene_Field::unIndexed('Summary', $teaser, 'UTF-8')); | ||
| 110 | + $this->lucene->addDocument($doc); | ||
| 104 | } | 111 | } |
| 105 | 112 | ||
| 106 | /** | 113 | /** |
| @@ -232,6 +239,7 @@ class PHPLuceneIndexer extends Indexer | @@ -232,6 +239,7 @@ class PHPLuceneIndexer extends Indexer | ||
| 232 | 239 | ||
| 233 | $document_id = PHPLuceneIndexer::stringToLong($document->DocumentID); | 240 | $document_id = PHPLuceneIndexer::stringToLong($document->DocumentID); |
| 234 | 241 | ||
| 242 | + /* | ||
| 235 | $coreText = ''; | 243 | $coreText = ''; |
| 236 | if ($queryContent) | 244 | if ($queryContent) |
| 237 | { | 245 | { |
| @@ -243,6 +251,11 @@ class PHPLuceneIndexer extends Indexer | @@ -243,6 +251,11 @@ class PHPLuceneIndexer extends Indexer | ||
| 243 | } | 251 | } |
| 244 | 252 | ||
| 245 | $content = $query->highlightMatches($coreText); | 253 | $content = $query->highlightMatches($coreText); |
| 254 | + */ | ||
| 255 | + | ||
| 256 | + $teaser = $document->Summary; | ||
| 257 | + | ||
| 258 | + $content = $query->highlightMatches($teaser); | ||
| 246 | 259 | ||
| 247 | $title = $document->Title; | 260 | $title = $document->Title; |
| 248 | $score = $hit->score; | 261 | $score = $hit->score; |
| @@ -250,6 +263,7 @@ class PHPLuceneIndexer extends Indexer | @@ -250,6 +263,7 @@ class PHPLuceneIndexer extends Indexer | ||
| 250 | // avoid adding duplicates. If it is in already, it has higher priority. | 263 | // avoid adding duplicates. If it is in already, it has higher priority. |
| 251 | if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) | 264 | if (!array_key_exists($document_id, $results) || $score > $results[$document_id]->Score) |
| 252 | { | 265 | { |
| 266 | + $item = new DocumentResultItem($document_id, $score, $title, $content); | ||
| 253 | $item = new QueryResultItem($document_id, $score, $title, $content); | 267 | $item = new QueryResultItem($document_id, $score, $title, $content); |
| 254 | if ($item->CanBeReadByUser) | 268 | if ($item->CanBeReadByUser) |
| 255 | { | 269 | { |
| @@ -284,4 +298,8 @@ class PHPLuceneIndexer extends Indexer | @@ -284,4 +298,8 @@ class PHPLuceneIndexer extends Indexer | ||
| 284 | return _kt('Document Indexer Library'); | 298 | return _kt('Document Indexer Library'); |
| 285 | } | 299 | } |
| 286 | } | 300 | } |
| 287 | -?> | 301 | + |
| 302 | + public function isDocumentIndexed($documentId){ | ||
| 303 | + // do something | ||
| 304 | + } | ||
| 305 | +?> | ||
| 288 | \ No newline at end of file | 306 | \ No newline at end of file |