Commit b038d12f authored by Nicolas Delaby's avatar Nicolas Delaby

Extend test for FullText Querying

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20807 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0da77944
......@@ -43,13 +43,21 @@ class TestSearchKeyLexer(unittest.TestCase):
run_all_test = 1
quiet = 0
def assertSameSet(self, a, b, msg=""):
if not msg:
msg='%r != %r' % (a, b)
for i in a:
self.failUnless(i in b, msg)
for i in b:
self.failUnless(i in a, msg)
self.assertEquals(len(a), len(b), msg)
def compare(self, search_key_class, search_value, expected_token_types):
""" """
key = getSearchKeyInstance(search_key_class)
tokens = key.tokenize(search_value)
token_types = [x.type for x in tokens]
self.assertEquals(set(token_types), set(expected_token_types))
self.assertSameSet(token_types, expected_token_types)
def test_01ProperPoolInitialization(self, quiet=quiet, run=run_all_test):
""" Check that search key pool is properly initialized """
......@@ -122,11 +130,14 @@ size/Child/34"""
def test_05FullTextKey(self, quiet=quiet, run=run_all_test):
""" Check lexer for FullTextKey."""
if not run: return
self.compare(FullTextKey, 'John Doe',
('WORD', 'WORD',))
self.compare(FullTextKey, 'John Doe', ('WORD', 'WORD',))
self.compare(FullTextKey, '+John -Doe',
('PLUS', 'WORD', 'MINUS', 'WORD',))
self.compare(FullTextKey, '.', ('WORD',))
self.compare(FullTextKey, 'John*', ('WORD', 'ASTERISK'))
self.compare(FullTextKey, '+apple +(>turnover <strudel)',
('PLUS', 'WORD', 'PLUS', 'LEFTPARENTHES', 'GREATERTHAN', 'WORD',
'LESSTHAN', 'WORD', 'RIGHTPARENTHES',))
def test_06ScriptableKey(self, quiet=quiet, run=run_all_test):
""" Check lexer for ScriptableKey."""
......@@ -387,6 +398,13 @@ class TestSearchKeyQuery(unittest.TestCase):
"MATCH full_text.SearchableText AGAINST ('.' )",
["MATCH full_text.SearchableText AGAINST ('.' ) AS full_text_SearchableText_relevance",
"MATCH full_text.SearchableText AGAINST ('.' ) AS SearchableText_relevance"])
#Boolean Mode
self.compare(FullTextKey,
'full_text.SearchableText',
'John*',
"MATCH full_text.SearchableText AGAINST ('John*' IN BOOLEAN MODE)",
["MATCH full_text.SearchableText AGAINST ('John*' IN BOOLEAN MODE) AS full_text_SearchableText_relevance",
"MATCH full_text.SearchableText AGAINST ('John*' IN BOOLEAN MODE) AS SearchableText_relevance"])
def test_07ScriptableKey(self, quiet=quiet, run=run_all_test):
""" Check ScriptableKey query generation"""
......
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