You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Felix Schwarz <fe...@web.de> on 2008/06/16 13:48:28 UTC

Problems understanding QueryParser + WildcardQueries

Hi,

I have a small problem regarding QueryParser and WildcardQueries.

Basically, I'm indexing documents like this:
doc.add(new Field("title", "_FooBar", Field.Store.YES, Field.Index.TOKENIZED));

Afterwards I expected that this query would return the document above:
QueryParser parser = new QueryParser("title", getAnalyzer());
Query q = parser.parse("_Foo*");

But instead no hit is returned (yes, I'm using StandardAnalyzer for indexing+searching).
If I search for "_FooBar", it works.

Obviously, I did not understand thorougly what Lucene does with my query.

Can anyone shed some light on this?

Thank you very much
fs

PS: Maybe it's just a stupid coding error. The complete test case is available, too:
http://www.felix-schwarz.name/files/misc/2008/UnderscoreSearching.java

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Problems understanding QueryParser + WildcardQueries

Posted by Erick Erickson <er...@gmail.com>.
Here's your answer I think....

http://wiki.apache.org/lucene-java/LuceneFAQ#head-133cf44dd3dff3680c96c1316a663e881eeac35a


In a nutshell, wildcard queries are not passed through an analyzer, although
they are
lower-cased by default. So you're indexing foobar but searching on _foobar
(after rewrite)....

But since searching on "_FooBar" *is* passed through the analyzer, it works.

query.toString is your friend <G>......

at least I think....

Best
Erick

On Mon, Jun 16, 2008 at 7:48 AM, Felix Schwarz <fe...@web.de> wrote:

> Hi,
>
> I have a small problem regarding QueryParser and WildcardQueries.
>
> Basically, I'm indexing documents like this:
> doc.add(new Field("title", "_FooBar", Field.Store.YES,
> Field.Index.TOKENIZED));
>
> Afterwards I expected that this query would return the document above:
> QueryParser parser = new QueryParser("title", getAnalyzer());
> Query q = parser.parse("_Foo*");
>
> But instead no hit is returned (yes, I'm using StandardAnalyzer for
> indexing+searching).
> If I search for "_FooBar", it works.
>
> Obviously, I did not understand thorougly what Lucene does with my query.
>
> Can anyone shed some light on this?
>
> Thank you very much
> fs
>
> PS: Maybe it's just a stupid coding error. The complete test case is
> available, too:
> http://www.felix-schwarz.name/files/misc/2008/UnderscoreSearching.java
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>