Zend lucene - search within range

旧城冷巷雨未停 提交于 2019-12-11 17:09:12

问题


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:


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]";


来源:https://stackoverflow.com/questions/5602709/zend-lucene-search-within-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!