How does Zend Lucene handle numeric range searches?

328 Views Asked by At

I have this fields in the index

id    name                   genders          ages
1     "John Doe and Co."     "male male"      "18 20" 
2     'Mr. and Mrs. Joe Dee' "male female"    "25 27"

and here is the code to retrieve both rows

$min_age = '19'
$max_age = '26';

$ages_query = new Zend_Search_Lucene_Search_Query_Range(new Zend_Search_Lucene_Index_Term($min_age, 'ages'), new Zend_Search_Lucene_Index_Term($max_age, 'ages'), TRUE);

$lucene_query = new Zend_Search_Lucene_Search_Query_Boolean();
$lucene_query->addSubquery($ages_query, null);

I only return the second row. Why did I not get the first row when it clearly should be returned based on the range query?

1

There are 1 best solutions below

0
On BEST ANSWER

This is wrong format for ages field, you should break into two fields

age_from : 18
age_to   : 20

Query :-

 +age_from:[19 TO *]
 +age_to:[* TO 26 *]

I not sure you related to this question or not : Zend Lucene and range search on a field with multiple values

But the idea is do not store CSV into lucene.