[zope2-tracker] [Bug 553045] [NEW] ZCTextIndex fails when an operator isn's adjacent to a query

Tres Seaver tseaver at palladion.com
Thu Apr 1 10:13:40 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ross Patterson wrote:
> Public bug reported:
> 
> When a ZCTextIndex query raises an exception when a qyuery starts or
> ends with an operator or when an operator is adjacent to an operator
> (e.g. "not" or "and").
> 
> The query logic should probably combine adjacent operators or treat the
> second adjacent operator as a query and something similar for the
> beginning or end of the query string.

Fixing up the query is "guessing" / policy, and doesn't belong in the
realm of the index:  the UI should be responsible for any such cleanups,
because otherwise the policy can't be changed to fit local conditions.

BTW, doing an actual search for one of the operators is possible by
wrapping the operator in double quotes.

If you'd still like to pursue this, then we need to make the "query
normalizer" a configurable option, e.g. using an adapter loookup inside
'QueryParser.parseQuery', just before it kicks down to the actual
recursive descent parser.  Something like (untested)::

 ------------------- %< -----------------------
 --- src/Products/ZCTextIndex/QueryParser.py	(revision 110122)
 +++ src/Products/ZCTextIndex/QueryParser.py	(working copy)
 @@ -121,7 +121,9 @@
              tokens = _tokenizer_unicode_regex.findall(query)
          except UnicodeDecodeError:
              tokens = _tokenizer_regex.findall(query)
 -        self._tokens = tokens
 +        normalizer = queryAdapter(self,
 +                            IQueryNormalizer, lambda x: x)
 +        self._tokens = notrmalizer(tokens)
          # classify tokens
          self._tokentypes = [_keywords.get(token.upper(), _ATOM)
                              for token in tokens]
 ------------------- %< -----------------------


Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAku0qhQACgkQ+gerLs4ltQ6gaQCfc3rSwcYKZSIK8RYDO6AI8wit
kcUAoMkbtyqbXIN4nCKmRsDDAiUCXzGp
=TOV3
-----END PGP SIGNATURE-----

-- 
ZCTextIndex fails when an operator isn's adjacent to a query
https://bugs.launchpad.net/bugs/553045
You received this bug notification because you are a member of Zope 2
Developers, which is subscribed to Zope 2.


More information about the zope2-tracker mailing list