简体   繁体   English

显示Lucene搜索结果中的示例文本

[英]Displaying sample text from the Lucene Search Results

Currently, I am using Lucene version 3.0.2 to create a search application that is similar to a dictionary. 当前,我正在使用Lucene 3.0.2版创建类似于字典的搜索应用程序。 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. 我要显示的对象之一是一种“示例”,其中Lucene将在书中寻找一个单词,然后显示使用该单词的句子。

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. 我一直在阅读《 Lucene in Action》一书,其中提到了类似的内容,但通过浏览我找不到其他提及。 Is this something you can do with Lucene? 这是Lucene可以做的事情吗? If it is, how is can you do it? 如果是,您该怎么办?

I believe what you are looking for is a Highlighter. 我相信您正在寻找的是荧光笔。

One possibility is to use the lucene.search.highlight package, specifically the Highlighter . 一种可能是使用lucene.search.highlight包,特别是Highlighter

Another option is to use the lucene.search.vectorhighlight package, specifically the FastVectorHighlighter . 另一个选择是使用lucene.search.vectorhighlight包,特别是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. 如果您可以将书预分成更短的部分,则突出显示的速度会更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM