zend_search_lucene 中面临的问题

发布于 2024-11-26 08:07:43 字数 2218 浏览 1 评论 0原文

我正在使用 Zend Lucene 搜索:

    ......
    $results = $test->fetchAll();

                   setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
          Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
                foreach ($results as $result) {
                    $doc = new Zend_Search_Lucene_Document();

                    // add Fields
                    $doc->addField(
                            Zend_Search_Lucene_Field::Text('testid', $result->id));
                    $doc->addField(
                            Zend_Search_Lucene_Field::Keyword('testemail', strtolower(($result->email))));
                    $doc->addField(
                            Zend_Search_Lucene_Field::Text('testconfirmdate', $result->confirmdate));
                    $doc->addField(
                            Zend_Search_Lucene_Field::Text('testcreateddate', $result->createddate));
                    // Add document to the index
                    $index->addDocument($doc);
                }
                // Optimize index.
                $index->optimize();

                // Search by query
                setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
                if(strlen($Data['name']) > 2){
                    //$query = Zend_Search_Lucene_Search_QueryParser::parse($Data['name'].'*');
                                    $pattern = new Zend_Search_Lucene_Index_Term($Data['name'].'*');
                                    $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
                                    $this->view->hits = $index->find(strtolower($query));
                            }
                else{
                    $query  = $Data['name'];
                                    $this->view->hits = $index->find($query);
                                }
............

这里工作​​正常:

  1. 当我给出完整的单词、前 3 个字符、不区分大小写的单词时,它可以工作

我的问题是:

  1. 当我搜索电子邮件时,我收到类似“通配符搜索仅支持非多个单词术语
  2. 当我搜索“1234”或09/06/2011等数字/日期时,我收到类似“至少 3模式开头需要非通配符”

我想在此处搜索日期、电子邮件、号码。

I am using Zend Lucene Search:

    ......
    $results = $test->fetchAll();

                   setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
          Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8());
                foreach ($results as $result) {
                    $doc = new Zend_Search_Lucene_Document();

                    // add Fields
                    $doc->addField(
                            Zend_Search_Lucene_Field::Text('testid', $result->id));
                    $doc->addField(
                            Zend_Search_Lucene_Field::Keyword('testemail', strtolower(($result->email))));
                    $doc->addField(
                            Zend_Search_Lucene_Field::Text('testconfirmdate', $result->confirmdate));
                    $doc->addField(
                            Zend_Search_Lucene_Field::Text('testcreateddate', $result->createddate));
                    // Add document to the index
                    $index->addDocument($doc);
                }
                // Optimize index.
                $index->optimize();

                // Search by query
                setlocale(LC_CTYPE, 'de_DE.iso-8859-1');
                if(strlen($Data['name']) > 2){
                    //$query = Zend_Search_Lucene_Search_QueryParser::parse($Data['name'].'*');
                                    $pattern = new Zend_Search_Lucene_Index_Term($Data['name'].'*');
                                    $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern);
                                    $this->view->hits = $index->find(strtolower($query));
                            }
                else{
                    $query  = $Data['name'];
                                    $this->view->hits = $index->find($query);
                                }
............

Works fine here:

  1. It works when I give complete word, first 3 character, case insensitive words

My issues are:

  1. When I search for email, i got error like "Wildcard search is supported only for non-multiple word terms "
  2. When I search for number/date like "1234" or 09/06/2011, I got error like "At least 3 non-wildcard characters are required at the beginning of pattern"

I want to search date, email, number here.

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

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

发布评论

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

评论(2

汹涌人海 2024-12-03 08:07:43

在文件 zend/search/Lucene/search/search/query/wildcard 中设置了一个参数,

private static $_minPrefixLength = 3;

更改它,它可能会工作..!

In file zend/search/Lucene/search/search/query/wildcard a parameter is set,

private static $_minPrefixLength = 3;

chnage it and it may work..!

静若繁花 2024-12-03 08:07:43

根据 NaanuManu 的建议,我做了更多的挖掘来解决这个问题 - 我在此处发布了我对相关问题的回答,但为了方便重复:

直接取自 Zend 参考文档,您可以使用:

  • Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength()
    查询所需的最小前缀长度并
  • 使用 Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength()
    设置它。

所以我的建议是以下两种情况之一:

  1. 使用 Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0)

  2. 使用 JavaScript 或其他方式验证所有搜索查询,以确保至少有Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() 在使用任何通配符之前(我建议查询该通配符,而不是假设默认值“3”,以便验证灵活)

Based on NaanuManu's suggestion, I did a little more digging to figure this out - I posted my answer on a related question here, but repeating for convenience:

Taken directly from the Zend Reference documentation, you can use:

  • Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() to
    query the minimum required prefix length and
  • use Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength() to
    set it.

So my suggestion would be either of two things:

  1. Set the prefixMinLength to 0 using Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0)

  2. Validate all search queries using javascript or otherwise to ensure there is a minimum of Zend_Search_Lucene_Search_Query_Wildcard::getMinPrefixLength() before any wildcards used (I recommend querying that instead of assuming the default of "3" so the validation is flexible)

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