Hi Andrew, you can escape the special characters in the string that QueryParser reserves by:
String queryString = QueryParser.escape( queryString ); Query query = QueryParser.parse( queryString ); Yuhan On Mon, Jan 24, 2011 at 6:03 PM, Andrew Kane <andrewrk...@gmail.com> wrote: > Wow, passing the buck doesn't really work for me. If you think Lucene is a > *database* that's fine, but in your demo code (or wherever) you should have > a translation routine to convert user input into *SQL/whatever language > you're using* and solve 95% of the use cases. Does such a translation > routine exist? > > Andrew. > > > On Mon, Jan 24, 2011 at 8:51 PM, Erick Erickson <erickerick...@gmail.com > >wrote: > > > Yes. You're confusing an *engine* with a full-blown application. > > > > The user here is a Java programmer. I argue that guessing, which > > is what you're asking for, is emphatically NOT in the domain of the > > search *engine*, which is what Lucene is. Imagine the poor programmer > > trying to understand why certain results were returned when the > > engine changed the query while attempting to guess. Chaos. > > > > Dealing with bad user input is the application's responsibility. You're > > perfectly > > free to try to figure out what "the right thing to do" is, given your > > search > > domain, when you catch a parsing error. And I flat guarantee you'll be > > wrong > > for some percentage of cases. > > > > Which is why the engine is doing what it's doing, IMO... > > > > Best > > Erick > > > > On Mon, Jan 24, 2011 at 8:40 PM, Andrew Kane <andrewrk...@gmail.com> > > wrote: > > > > > What are you talking about?! A search engine isn't a compiler with a > > > programmer for a user and a strict syntax. The job of a search engine > is > > > to > > > produce the best results it can *for any given input*. Am I missing > > > something here? > > > > > > Andrew. > > > > > > > > > On Mon, Jan 24, 2011 at 5:15 PM, Adriano Crestani < > > > adrianocrest...@gmail.com > > > > wrote: > > > > > > > It's valid syntax error, since - is the exclusion operator, so the QP > > > > expects a term, phrase, parenthesis, etc after that. > > > > > > > > On Mon, Jan 24, 2011 at 5:05 PM, Andrew Kane <andrewrk...@gmail.com> > > > > wrote: > > > > > > > > > Shouldn't these two queries be fine? (from TREC million query > > track). > > > > > Should this be entered as a bug? > > > > > > > > > > Thanks, > > > > > > > > > > Andrew. > > > > > > > > > > > > > > > > > > > > Cannot parse 'statistics on child labor laws 1930 -': Encountered > > > "<EOF>" > > > > > at > > > > > line 1, column 37. > > > > > Was expecting one of: > > > > > "(" ... > > > > > "*" ... > > > > > <QUOTED> ... > > > > > <TERM> ... > > > > > <PREFIXTERM> ... > > > > > <WILDTERM> ... > > > > > "[" ... > > > > > "{" ... > > > > > <NUMBER> ... > > > > > <TERM> ... > > > > > "*" ... > > > > > > > > > > Cannot parse 'u.s. census bureau local employment dynamics --': > > > > Encountered > > > > > " "-" "- "" at line 1, column 46. > > > > > Was expecting one of: > > > > > "(" ... > > > > > "*" ... > > > > > <QUOTED> ... > > > > > <TERM> ... > > > > > <PREFIXTERM> ... > > > > > <WILDTERM> ... > > > > > "[" ... > > > > > "{" ... > > > > > <NUMBER> ... > > > > > <TERM> ... > > > > > "*" ... > > > > > > > > > > > > > > >