Search in Single-Token-Field using Lucene.NET

。_饼干妹妹 提交于 2019-12-25 03:15:30

问题


I´m using Lucene.NET 3.0.3 for indexing the content of word-, excel-, etc. documents and some custom fields for each document.
If I index a field named "title" as Field.Index.NOT_ANALYZED the Lucene-Index stored the field in correct form. The hole title is stored in a single token. That´s what I want.

e.g. title of document is "Lorem ipsum dolor"
field in Lucene-index: "Lorem ipsum dolor"

If I search using exact search in this field I get no results.
My searchterm looks like: title:"Lorem ipsum dolor"
For searching i´m use the same StandardAnalzer.

Why I can´t find the document?


回答1:


StandardAnalyzer is sensitive to whitespace, among other delimiters. That is, it tokenizes the search term into three tokens:

( Lorem, ipsum, dolor )

But you indexed field title using Field.Index.NOT_ANALYZED so none of the three tokens above can match the single token in this field:

( Lorem ipsum dolor )

Use KeywordAnalyzer, which tokenizes the entire field value as a single token. As always, you need to use the same analyzer for both indexing and searching.



来源:https://stackoverflow.com/questions/19836528/search-in-single-token-field-using-lucene-net

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