mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-13 13:11:31 +00:00
better checking for correct search term
This commit is contained in:
parent
c2dc213acf
commit
9615623e1a
|
@ -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;
|
|
||||||
} /* }}} */
|
} /* }}} */
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user