Zend_Search_Lucene range query error
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 te开发者_JAVA技巧rm
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);
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());
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.
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.
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.
精彩评论