QueryParsingException With Certain Characters

I'm getting parsing exceptions when the user enters certain characters
in their search. For example, the following all throw:

{"query":{"field":{"Title":{"query":"^"}}}}
{"query":{"field":{"Title":{"query":""}}}}'
{"query":{"field":{"Title":{"query":"!"}}}}'
{"query":{"field":{"Title":{"query":"~"}}}}'

How do I handle this? I'm not concerned whether these actually return
results. I'm content if the search ignores these. Or I can strip
them out. I just don't want an exception. If I strip them, how do I
know the full list of characters to strip?

I also tried escaping them (preceding with backslash), but it still
threw. Should I be applying some kind of encoding?

On Sat, 2011-01-01 at 09:58 -0800, Tim Scott wrote:

I'm getting parsing exceptions when the user enters certain characters
in their search. For example, the following all throw:

{"query":{"field":{"Title":{"query":"^"}}}}
{"query":{"field":{"Title":{"query":""}}}}'
{"query":{"field":{"Title":{"query":"!"}}}}'
{"query":{"field":{"Title":{"query":"~"}}}}'

Yes - these are all reserved characters.

How do I handle this? I'm not concerned whether these actually return
results. I'm content if the search ignores these. Or I can strip
them out. I just don't want an exception. If I strip them, how do I
know the full list of characters to strip?

You can see the list here:
http://lucene.apache.org/java/3_0_0/queryparsersyntax.html

I also tried escaping them (preceding with backslash), but it still
threw. Should I be applying some kind of encoding?

You can escape them with a backslash, but you probably need \ in order
to overcome shell escaping.

Which API are you using? For the Perl API, I'm about to release a module
which filter query strings to remove constructs which can cause errors,
and to give the programmer some control over what is allowed through.

clint