better checking for correct search term

This commit is contained in:
Uwe Steinmann 2013-06-17 10:50:31 +02:00
parent c2dc213acf
commit 9615623e1a

View File

@ -49,30 +49,35 @@ class SeedDMS_Lucene_Search {
* @return object instance of SeedDMS_Lucene_Search * @return object instance of SeedDMS_Lucene_Search
*/ */
function search($term, $owner, $status='', $categories=array(), $fields=array()) { /* {{{ */ function search($term, $owner, $status='', $categories=array(), $fields=array()) { /* {{{ */
$query = ''; $querystr = '';
if($fields) { if($fields) {
} else { } else {
if($term) if($term)
$query .= trim($term); $querystr .= trim($term);
} }
if($owner) { if($owner) {
if($query) if($querystr)
$query .= ' && '; $querystr .= ' && ';
$query .= 'owner:'.$owner; $querystr .= 'owner:'.$owner;
} }
if($categories) { if($categories) {
if($query) if($querystr)
$query .= ' && '; $querystr .= ' && ';
$query .= '(category:"'; $querystr .= '(category:"';
$query .= implode('" || category:"', $categories); $querystr .= implode('" || category:"', $categories);
$query .= '")'; $querystr .= '")';
} }
$hits = $this->index->find($query); try {
$recs = array(); $query = Zend_Search_Lucene_Search_QueryParser::parse($querystr);
foreach($hits as $hit) { $hits = $this->index->find($query);
$recs[] = array('id'=>$hit->id, 'document_id'=>$hit->document_id); $recs = array();
foreach($hits as $hit) {
$recs[] = array('id'=>$hit->id, 'document_id'=>$hit->document_id);
}
return $recs;
} catch (Zend_Search_Lucene_Search_QueryParserException $e) {
return array();
} }
return $recs;
} /* }}} */ } /* }}} */
} }
?> ?>