Lucene search match any word at phrase

别说谁变了你拦得住时间么 提交于 2019-12-02 10:25:47

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