2011-03-10 14:12:06 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of search in lucene index
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS_Lucene
|
2011-03-10 14:12:06 +00:00
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010, Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for searching in a lucene index.
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS_Lucene
|
2011-03-10 14:12:06 +00:00
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2011, Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2013-02-14 11:10:53 +00:00
|
|
|
class SeedDMS_Lucene_Search {
|
2011-03-10 14:12:06 +00:00
|
|
|
/**
|
|
|
|
* @var object $index lucene index
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
protected $index;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance of the search
|
|
|
|
*
|
|
|
|
* @param object $index lucene index
|
2013-02-14 11:10:53 +00:00
|
|
|
* @return object instance of SeedDMS_Lucene_Search
|
2011-03-10 14:12:06 +00:00
|
|
|
*/
|
|
|
|
function __construct($index) { /* {{{ */
|
|
|
|
$this->index = $index;
|
|
|
|
$this->version = '@package_version@';
|
|
|
|
if($this->version[0] == '@')
|
|
|
|
$this->version = '3.0.0';
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search in index
|
|
|
|
*
|
|
|
|
* @param object $index lucene index
|
2013-02-14 11:10:53 +00:00
|
|
|
* @return object instance of SeedDMS_Lucene_Search
|
2011-03-10 14:12:06 +00:00
|
|
|
*/
|
2012-10-09 09:57:28 +00:00
|
|
|
function search($term, $owner, $status='', $categories=array(), $fields=array()) { /* {{{ */
|
2013-06-17 08:50:31 +00:00
|
|
|
$querystr = '';
|
2012-10-09 09:57:28 +00:00
|
|
|
if($fields) {
|
|
|
|
} else {
|
|
|
|
if($term)
|
2013-06-17 08:50:31 +00:00
|
|
|
$querystr .= trim($term);
|
2012-10-09 09:57:28 +00:00
|
|
|
}
|
2011-03-10 14:12:06 +00:00
|
|
|
if($owner) {
|
2013-06-17 08:50:31 +00:00
|
|
|
if($querystr)
|
|
|
|
$querystr .= ' && ';
|
|
|
|
$querystr .= 'owner:'.$owner;
|
2011-03-10 14:12:06 +00:00
|
|
|
}
|
|
|
|
if($categories) {
|
2013-06-17 08:50:31 +00:00
|
|
|
if($querystr)
|
|
|
|
$querystr .= ' && ';
|
|
|
|
$querystr .= '(category:"';
|
|
|
|
$querystr .= implode('" || category:"', $categories);
|
|
|
|
$querystr .= '")';
|
2011-03-10 14:12:06 +00:00
|
|
|
}
|
2013-06-17 08:50:31 +00:00
|
|
|
try {
|
|
|
|
$query = Zend_Search_Lucene_Search_QueryParser::parse($querystr);
|
2013-08-13 18:20:12 +00:00
|
|
|
try {
|
|
|
|
$hits = $this->index->find($query);
|
|
|
|
$recs = array();
|
|
|
|
foreach($hits as $hit) {
|
|
|
|
$recs[] = array('id'=>$hit->id, 'document_id'=>$hit->document_id);
|
|
|
|
}
|
|
|
|
return $recs;
|
|
|
|
} catch (Zend_Search_Lucene_Exception $e) {
|
2013-08-13 20:08:47 +00:00
|
|
|
return false;
|
2013-06-17 08:50:31 +00:00
|
|
|
}
|
|
|
|
} catch (Zend_Search_Lucene_Search_QueryParserException $e) {
|
2013-08-13 20:08:47 +00:00
|
|
|
return false;
|
2011-03-10 14:12:06 +00:00
|
|
|
}
|
|
|
|
} /* }}} */
|
|
|
|
}
|
|
|
|
?>
|