lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject Multiple Keywords - Regular and Any Order Search
Date Thu, 10 Oct 2013 15:54:07 GMT

I have implemented Lucene to search for a single keyword across multiple fields and it works
great. I did this by concatenating all the fields into a "contents" field and searching against
this field.

When I give multiple keywords against this setup, Lucene by default does an OR search, leading
to loads of duplicates. This, I understand is an expected behaviour.

1.       Hence the first thing that I am trying to achieve is search functionality for multiple
keywords. The most popular suggestion is to implement PhraseQuery. I will try this out, but
please let me know if you can provide an example or any suggestions.

2.       Once the multiple keywords search is implemented, I need to provide another option
to the users. They should be able to check a checkbox "Search in any order". If checked, if
the same keywords of the phrase are present "in a particular field" BUT in different order,
that should still be a match. I don't know how to implement this without forming all permutations
of the phrase and then performing an AND search. This could be very expensive in terms of
performance. Please let me know if Lucene provides a way to do this.

Examples for Item 2:


Search1: "RAINING HEAVILY TODAY" - Should Match

Search2: "RAINING TODAY HEAVILY" - Should Match

Search3: "RAIN TODAY HEAVILY" - Should NOT Match

Search4: "ABC CORPORATION LIMITED" - Should Match

Search5: "ABC CORP LIMITED" - Should NOT Match

Search6: "ABC LIMITED CORPORATION" - Should Match

I am also not sure if the "contents" field approach will work in this case. Do I need to index
the fields separately using "MultiFieldQueryParser" to achieve this?

Sorry for the lengthy question. I would greatly appreciate any suggestions or inputs.



This message is for information purposes only, it is not a recommendation, advice, offer or
solicitation to buy or sell a product or service nor an official confirmation of any transaction.
It is directed at persons who are professionals and is not intended for retail customer use.
Intended for recipient only. This message is subject to the terms at:

For important disclosures, please see: regarding
market commentary from Barclays Sales and/or Trading, who are active market participants;
and in respect of Barclays Research, including disclosures relating to specific issuers, please


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message