Zend Lucene - 如何进行查询

发布于 2024-10-19 14:50:48 字数 1018 浏览 0 评论 0原文

我的创建索引函数如下所示

function create()
{
    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive ());
    $index = Zend_Search_Lucene::create('data/index');      
    $doc = new Zend_Search_Lucene_Document();

    $doc->addField(Zend_Search_Lucene_Field::Text('title', 'a cheap car in town milage under 3000','utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('detail','a cheap car in town milage under 3000','utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('category', 'milage under 3000','utf-8'));

    $index->addDocument($doc);
}

当用户搜索“城镇里程低于3000的廉价汽车”时,我会将查询分为

$query1 = "a cheap car";
$query2 = "in town";
$query3 = " milage under 3000";

我要搜索的

$query1 in field "title", $query2 in field "detail", $query3 in field "category". 

3部分我也想搜索数字不区分大小写和文本不区分大小写。我该怎么做呢?我需要实际的代码,因为我对 Zend Lucene 文档完全感到困惑,我不知道要使用哪个代码或查询。

My create index function is as bellow

function create()
{
    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive ());
    $index = Zend_Search_Lucene::create('data/index');      
    $doc = new Zend_Search_Lucene_Document();

    $doc->addField(Zend_Search_Lucene_Field::Text('title', 'a cheap car in town milage under 3000','utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('detail','a cheap car in town milage under 3000','utf-8'));
    $doc->addField(Zend_Search_Lucene_Field::Text('category', 'milage under 3000','utf-8'));

    $index->addDocument($doc);
}

When user search for "a cheap car in town milage under 3000", I will split the query into 3 parts

$query1 = "a cheap car";
$query2 = "in town";
$query3 = " milage under 3000";

I want to search

$query1 in field "title", $query2 in field "detail", $query3 in field "category". 

I also want to search number case insensitive and text case insensitive. How can I do it? I would need the actual code because I'm completely confused by the Zend Lucene docs, I don't know which code or query to use.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2024-10-26 14:50:49

您的查询将是:

$query = Zend_Search_Lucene_Search_QueryParser::parse("title:($query1) detail:($query2) category:($query3)";
$hits = $index->find( $query);

索引不区分大小写,除非在创建时明确设置为区分大小写。

your query will be:

$query = Zend_Search_Lucene_Search_QueryParser::parse("title:($query1) detail:($query2) category:($query3)";
$hits = $index->find( $query);

Index is case-insensitive, unless explicitly set to case sensitive upon creation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文