Displaying sample text from the Lucene Search Results

隐身守侯 提交于 2019-12-02 08:53:26

问题


Currently, I am using Lucene version 3.0.2 to create a search application that is similar to a dictionary. One of the objects that I want to display is a sort of "example", where Lucene would look for a word in a book and then the sentences where the words were used are displayed.

I've been reading the Lucene in Action book and it mentions something like this, but looking through it I can't find other mentions. Is this something you can do with Lucene? If it is, how is can you do it?


回答1:


I believe what you are looking for is a Highlighter.

One possibility is to use the lucene.search.highlight package, specifically the Highlighter.

Another option is to use the lucene.search.vectorhighlight package, specifically the FastVectorHighlighter.

Both classes search a text document, choose relevant snippets and display them with the matching terms highlighted. I have only used the first one, which worked fine for my use-case. If you can pre-divide the book into shorter parts, it would make highlighting faster.



来源:https://stackoverflow.com/questions/3652672/displaying-sample-text-from-the-lucene-search-results

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