Commit e9da5fa8 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

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
parent 43893f04
......@@ -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('.')
......
......@@ -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*',
......
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