Commit 14027244 authored by Romain Courteaud's avatar Romain Courteaud

improve FULLTEXT_BOOLEAN_DETECTOR, i.e. '*a' is not a boolean search, but 'a*' is.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45521 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 70770b3c
...@@ -36,7 +36,7 @@ from zope.interface.verify import verifyClass ...@@ -36,7 +36,7 @@ from zope.interface.verify import verifyClass
from Products.ZSQLCatalog.SQLCatalog import profiler_decorator from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
import re import re
FULLTEXT_BOOLEAN_DETECTOR = re.compile(r'.*(^|\s)[\+\-<>\(\)\~\*]') FULLTEXT_BOOLEAN_DETECTOR = re.compile(r'.*((^|\s)[\+\-<>\(\~]|[\*\)](\s|$))')
class FullTextKey(SearchKey): class FullTextKey(SearchKey):
""" """
......
...@@ -539,11 +539,29 @@ class TestSQLCatalog(unittest.TestCase): ...@@ -539,11 +539,29 @@ class TestSQLCatalog(unittest.TestCase):
Fulltext searches must switch automatically to boolean mode if boolean Fulltext searches must switch automatically to boolean mode if boolean
operators are found in search value. operators are found in search value.
""" """
self.catalog(ReferenceQuery(ReferenceQuery(operator='match_boolean',
fulltext=MatchList(['a*'])), operator='and'),
{'fulltext': 'a*'})
self.catalog(ReferenceQuery(ReferenceQuery(operator='match_boolean',
fulltext=MatchList(['a* b'])), operator='and'),
{'fulltext': 'a* b'})
self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='*a'),
operator='and'),
{'fulltext': '*a'})
self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a'),
operator='and'),
{'fulltext': 'a'})
self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a+b'), operator='and'), self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a+b'), operator='and'),
{'fulltext': 'a+b'}) {'fulltext': 'a+b'})
self.catalog(ReferenceQuery(ReferenceQuery(operator='match_boolean', self.catalog(ReferenceQuery(ReferenceQuery(operator='match_boolean',
fulltext=MatchList(['a +b', '+b a'])), operator='and'), fulltext=MatchList(['a +b', '+b a'])), operator='and'),
{'fulltext': 'a +b'}, check_search_text=False) {'fulltext': 'a +b'}, check_search_text=False)
self.catalog(ReferenceQuery(ReferenceQuery( self.catalog(ReferenceQuery(ReferenceQuery(
ReferenceQuery(operator='=', uid='foo'), ReferenceQuery(operator='=', uid='foo'),
ReferenceQuery(operator='match_boolean', ReferenceQuery(operator='match_boolean',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment