Zend lucene - search within range

2019-09-01 18:54发布

I have the following code to create the Zend Lucene index

        $doc->addField(Zend_Search_Lucene_Field::UnStored('keywords', $job->getKeywords()));
        $doc->addField(Zend_Search_Lucene_Field::UnStored('title', $job->getTitle()));
        $doc->addField(Zend_Search_Lucene_Field::UnStored('region', $job->getRegion()));
        $doc->addField(Zend_Search_Lucene_Field::keyword('minSalary', $minSalary));
        $doc->addField(Zend_Search_Lucene_Field::keyword('maxSalary', $maxSalary));
        $doc->addField(Zend_Search_Lucene_Field::UnStored('type', $job->getType()));

and my search query is

$query = 'minSalary:[0 TO 20000]';

Here I am trying to get all jobs whose minSalary is equal or less than 20000. But the result I get has jobs with following minSalary values

110000
100000
20000
10000

Can anyone advice on this?

Thanks B

1条回答
三岁会撩人
2楼-- · 2019-09-01 19:34

I suggest to use strings instead of numeric values. Convert all numeric values (e.g. 1000) in strings with the same length (e.g. 0001000) during the indexing process. So, if you want to search for a minSalary from 0 to 20000, your query string has to look like this:

$query = "minSalary:[0000000 TO 0020000]";
查看更多
登录 后发表回答