Displaying sample text from the Lucene Search Results(显示来自 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 搜索结果的示例文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:显示来自 Lucene 搜索结果的示例文本


基础教程推荐
- 大摇大摆的枚举 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java Swing计时器未清除 2022-01-01