简体   繁体   English

在Lucene中搜索短语

[英]Searching phrases in Lucene

Could somebody point me to an example how to search for phrases with Lucene.net? 有人能指出一个如何用Lucene.net搜索短语的例子吗?

Let's say I have in my index a document with field "name", value "Jon Skeet". 假设我在索引中有一个带有字段“name”的文档,值为“Jon Skeet”。 Now I want to be able to find that document when searching for "jon skeet". 现在我希望能够在搜索“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. Lucene查询语法看起来像这个"jon skeet"~3 ,意思是在彼此的三个单词中找到“jon”和“skeet”。 With this syntax, relative order doesn't matter; 使用这种语法,相对顺序无关紧要; "jon q. skeet", "skeet, q. jon", and "jon skeet" would all match. “jon q.satet”,“skeet,q.jon”和“jon skeet”都将匹配。

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. 此分析器既可用于索引器,也可用于搜索应用程序中的用户输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM