lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mick l <>
Subject Wildcard and Literal Searches combined
Date Tue, 24 Jun 2008 12:28:53 GMT

My users require wildcard searches. Sometimes their search phrases contain
spaces. I am having trouble trying to implement a wildcard search on strings
containing spaces, so if the term includes spaces I force a literal search
by adding double quotes to the search term.
So the search string for 'Dublin' becomes search term (Dublin*)
whereas search string 'Dublin City' becomes ("Dublin City")

If I use (Dublin City*) I get all instances of Dublin OR City in the results
which is not what I am looking for. 

Is there any way I can combine the wildcard search and the literal?

Heres my existing code. Its in c# with Lucene.Net

//if input has spaces we do a literal search
if (sSearchQuery.IndexOf(" ") < 0)
sSearchQuery = "(" + sSearchQuery + "*)";
sSearchQuery = "(\"" + sSearchQuery + "\")";
IndexSearcher searcher = new IndexSearcher(sIndexLocation);
Hits oHitColl = searcher.Search(oParser.Parse(sSearchQuery));

Thanks folks 
View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message