在 Lucene 中搜索短语

发布于 2024-07-10 00:17:54 字数 119 浏览 12 评论 0原文

有人能给我举一个如何使用 Lucene.net 搜索短语的例子吗?

假设我的索引中有一个包含字段“name”、值“Jon Skeet”的文档。 现在我希望在搜索“jon skeet”时能够找到该文档。

Could somebody point me to an example how to search for phrases with Lucene.net?

Let's say I have in my index a document with field "name", value "Jon Skeet". Now I want to be able to find that document when searching for "jon skeet".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞慾 2024-07-17 00:17:54

您可以使用邻近搜索来查找特定范围内的术语彼此的距离。 Lucene 查询语法类似于 "jon skeet"~3,意思是在三个单词内查找“jon”和“skeet”。 使用这种语法,相对顺序并不重要; “jon q. skeet”、“skeet, q. jon”和“jon skeet”都会匹配。

如果您有一个想要将其视为单个标记的短语列表,则需要在分析器中处理它。 例如,您希望将“近东”、“中东”和“远东”视为单独的标记。 您需要编写一个具有一定前瞻功能的分析器,以便它可以将这些短语视为一个单词。 该分析器既可用于索引器,也可用于搜索应用程序中的用户输入。

You can use a proximity search to find terms within a certain distance of each other. The Lucene query syntax looks like this "jon skeet"~3, meaning find "jon" and "skeet" within three words of each other. With this syntax, relative order doesn't matter; "jon q. skeet", "skeet, q. jon", and "jon skeet" would all match.

If you have a list of phrases that you want to treat as a single token, you need to take care of that in your analyzer. For instance, you want to treat "near east", "middle east", and "far east" as individual tokens. You need to write an analyzer with some lookahead, so that it can treat these phrases as if they were one word. This analyzer is used both in the indexer, and against user input in the search application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文