lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Wildcard and Literal Searches combined
Date Tue, 24 Jun 2008 13:36:15 GMT
Do you require that the words be right next to each other? You can,
of course, set your default to AND (it's OR unless you change it
explicitly). That'll give you documents that have both Dublin and City.
You don't need wildcards at all in this case.

If you require exact matches, you can use PhraseQuery or SpanQuery
to get words right next to each other. That is, "dublin city" would
be found but not "dublin is a very large city". You can set slop
(the distance between terms that counts as a hit) variously, and you
can also specify whether order is important. Again, you don't need
wildcards at all (and shouldn't use them unless you really need to).

Beware that phrase queries do NOT go through wildcard expansion. That
is, "Dubli* city" (as a PhraseQuery) doesn't do what you might think.

I'd really look over the query syntax carefully for more insights. See
http://lucene.apache.org/java/docs/queryparsersyntax.html

Also note that SpanQueries are something you construct yourself, you
don't send text through the query parser and magically get SpanQueries
back.

Best
Erick

On Tue, Jun 24, 2008 at 8:28 AM, mick l <kali.mist@gmail.com> wrote:

>
> Folks,
> 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 + "*)";
> }
> else
> {
> sSearchQuery = "(\"" + sSearchQuery + "\")";
> }
> IndexSearcher searcher = new IndexSearcher(sIndexLocation);
> Hits oHitColl = searcher.Search(oParser.Parse(sSearchQuery));
>
> Thanks folks
> --
> View this message in context:
> http://www.nabble.com/Wildcard-and-Literal-Searches-combined-tp18089950p18089950.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

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