Zend框架Lucene布尔/“Google”样搜索 [英] Zend Framework Lucene Boolean / "Google"-like search

查看:108
本文介绍了Zend框架Lucene布尔/“Google”样搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 http://demos.zatechcorp.com/codeigniter/

在我的机器上运行的当前化身中,我在Codeigniter中加载了ZendFramework,并生成了一个索引,如下所示:

In its current incarnation running on my machine, I loaded the ZendFramework inside Codeigniter, and generated an index, like this:

    // ... Some code that loads all the markets
    foreach ($markets as $market)
    {
        $doc = new Zend_Search_Lucene_Document();
        // Id for retrieval
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', $market->id));
        // Store document URL to identify it in search result.
        $doc->addField(Zend_Search_Lucene_Field::Text('url', $market->permalink));
        // Index document content
        $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', $market->description));
        // Title
        $doc->addField(Zend_Search_Lucene_Field::Text('title', $market->title));
        // Phone
        $doc->addField(Zend_Search_Lucene_Field::Keyword('phone', $market->phone));
        // Fax
        $doc->addField(Zend_Search_Lucene_Field::Keyword('fax', $market->fax));
        // Street
        $doc->addField(Zend_Search_Lucene_Field::Keyword('street', $market->street));
        // City
        $doc->addField(Zend_Search_Lucene_Field::Keyword('city', $market->city));
        // State
        $doc->addField(Zend_Search_Lucene_Field::Keyword('state', $market->state));
        // Zip
        $doc->addField(Zend_Search_Lucene_Field::Keyword('zip', $market->zip));
        // Type
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('type', 'market'));

        // Store Document
        $index->addDocument($doc);
    }



在我的搜索中,我这样做:

In my search, I do this:

    $hits    = $index->find($q);

这是用简单的单词,但是当我想做一个搜索如Sheba Foods包括),它返回一个结果,但是错误的结果,甚至没有单词Sheba。

This works with simple words, but when I want to do a search like "Sheba Foods" (quotes included), it returns one result, but the wrong one, which doesn't even have the word "Sheba".

我从MySQL全文搜索它的明显问题,并且不能与此有任何进展。

I moved away from MySQL full-text search because of its obvious problems, and can't make any headway with this.

我一直在看着Zend_Search_Lucene_Search_QueryParser :: parse()方法。答案在于这个方法?

I've been looking at the Zend_Search_Lucene_Search_QueryParser::parse() method. Does the answer lie in this method?

推荐答案

我想出来了。使用Lucene,您可以添加名称为id的字段,但从匹配中检索id会给您不同的结果 - 我猜这是整个搜索结果中搜索字词的ID。

I figured it out. With Lucene, you can add a field with the name 'id', but retrieving id from a hit gives you something different -- I'll guess this is the id of the search term within the entire search results.

在这种情况下,我不得不使用不同的字段名称,例如:

What I had to do in this case was use a different field name like this:

    // Id for retrieval
    $doc->addField(Zend_Search_Lucene_Field::UnIndexed('item_id', $market->id));

这篇关于Zend框架Lucene布尔/“Google”样搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆