Displaying sample text from the Lucene Search Resu

2019-03-03 07:17发布

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条回答
爷、活的狠高调
2楼-- · 2019-03-03 07:40

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.

查看更多
登录 后发表回答