如何使用zend_search_lucene构建像google一样搜索的功能?

时间:2012-06-04 10:10:58

标签: php lucene full-text-search search-engine zend-search-lucene

我正在使用zend_search_lucene在文档中搜索关键字。 在其中一个文档中,它有短语This taught me a valuable lesson in time management as I still had to attend lectures and tutorials during the day. I enjoyed improving my telephone manner and learning to deal with different reactions to my requests for donations.

现在,如果搜索“有关时间管理的宝贵课程”,它什么都没有。我使用下面的代码来搜索它。

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());

$index = new Zend_Search_Lucene('/home/project/mgh/data/search_file/lucene.customer.index');

 Zend_Search_Lucene::getDefaultSearchField('contents');

    $results = $index->find('contents:"valuable lesson on cost management" ');

    $this->count=count($results);

在上面的示例中,只有不匹配,代替'in'有'on'但剩余的单词匹配。 如果几个单词匹配,如何获得结果计数(即使几个单词不匹配)?

感谢您的建议。

参考:http://framework.zend.com/manual/en/zend.search.lucene.query-language.html

2 个答案:

答案 0 :(得分:0)

问题不在于zend_search_lucene,而在于Lucene如何索引您的数据。我建议您阅读Solr文档中的Analyzers, Tokenizers, and Token Filters以了解其工作原理。如果你发布schema.xml信息(你在哪里定义哪些信息应该被编入索引以及以哪种方式),它也会有所帮助。

答案 1 :(得分:0)

这里的关键可能是停用词。如果你有' in' ' on'定义为停用词(Lucene会忽略,因为它们太常见),然后您的查询有关时间管理的宝贵课程'将符合时间管理方面的宝贵经验教训'文档文本部分。

相关问题