Ferret::QueryParser::QueryParseException

During our last week of Ferret / aaf usage (also our first week of
Ferret / aaf usage), I have received 8 messages stating that our app
encountered a Ferret::QueryParser::QueryParseException. For instance:

A Ferret::QueryParser::QueryParseException occurred in foo#search:

Error occurred in src/q_parser.y:279 - yyerror
couldn’t parse query “com – 404”. Error message was syntax error

/where/gems/are/stored/gems/ferret-0.10.11/lib/ferret/index.rb:709 in
‘parse’

(thanks to the excellent exception_notification plugin for what you see
above)

So I did a little research into the Exception, which only left me with
more questions. According to the RDoc for Ferret, the
Ferret::QueryParser#new method has a :clean_string option that should
escape any special characters, and by default it’s on. I emailed the
author of aaf and he said that he doesn’t do anything with this flag, so
it should still be on. In that case, why am I still seeing this
exception?

Jim

On 10/16/06, Jim K. [email protected] wrote:

‘parse’
exception?

Jim

clean_string isn’t perfect. It escapes special characters within
phrases (except for ‘<>’ and ‘|’ which have special meaning within
phrases). It also tries to match up quotes and brackets. If it still
can’t parse the query then it will raise an exception unless you set
:handle_exception to true in which case the exception will be ignored
and the query will be parsed as a simple boolean query and all special
characters will be ignored.

I hope that makes sense. If you have any suggestions I’d be happy to
hear them.

Cheers,
Dave

David B. wrote:

On 10/16/06, Jim K. [email protected] wrote:

‘parse’
exception?

Jim

clean_string isn’t perfect. It escapes special characters within
phrases (except for ‘<>’ and ‘|’ which have special meaning within
phrases). It also tries to match up quotes and brackets. If it still
can’t parse the query then it will raise an exception unless you set
:handle_exception to true in which case the exception will be ignored
and the query will be parsed as a simple boolean query and all special
characters will be ignored.

I hope that makes sense. If you have any suggestions I’d be happy to
hear them.

Cheers,
Dave

OK, the actual flag I needed was :handle_parse_errors as opposed to
:handle_exception, or :handle_parser_errors (that one’s in the RDocs on
the ferret trac). Calling acts_as_ferret like so did the trick:
acts_as_ferret({:fields => {:field => {:store => :compressed}}},
{:handle_parser_errors => true})

Thanks for pointing me in the right direction. I was going to submit a
patch to the docs but it looks like you’ve fixed it already in the
trunk.

Jim