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 Chun Wei Ho <cw...@gmail.com> on 2006/03/20 10:09:38 UTC

Simpler QueryParser

I am wondering if anyone has existing code for a simpler QueryParser -
one that does not create the more complex prefix/fuzzy/range queries,
but still allow the usual term/boolean queries.

I use QueryParser to directly parse user input (allowing for more
flexible specification of include/exclude and fields conditions), but
do not want them to use the more resource intensive queries.

Just checking since QueryParser is done in javacc which I have little
experience in to rewrite or subclass.

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


Re: Simpler QueryParser

Posted by Nadav Har'El <NY...@il.ibm.com>.
"Chun Wei Ho" <cw...@gmail.com> wrote on 20/03/2006 11:09:38 AM:
> I am wondering if anyone has existing code for a simpler QueryParser -
> one that does not create the more complex prefix/fuzzy/range queries,
> but still allow the usual term/boolean queries.
>
> I use QueryParser to directly parse user input (allowing for more
> flexible specification of include/exclude and fields conditions), but
> do not want them to use the more resource intensive queries.
>
> Just checking since QueryParser is done in javacc which I have little
> experience in to rewrite or subclass.

The "Lucene In Action" book has a section about exactly this issue:
section 6.3.2, "Prohibiting fuzzy and wildcard queries". The idea is
that you can tell the existing QueryParser not to allow such queries,
rather than write a different parser.

The trick is to create a new class, say, LimitedQueryParser, extending
QueryParser, and override it's getWildCardQuery, getFuzzyQuery,
getRangeQuery (see the QueryParser documentation for the full list);
If you don't want any of these supported, just throw an exception
(typically ParseException), and the parsing will fail if these
features are used (or, alternatively, think of what else you can
do in this case).

--
Nadav Har'El


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