Why is this Lucene query a “contains” instead of a “startsWith”?

落爺英雄遲暮 提交于 2019-12-05 10:43:36

StandardAnalyzer will tokenize "Fleet Africa" into "fleet" and "africa". Your a* search will match the later term.

If you want to consider "Fleet Africa" as one single term, use an analyzer that does not break up your string on whitespaces. KeywordAnalyzer is an example, but you may still want to lowercase your data so queries are case insensitive.

Yuval F

The short answer: all your queries do not constrain the search to the start of the field. You need an EdgeNGramTokenFilter or something like it. See this question for an implementation of autocomplete in Lucene.

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