在 Lucene 中搜索短语
有人能给我举一个如何使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用邻近搜索来查找特定范围内的术语彼此的距离。 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.