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 Simon Wistow <si...@thegestalt.org> on 2007/04/04 22:42:12 UTC

Better parsing of Queries

I'm looking for some advice on dealing with malformed queries.

If a user searches for "yow!" then I get an exception from the query 
parser. I can get round this by using QueryParser.escape(query) first 
but then that prevents them from searching using other bits of the the 
query syntax such as "author:alice".

Is there an easy way to get a query such as 

    "yow! author:alice"

and get back

    "yow\! author:alice"

i.e only escape the special characters when they don't make sense?

Simon

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


Re: Better parsing of Queries

Posted by Chris Hostetter <ho...@fucit.org>.
deja vu ... didn't someone else just asking about "tolerant" query
parsing, and then followup that they have found this suggestion from past
me...

http://www.nabble.com/Error-tolerant-query-parsing-tf108987.html

...inspecting the ParseException should allow you to do all sorts of
iterative "fixing" of the query string.

: Date: Wed, 4 Apr 2007 21:42:12 +0100
: From: Simon Wistow <si...@thegestalt.org>
: Reply-To: java-user@lucene.apache.org
: To: Lucene <ja...@lucene.apache.org>
: Subject: Better parsing of Queries
:
: I'm looking for some advice on dealing with malformed queries.
:
: If a user searches for "yow!" then I get an exception from the query
: parser. I can get round this by using QueryParser.escape(query) first
: but then that prevents them from searching using other bits of the the
: query syntax such as "author:alice".
:
: Is there an easy way to get a query such as
:
:     "yow! author:alice"
:
: and get back
:
:     "yow\! author:alice"
:
: i.e only escape the special characters when they don't make sense?
:
: Simon
:
: ---------------------------------------------------------------------
: To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
: For additional commands, e-mail: java-user-help@lucene.apache.org
:



-Hoss


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


Re: Better parsing of Queries

Posted by Erick Erickson <er...@gmail.com>.
About all you can do is roll your own. I suspect a decent regular
expression would work, or you could let Lucene escape the
query and then re-replace all \: with :

Erick

On 4/4/07, Simon Wistow <si...@thegestalt.org> wrote:
>
> I'm looking for some advice on dealing with malformed queries.
>
> If a user searches for "yow!" then I get an exception from the query
> parser. I can get round this by using QueryParser.escape(query) first
> but then that prevents them from searching using other bits of the the
> query syntax such as "author:alice".
>
> Is there an easy way to get a query such as
>
>     "yow! author:alice"
>
> and get back
>
>     "yow\! author:alice"
>
> i.e only escape the special characters when they don't make sense?
>
> Simon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>