我使用zend lucene進行搜索。 我形成我的索引與該代碼zend lucene接近字段開頭
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::text('word_id', $word['id']));
$boostField = Zend_Search_Lucene_Field::text('priority', $word['priority']);
$doc->addField($boostField);
$doc->addField(Zend_Search_Lucene_Field::unStored('description', $word['name'], 'UTF-8'));
$index->addDocument($doc);
與代碼解析搜索字符串:
$query= str_replace(array('-','!','@','#','$','%','^','&','*','(',')'), ' ', $query);
$query = trim($query);
$words = explode(" ", $query);
unset($query);
$query = "";
foreach ($words as $word) {
$query.='(' . $word . '*)';
if ($word != end($words)) {
$query.=' AND ';
}
}
return $query;
有了這樣的代碼搜索:
try {
Zend_Search_Lucene::setResultSetLimit($limit);
$index = Zend_Search_Lucene::open($this->_indexPath);
} catch (Exception $e) {
return false;
}
try {
return $index->find($query, 'score', SORT_NUMERIC, SORT_DESC, 'priority', SORT_NUMERIC, SORT_ASC);
} catch (Exception $e) {
return false;
}
所以,我的問題,我有索引一些領域,如:nootebook黑色包,nootebook藍色包,nootebook,nootebook蘋果。 例如我輸入「筆記本」,我想要「nootebook,nootebook蘋果」的頂部結果。 但我有最好的結果袋!我做錯了什麼?我需要做的是從搜索字段的起始位置獲得最大近距離位置的結果? 有可能嗎?
你能否解釋一下「筆記本蘋果」和「黑色筆記本包」之間應該做什麼邏輯區分,只要與查詢「筆記本」相關? – femtoRgon
在「筆記本蘋果」一詞中「筆記本」最大接近左側。在「筆記本黑包」一詞中,「筆記本」離左側很遠。我想進行搜索,基於左邊是多麼接近的詞是什麼。 –