Lucene search match any word at phrase

前端 未结 1 763
情歌与酒
情歌与酒 2021-01-28 19:19

i wanna search a string with lots of words, and retrieves documents that matches with any of them. My indexing method is the folowing:

 Document document = new D         


        
1条回答
  •  长情又很酷
    2021-01-28 19:55

    Using createPhraseQuery("termos", "list of words") will precisely try to match the phrase "list of words" with a phrase slop of 0.

    If you want to match any term in a list of words, you can use createBooleanQuery :

    new QueryBuilder(analyzer).createBooleanQuery("termos", terms, BooleanClause.Occur.SHOULD);
    

    As an alternative, you can also use createMinShouldMatchQuery() so that you can require a fraction of the number of query terms to match, eg. to match at least 10 percent of the terms :

    new QueryBuilder(analyzer).createMinShouldMatchQuery("termos", terms, 0.1f));
    

    0 讨论(0)
提交回复
热议问题