显示来自 Lucene 搜索结果的示例文本 [英] Displaying sample text from the Lucene Search Results

查看:30
本文介绍了显示来自 Lucene 搜索结果的示例文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在使用 Lucene 版本 3.0.2 创建一个类似于字典的搜索应用程序.我要显示的对象之一是一种示例",Lucene 会在其中查找书中的一个单词,然后显示使用这些单词的句子.

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.

我一直在阅读 Lucene in Action 这本书,其中提到了类似的内容,但通过它我找不到其他提及.这是你可以用 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. Is this something you can do with Lucene? If it is, how is can you do it?

推荐答案

我相信您正在寻找的是荧光笔.

I believe what you are looking for is a Highlighter.

一种可能性是使用 lucene.search.highlight 包,特别是 荧光笔.

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

另一种选择是使用 lucene.search.vectorhighlight 包,特别是 FastVectorHighlighter.

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.

这篇关于显示来自 Lucene 搜索结果的示例文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆