Zend_Search_Lucene范围查询错误

发布于 2024-09-01 07:50:22 字数 528 浏览 5 评论 0原文

我已经为每个文档设置了日期字段。 (关键字)

其中存储的值就是这种格式; 20100511

每次尝试执行范围查询时,都会收到以下错误:

date:[10000000 TO 20000000]

至少一个范围查询边界项 必须是非空术语

有人知道吗?

更新

我已经让它以编程方式工作。 这是否意味着解析器有错误?

$from  = new Zend_Search_Lucene_Index_Term('10000000', 'dateOfBirthMod');
$to    = new Zend_Search_Lucene_Index_Term('20000000', 'dateOfBirthMod');
$query = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);

I have set up each document with a date field. (keyword)

Values stored in it are in this format; 20100511

Each time I try to perform a ranged query, I get the following error:

date:[10000000 TO 20000000]

At least one range query boundary term
must be non-empty term

Anyone got a clue?

Update

I have gotten this to work programmatically.
Does that mean the parser is buggy?

$from  = new Zend_Search_Lucene_Index_Term('10000000', 'dateOfBirthMod');
$to    = new Zend_Search_Lucene_Index_Term('20000000', 'dateOfBirthMod');
$query = new Zend_Search_Lucene_Search_Query_Range($from, $to, true);

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

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

发布评论

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

评论(4

一梦浮鱼 2024-09-08 07:50:22

实际上,这更多的是一个有问题的默认值,而不是一个错误。您可以更改分析器以允许数字。事实上,您甚至可以编写自定义分析器。请参阅 http://framework.zend.com/manual/en /zend.search.lucene.extending.html

允许数字标记化的设置

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());

在 Zf 1.x 和 Zf 2.x 中

Zend\Search\Lucene\Analysis\Analyzer\Analyzer::setDefault(new Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive());

Actually, this is more of a questionable default, not a bug. You can change the analyzer to allow numbers. In fact, you can even write a custom analyzer. See http://framework.zend.com/manual/en/zend.search.lucene.extending.html

The setting for allowing numbers to be tokenized is

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive());

in Zf 1.x and in Zf 2.x

Zend\Search\Lucene\Analysis\Analyzer\Analyzer::setDefault(new Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive());
救赎№ 2024-09-08 07:50:22

显然这是查询解析器中的一个错误(顺便说一句,相当旧)。我建议您对该问题添加评论或打开一个新问题以确认该问题在 ZF 的 xx 版本中仍然发生。

Apparently it is a bug in the query parser (quite old btw). I would suggest that you either add a comment to that issue or open a new one to confirm that it is still happening in version x.x of the ZF.

沫尐诺 2024-09-08 07:50:22

我已经为这个错误做了一个解决方法,该方法源于名为 tokenize() 的方法,该方法不返回任何值,并且可以在 Zend/Search/Lucene/Analysis/Analyzer.php 中找到

您可以尝试将代码替换为如果您使用最新的 ZF 版本 (1.10.7),请执行以下操作。

public function tokenize($data, $encoding = '')
{
    $this->setInput($data, $encoding);

    $tokenList = array();
    /*
    while (($nextToken = $this->nextToken()) !== null) {
        $tokenList[] = $this->_input;
    }
    */
        $tokenList[] = new Zend_Search_Lucene_Analysis_Token( $this->_input, 1, 1 );

    return $tokenList;
}

我不知道它是否适用于旧版本。

I've made a workaround for this bug which stems from the method called tokenize() which does not return any value and which may be found in the Zend/Search/Lucene/Analysis/Analyzer.php

You can try to replace the code with the following one if you use the latest ZF release (1.10.7).

public function tokenize($data, $encoding = '')
{
    $this->setInput($data, $encoding);

    $tokenList = array();
    /*
    while (($nextToken = $this->nextToken()) !== null) {
        $tokenList[] = $this->_input;
    }
    */
        $tokenList[] = new Zend_Search_Lucene_Analysis_Token( $this->_input, 1, 1 );

    return $tokenList;
}

I don't know whether it works in older releases or not.

两相知 2024-09-08 07:50:22

首先,您必须将默认分析器更改为 TextNum,以在找到

ZF2 之前允许数字:

\ZendSearch\Lucene\Analysis\Analyzer\Analyzer::setDefault(new \ZendSearch\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive());

其次,您的日期字段必须是关键字,而不是文本。

First, you have to change default Analyzer to TextNum to allow number before finding

ZF2:

\ZendSearch\Lucene\Analysis\Analyzer\Analyzer::setDefault(new \ZendSearch\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive());

Second, your date field MUST be a keyword, not text.

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