lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <>
Subject Re: Escaping special character -
Date Wed, 19 Oct 2011 18:31:19 GMT
Right, term queries are NOT parsed, they assume you've
already done that (which you have in this case). which is
why you're finding that document with term query.

So take a look at the query explain (toString?) and see
what the query is actually being parsed as. My guess is that
StandardAnalyzer is splitting this into two tokens so you're
not matching.

There are two issues here. Escaping the - is just making it so
that the query parser doesn't interpret the hyphen as a NOT
operator. That says nothing about how the tokenizer (standard)
is breaking up the term after that. I expect you'd get your
expected results if you used, say, WhitespaceTokenizer...


On Tue, Oct 18, 2011 at 8:47 PM, anne <> wrote:
> Hi,
> I have a field that is not tokenized. Its value can contain a "-".
> For instance it could be "project-test". I have read that I need to escape
> this special character with a \
> I am using the following code (StandardAnanyzer):
>  Query query = queryParser.parse("field:project\\-test);
> and it doesn't retrieve my document.
> Is it because I need to use a TermQuery?
> I have tried with a TermQuery and it seems that in this case I don't need to
> escape the "-".
> Or is it because of the analyzer?
> Any help will be appreciated. Thanks a lot,
> Anne
> --
> View this message in context:
> Sent from the Lucene - Java Developer mailing list archive at
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message