2

所以,我有两个要索引的字段:

| 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 不喜欢什么。是我的数据吗?这是我创建查询的方式吗?还是我创建索引的方式?

4

0 回答 0