lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter M Cipollone" <>
Subject Re: Question on QueryParser.parse()
Date Fri, 14 May 2004 19:49:28 GMT

----- Original Message ----- 
From: "Terence Lai" <>
To: "'Lucene Users List'" <>
Sent: Friday, May 14, 2004 2:12 PM
Subject: Question on QueryParser.parse()

> I am trying to create a query object using the QueryParser for the search
word "A+". However, it always returns a Null object back. My code is stated
>     Query q = QueryParser.parse("A\+", "myIndex", new StandardAnalyzer());
> I've also tried the following query strings, but none of them returns the
query object back.
>     myIndex: A\+
>     myIndex: "A\+"
>     myIndex: "A+"
> Does anyone know the solution?

StandardAnalyzer is what's stopping you.  It will discard the letter "A"
because of its StopFilter, and it will discard the "+" because it considers
that character to be noise.  You have a few choices:

1. Build the query manually.

Query q = new TermQuery(new Term("myIndex", "A+");

This will only work if you actually indexed the term "A+" (i.e. if you did
not use StandardAnalyzer when you indexed the docs).

2. Use a different analyzer.  In this case, the only stock analyzer that
will work is the WhitespaceAnalyzer.

Bear in mind that if you switch analyzers you will have to reindex your
content with your new choice of analyzer.  If you need to search unusual
terms like this, you might want to make your own Analyzer out of a
WhitespaceTokenizer and a LowerCaseFilter, as follows:

class LcWsAnalyzer extends Analyzer {
  public TokenStream tokenStream(String fieldName, Reader reader) {
    return new LowerCaseFilter(new WhitespaceTokenizer(reader));

When the above Analyzer is used,  QueryParser.parse() returns


as the term it will search for.

> By the way, I am using Lucence 1.4 RC3.
> Thanks,
> Terence
> ----------------------------------------------------------
> Get your free email account from
>           Your Internet Virtual Desktop!
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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

View raw message