Lucene Query in Order
I have created lucene in java index and able to do searching. Now I want my query in such as way that it maintains order. Say for example I have following in my index
1 2 3 4 5
1 2 3 4 1
1 2 4 3 1
1 3 2 4 1
And my query is 1 3 4
then it should give result like :
1 2 3 4 5
1 2 3 4 1
1 3 2 4 1
1 2 4 3 1
Hope question is clear开发者_运维技巧.
Thanks, Ravi.
You can use span query to find terms that are in close proximity and are in specific order. The ordering condition can be relaxed. An excellent article on spans can be found here.
Can you use a BooleanQuery and be sure to call setAllowDocsOutOfOrder(true)
. If your index is ordered by docid, this should restrict the documents from becoming disordered.
Edit:
You could also use the Sort
class to order a search by index or relevance. This looks more useful as you can use any Query type in your search.
精彩评论