为什么我在 Lucene (zend) 中的 2 个字段搜索失败?

发布于 2024-10-01 10:41:30 字数 2219 浏览 5 评论 0原文

因此,我有两个正在索引的字段:

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

So, I have two fields I am indexing:

| 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 |

I am indexing in the following fashion:

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();

Now, I am querying the index in the following fashion:

$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()}";
}

Here is the odd thing. If I query for 'thai' or any word that is in field business_name I get results. But once I query for 'restaurant' my screen does not resolve but to a white screen. If I change my code to this:

$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);

Then I do get results. I don't get what Lucene does not like. Is it my data? Is it how I am creating my query? Or is it how I am creating my index?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文