所以,我有两个我正在编制索引的字段:
| NAME | TYPE |
-------------------------------------
|Texas Steak | Restaurant |
|Bone Digs Restaurant | Restaurant |
|Rain Sushi | Restaurant |
|Brazil Steakhouse | Restaurant |
|Alfredos | Restaurant |
|Mediterranean Corner | Restaurant |
|Korean Taqueria | Restaurant |
|Orlando Cantina | Restaurant |
|Boomer Bar and Grill | Restaurant |
|Top Spice | Restaurant |
|Tamarind | Restaurant |
我按以下方式编制索引:
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());
//let lucene search for numbers as well as words
try {
$index = Zend_Search_Lucene::create('data/');
} catch(Zend_Search_Lucene_Exception $e){
echo "Unable {$e->getMessage()}";
}
$mdlPage = new Application_Model_DbTable_Business();
$currentPages = $mdlPage->fetchAll();
if($currentPages->count() >= 0) {
foreach ($currentPages as $p) {
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::text('business_name', $p->business_name));
$doc->addField(Zend_Search_Lucene_Field::text('primary_category',$p->primary_category));
$index->addDocument($doc);
}
}
$index->commit();
$index->optimize();
$this->view->indexSize = $index->numDocs();
现在,我正在以下列方式查询索引:
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
$query->addTerm(new Zend_Search_Lucene_Index_Term($keyword,'business_name'),null);
$query->addTerm(new Zend_Search_Lucene_Index_Term($keyword,'primary_category'),null);
echo $query;
try {
$results = $index->find($query);
}
catch (Zend_Search_Lucene_Exception $e) {
echo "Unable {$e->getMessage()}";
}
这是奇怪的事情。如果我查询'thai'或字段business_name中的任何单词,我会得到结果。但是一旦我查询“餐馆”,我的屏幕就无法解决,而是白屏。如果我将我的代码更改为:
$query = new Zend_Search_Lucene_Search_Query_MultiTerm();
//$query->addTerm(new Zend_Search_Lucene_Index_Term($keyword,'business_name'),null);
$query->addTerm(new Zend_Search_Lucene_Index_Term($keyword,'primary_category'),null);
然后我得到了结果。我不明白Lucene不喜欢什么。这是我的数据吗?是我如何创建我的查询?或者我是如何创建索引的?