From e9da5fa85e092b44b007cf36a129fcef35576015 Mon Sep 17 00:00:00 2001 From: Kazuhiko Shiozaki <kazuhiko@nexedi.com> Date: Wed, 4 Jun 2008 21:51:19 +0000 Subject: [PATCH] treat 'foo bar' as the 'AND' search in fulltext search, i.e. to find documents that contain both 'foo' and 'bar' (Bug #882). git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21329 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ZSQLCatalog/SearchKey/FullTextKey.py | 6 ++++-- product/ZSQLCatalog/tests/testSearchKeys.py | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/product/ZSQLCatalog/SearchKey/FullTextKey.py b/product/ZSQLCatalog/SearchKey/FullTextKey.py index d07e61760d..0a56558426 100644 --- a/product/ZSQLCatalog/SearchKey/FullTextKey.py +++ b/product/ZSQLCatalog/SearchKey/FullTextKey.py @@ -27,6 +27,7 @@ ############################################################################## from SearchKey import SearchKey +import re SEARCH_MODE_MAPPING = {'in_boolean_mode': 'IN BOOLEAN MODE', 'with_query_expansion': 'WITH QUERY EXPANSION'} @@ -62,8 +63,6 @@ class FullTextKey(SearchKey): #r'[^\+\-<>\(\)\~\*\"\s]\S*' #r'[\x7F-\xFF\w\d][\x7F-\xFF\w\d]*' # WORD may contain arbitrary letters and numbers without white space - word_value = t.value - t.value = "'%s'" % word_value return t def buildSQLExpression(self, key, value, @@ -79,6 +78,9 @@ class FullTextKey(SearchKey): if token.type != 'WORD': mode = SEARCH_MODE_MAPPING['in_boolean_mode'] break + if mode == '' and len(tokens) > 1: + value = ' '.join(['+%s' % x.value for x in tokens]) + mode = SEARCH_MODE_MAPPING['in_boolean_mode'] # split (if possible) to column.key if key.find('.') != -1: table, column = key.split('.') diff --git a/product/ZSQLCatalog/tests/testSearchKeys.py b/product/ZSQLCatalog/tests/testSearchKeys.py index 61c57c8470..df504f4aa7 100644 --- a/product/ZSQLCatalog/tests/testSearchKeys.py +++ b/product/ZSQLCatalog/tests/testSearchKeys.py @@ -393,6 +393,13 @@ class TestSearchKeyQuery(unittest.TestCase): ["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 stuart mill', + "MATCH full_text.SearchableText AGAINST ('+john +stuart +mill' IN BOOLEAN MODE)", + ["MATCH full_text.SearchableText AGAINST ('+john +stuart +mill' IN BOOLEAN MODE) AS full_text_SearchableText_relevance", + "MATCH full_text.SearchableText AGAINST ('+john +stuart +mill' IN BOOLEAN MODE) AS SearchableText_relevance"]) + self.compare(FullTextKey, 'full_text.SearchableText', 'John*', -- 2.30.9