我在Lucene中编写了一个索引搜索器,它将在索引数据库中搜索多个字段。
我编写了以下代码。
public function actionInd(){
$index = Lucene::open(Yii::$app->basePath."/search");
$res = $index->find('name:pr AND id:2');
foreach ($res as $hit){
$document = $hit->getDocument();
echo "<br>";echo "<br>";
print_r($document->getFieldValue('id'));
echo "<br>";
print_r($document->getFieldValue('name'));
}
}
public function actionCreate(){
$index = Lucene::open(Yii::$app->basePath."/search");
$doc = new Document();
$doc->addField(Field::Text('id', 3));
$doc->addField(Field::Text('name', 'pr'));
$doc->addField(Field::Text('title', 'prajapati'));
$doc->addField(Field::keyword('key', 3));
$index->addDocument($doc);
}
当调用ind动作输出时显示:1个公关AND条件不起作用。
我认为发出查询的方式是:
$query = Zend\Search\Lucene\Search\QueryParser::parse('name:pr AND id:2', 'iso-8859-5');
//or without char-encoding
$query = Zend\Search\Lucene\Search\QueryParser::parse('name:pr AND id:2');
$hits = $index->find($query);