4

My application takes a user inputted string and tries to parse it with the Lucene query parser. I noticed however that there are several formats of strings that provoke an error in this query parser.
e.g.:

  • ~anystring
  • anystring +

First I tried molding my user inputted string so that it could not contain these cases, but as I see it, there could be more cases I do not foresee now.

How do you handle Query parser exceptions? How do you prevent them?

Boris Callens
  • 90,659
  • 85
  • 207
  • 305

2 Answers2

2

We catch the remaining parse exceptions and display an error message ("Your search did not match any documents. Suggestion: Try different keywords.").

See also How to make the Lucene QueryParser more forgiving?

Community
  • 1
  • 1
trunkc
  • 6,223
  • 4
  • 34
  • 49
  • Hmm, yes, this is the most obvious way to go. But I would think that some common cases would be solved by the query parser itselve. But maybe that shouldn't be it's resposibility indeed. – Boris Callens Mar 02 '09 at 13:02
0
query.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"\/])/g, "");
double-beep
  • 5,031
  • 17
  • 33
  • 41