简体   繁体   中英

Lucene Reverse Phrase Search

If I want to search for Keyword "Error Message" , Can lucene be able to lend me results matching "Error Message" and "Message Error". Currenlty i am getting results matching "Error Message" Only. I am using Standard Analyser and Query Parser for searching a Keyword.

Use a PhraseQuery with slop > 0. From the javadoc :

Sets the number of other words permitted between words in query phrase. If zero, then this is an exact phrase search. For larger values this works like a WITHIN or NEAR operator. The slop is in fact an edit-distance, where the units correspond to moves of terms in the query phrase out of position. For example, to switch the order of two words requires two moves (the first move places the words atop one another), so to permit re-orderings of phrases, the slop must be at least two.

More exact matches are scored higher than sloppier matches, thus search results are sorted by exactness.

The slop is zero by default, requiring exact matches.

There isn't anything that will do quite that, other than doing it as a search for "Error Message" OR "Message Error".

But if you search for

Title:(Error AND Message)

then you'll get everything where the title matches "Error" and "Message".

One key point, though : if you're programmatically constructing a Lucene query, you really shouldn't be using QueryParser . You should be using a QueryBuilder to construct it structurally. QueryParser is only for human-generated queries that a user might type into your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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