Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
648 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...