问题描述
谁能给我举个例子,如何使用 Lucene.net 搜索词组?
Could somebody point me to an example how to search for phrases with Lucene.net?
假设我的索引中有一个文档,其字段为name",值为Jon Skeet".现在我希望能够在搜索jon skeet"时找到该文档.
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".
推荐答案
您可以使用 邻近搜索 以查找彼此相距一定距离内的术语.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.
这篇关于在 Lucene 中搜索短语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!