Token 'ATOM' required, 'and' found
I'm using zope 2.7.5 and when doing a catalog search in a ZCTextIndex containing the starting with the word "and" it barfs with this errror: E.g. http://www.peterbe.com/search?q=and+i+cant+stop+thinking+about+you Error Type: ParseError Error Value: Token 'ATOM' required, 'and' found (traceback below) It works perfectly fine with http://www.peterbe.com/search?q=i+and+cant+stop+thinking+about+you because then it doesn't start with "and". The easy fix is so do something like this: if q.lower().startswith('and'): q= q[3:] results = self.Catalog.searchResults(title=q) But, is there a more robust solution to this? One that doesn't require hardcoded English words in the code. Is there a way to escape "and" and "or" to treat them as actual words? Traceback (innermost last): Module ZPublisher.Publish, line 101, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Products.Peterbecom.Homepage, line 967, in SearchCatalog Module Products.Peterbecom.Homepage, line 985, in getSearchResults Module Products.ZCatalog.ZCatalog, line 649, in searchResults Module Products.ZCatalog.Catalog, line 753, in searchResults Module Products.ZCatalog.Catalog, line 496, in search Module Products.ZCTextIndex.ZCTextIndex, line 198, in _apply_index Module Products.ZCTextIndex.QueryParser, line 123, in parseQuery Module Products.ZCTextIndex.QueryParser, line 163, in _parseOrExpr Module Products.ZCTextIndex.QueryParser, line 176, in _parseAndExpr Module Products.ZCTextIndex.QueryParser, line 211, in _parseTerm Module Products.ZCTextIndex.QueryParser, line 230, in _parseAtom Module Products.ZCTextIndex.QueryParser, line 158, in _get Module Products.ZCTextIndex.QueryParser, line 144, in _require ParseError: Token 'ATOM' required, 'and' found -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Peter Bengtsson wrote:
But, is there a more robust solution to this?
The "correct" thing to do here is to write your own query parser, but that's a lot of hard work. I just catch the two exceptions that the QueryParser can throw and return an empty result set. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Ok. Sounds like a plan. What I need to do if it happens is to escape all the operator words like "and" "or" "not". Any idea how I can do that? On 7/25/05, Chris Withers <chris@simplistix.co.uk> wrote:
Peter Bengtsson wrote:
But, is there a more robust solution to this?
The "correct" thing to do here is to write your own query parser, but that's a lot of hard work.
I just catch the two exceptions that the QueryParser can throw and return an empty result set.
cheers,
Chris
-- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
----- Original Message ----- From: "Peter Bengtsson" <peterbe@gmail.com> To: "Chris Withers" <chris@simplistix.co.uk> Cc: <zope@zope.org> Sent: Monday, July 25, 2005 7:06 AM Subject: [Zope] Re: Token 'ATOM' required, 'and' found
Ok. Sounds like a plan. What I need to do if it happens is to escape all the operator words like "and" "or" "not". Any idea how I can do that?
Not a zope solution (or issue), but how about using regex in python code? Jonathan
On 7/25/05, Chris Withers <chris@simplistix.co.uk> wrote:
Peter Bengtsson wrote:
But, is there a more robust solution to this?
The "correct" thing to do here is to write your own query parser, but that's a lot of hard work.
I just catch the two exceptions that the QueryParser can throw and return an empty result set.
cheers,
Chris
-- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Ok. Sounds like a plan. What I need to do if it happens is to escape all the operator words like "and" "or" "not". Any idea how I can do that?
Not a zope solution (or issue), but how about using regex in python code?
Finding the words I'm not worried about. What I don't know is _how_ to escape the words. If it was putting it in square brackets i _would_ do: q = q.replace('not','[not]') Don't get hung up on that. What I'm after is the technique I can use upon the QueryParser for "ignoring" these operator words. -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
Peter Bengtsson wrote:
Don't get hung up on that. What I'm after is the technique I can use upon the QueryParser for "ignoring" these operator words.
RTSL ;-) QueryParser.py has a massive doc string at the top of it ;-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris Withers -
Jonathan -
Peter Bengtsson