Commit 172f393f authored by Vincent Pelletier's avatar Vincent Pelletier

Do not strip quotes in FullText and SphinxSEFullTextKey keys.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38362 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent adbd9696
......@@ -30,7 +30,7 @@
from SearchKey import SearchKey
from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery
from Products.ZSQLCatalog.SearchText import parse
from Products.ZSQLCatalog.SearchText import FullText_parse
from Products.ZSQLCatalog.interfaces.search_key import ISearchKey
from zope.interface.verify import verifyClass
from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
......@@ -46,7 +46,10 @@ class FullTextKey(SearchKey):
get_operator_from_value = False
def parseSearchText(self, value, is_column):
return parse(value, is_column)
return FullText_parse(value, is_column)
def _renderValueAsSearchText(self, value, operator):
return operator.asSearchText(value)
@profiler_decorator
def _processSearchValue(self, search_value, logical_operator,
......
......@@ -27,7 +27,7 @@
from SearchKey import SearchKey
from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery
from Products.ZSQLCatalog.SearchText import parse
from Products.ZSQLCatalog.SearchText import FullText_parse
from Products.ZSQLCatalog.interfaces.search_key import ISearchKey
from zope.interface.verify import verifyClass
from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
......@@ -40,7 +40,10 @@ class SphinxSEFullTextKey(SearchKey):
get_operator_from_value = False
def parseSearchText(self, value, is_column):
return parse(value, is_column)
return FullText_parse(value, is_column)
def _renderValueAsSearchText(self, value, operator):
return operator.asSearchText(value)
@profiler_decorator
def _buildQuery(self, operator_value_dict, logical_operator, parsed, group):
......
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Vincent Pelletier <vincent@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from lexer import update_docstrings
from AdvancedSearchTextParser import ValueNode, NotNode, LogicalNode
from AdvancedSearchTextParser import ColumnNode, AdvancedSearchTextParser
class FullTextSearchTextParser(AdvancedSearchTextParser):
# IMPORTANT:
# In short: Don't remove any token definition below even if they look
# useless.
# In detail: The lex methods below are redefined here because of ply nice
# feature of prioritizing tokens using the *line* *number* at which they
# are defined. As we inherit those methods from another class from another
# file (which doesn't match this file's content, of course) we must redefine
# wrapper methods to enforce token priority. Kudos to ply for so much
# customisable behaviour. Not.
def t_LEFT_PARENTHESE(self, t):
return AdvancedSearchTextParser.t_LEFT_PARENTHESE(self, t)
def t_RIGHT_PARENTHESE(self, t):
return AdvancedSearchTextParser.t_RIGHT_PARENTHESE(self, t)
def t_OPERATOR(self, t):
return AdvancedSearchTextParser.t_OPERATOR(self, t)
def t_STRING(self, t):
# Here is the only difference between AdvancedSearchTextParser and this
# class: strings are kept escaped (ie, they are considered as WORDs).
return AdvancedSearchTextParser.t_WORD(self, t)
def t_COLUMN(self, t):
return AdvancedSearchTextParser.t_COLUMN(self, t)
def t_OR(self, t):
return AdvancedSearchTextParser.t_OR(self, t)
def t_AND(self, t):
return AdvancedSearchTextParser.t_AND(self, t)
def t_NOT(self, t):
return AdvancedSearchTextParser.t_NOT(self, t)
def t_WORD(self, t):
return AdvancedSearchTextParser.t_WORD(self, t)
update_docstrings(FullTextSearchTextParser)
......@@ -31,6 +31,7 @@
import threading
from AdvancedSearchTextDetector import AdvancedSearchTextDetector
from AdvancedSearchTextParser import AdvancedSearchTextParser
from FullTextSearchTextParser import FullTextSearchTextParser
from lexer import ParserOrLexerError
try:
from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
......@@ -72,6 +73,7 @@ class ParserPool(object):
parser_pool = ParserPool()
DETECTOR_ID = parser_pool.register(AdvancedSearchTextDetector)
PARSER_ID = parser_pool.register(AdvancedSearchTextParser)
FULLTEXT_PARSER_ID = parser_pool.register(FullTextSearchTextParser)
def safeParsingDecorator(func):
"""
......@@ -103,6 +105,11 @@ def parse(input, is_column, *args, **kw):
result = None
return result
@profiler_decorator
@safeParsingDecorator
def FullText_parse(input, is_column, *args, **kw):
return parser_pool.get(FULLTEXT_PARSER_ID)(input, is_column, *args, **kw)
if __name__ == '__main__':
class Query:
def __init__(self, column, value, comparison_operator='='):
......
from SearchTextParser import parse, isAdvancedSearchText
from SearchTextParser import parse, isAdvancedSearchText, FullText_parse
......@@ -526,6 +526,15 @@ class TestSQLCatalog(unittest.TestCase):
fulltext=MatchList(['+a b', 'b +a'])),
operator='and'), operator='and'), {'fulltext': '+a b uid:foo'})
def test_FullTextQuoting(self):
# Quotes must be kept
self.catalog(ReferenceQuery(ReferenceQuery(operator='match',
fulltext='"a"'), operator='and'),
{'fulltext': '"a"'})
self.catalog(ReferenceQuery(ReferenceQuery(operator='match',
fulltext='"foo" bar "baz"'), operator='and'),
{'fulltext': '"foo" bar "baz"'})
def test_DefaultKeyTextRendering(self):
self.catalog(ReferenceQuery(ReferenceQuery(operator='like', default='a% b'), operator='and'),
{'default': 'a% b'})
......
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