Commit 18fa322a authored by Bartek Górny's avatar Bartek Górny

Added support for advanced MySQL search modes

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9075 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e3285d13
...@@ -171,6 +171,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -171,6 +171,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
uid -> the (local) universal ID of objects uid -> the (local) universal ID of objects
path -> the (local) path of objects path -> the (local) path of objects
If you pass it a "SearchableText" argument, it does a MySQL full-text search.
Additionally you can pass it a search_mode argument ('natural', 'in_boolean_mode'
or 'with_query_expansion') to use an advanced search mode ('natural'
is the default).
bgrain defined in meyhods... bgrain defined in meyhods...
...@@ -1600,7 +1605,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1600,7 +1605,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
where_expression += ["%s LIKE '%%%s%%'" % (key, value)] where_expression += ["%s LIKE '%%%s%%'" % (key, value)]
elif key in full_text_search_keys: elif key in full_text_search_keys:
# We must add % in the request to simulate the catalog # We must add % in the request to simulate the catalog
where_expression += ["MATCH %s AGAINST ('%s')" % (key, value)] search_mode=kw.get('search_mode','natural').lower()
modes={'natural':'','in_boolean_mode':'IN BOOLEAN MODE','with_query_expansion':'WITH QUERY EXPANSION'}
mode=modes.get(search_mode,'')
where_expression += ["MATCH %s AGAINST ('%s' %s)" % (key, value, mode)]
else: else:
where_expression += ["%s = '%s'" % (key, value)] where_expression += ["%s = '%s'" % (key, value)]
elif type(value) is type([]) or type(value) is type(()): elif type(value) is type([]) or type(value) is type(()):
...@@ -1623,7 +1631,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1623,7 +1631,10 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
query_item += ["%s LIKE '%%%s%%'" % (key, value_item)] query_item += ["%s LIKE '%%%s%%'" % (key, value_item)]
elif key in full_text_search_keys: elif key in full_text_search_keys:
# We must add % in the request to simulate the catalog # We must add % in the request to simulate the catalog
query_item += ["MATCH %s AGAINST ('%s')" % (key, value)] search_mode=kw.get('search_mode','natural').lower()
modes={'natural':'','in_boolean_mode':'IN BOOLEAN MODE','with_query_expansion':'WITH QUERY EXPANSION'}
mode=modes.get(search_mode,'')
query_item += ["MATCH %s AGAINST ('%s')" % (key, value, mode)]
else: else:
query_item += ["%s = '%s'" % (key, value_item)] query_item += ["%s = '%s'" % (key, value_item)]
if len(query_item) > 0: if len(query_item) > 0:
...@@ -1934,3 +1945,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1934,3 +1945,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
Globals.default__class_init__(Catalog) Globals.default__class_init__(Catalog)
class CatalogError(Exception): pass class CatalogError(Exception): pass
# vim: filetype=python syntax=python shiftwidth=2
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