2

有一些使用 Zend Lucene 进行搜索的代码:

$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.'.$this->index_file));
$results = $index->find('PHP');
foreach ($results as $result) 
{
    echo $result->name;
    echo '<br/>';
}

它工作正常。但现在我需要添加“where”条件来搜索:“WHERE vacancy_state=1”。我该怎么做?谢谢。

4

1 回答 1

0

您需要创建查询。您可以将其作为文本执行或使用查询 API(ofc vancy_state 必须在您的索引中):

title:"PHP" AND vacancy_state:1

或者使用 API 应该是这样的:

    $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
    $query->addTerm(new Zend_Search_Lucene_Index_Term('PHP'), true);
    $query->addTerm(new Zend_Search_Lucene_Index_Term(1, 'vacancy_state'), true);
    $index->find($query);

或者

    $query = new Zend_Search_Lucene_Search_Query_Boolean();
    $term = new Zend_Search_Lucene_Index_Term('PHP');
    $subquery = new Zend_Search_Lucene_Search_Query_Term($term);
    $query->addSubquery($subquery, true);
    $term = new Zend_Search_Lucene_Index_Term(1, 'vacancy_state');
    $subquery = new Zend_Search_Lucene_Search_Query_Term($term);
    $query->addSubquery($subquery, true);
于 2013-08-13T08:12:37.170 回答