Skip to content

Commit

Permalink
Move inline function to global scope
Browse files Browse the repository at this point in the history
There's no benefit of having the function defined inline,
it just clutters the, already long, buildQueryAndParameters method.
  • Loading branch information
gforcada committed Dec 11, 2015
1 parent 2ac33ed commit b0001b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/collective/solr/queryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,12 @@ def quote(term, textfield=False):
stack.current.append('\\%s' % special)
i += 1
return str(stack)


def quote_iterable_item(term):
if isinstance(term, unicode):
term = term.encode('utf-8')
quoted = quote(term)
if not quoted.startswith('"') and not quoted == term:
quoted = quote('"' + term + '"')
return quoted
10 changes: 2 additions & 8 deletions src/collective/solr/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from collective.solr.mangler import subtractQueryParameters
from collective.solr.parser import SolrResponse
from collective.solr.queryparser import quote
from collective.solr.queryparser import quote_iterable_item
from collective.solr.utils import isWildCard
from collective.solr.utils import prepareData
from collective.solr.utils import prepare_wildcard
Expand Down Expand Up @@ -160,14 +161,7 @@ def buildQueryAndParameters(self, default=None, **args):
elif isinstance(value, (tuple, list)):
# list items should be treated as literals, but
# nevertheless only get quoted when necessary
def quoteitem(term):
if isinstance(term, unicode):
term = term.encode('utf-8')
quoted = quote(term)
if not quoted.startswith('"') and not quoted == term:
quoted = quote('"' + term + '"')
return quoted
value = '(%s)' % ' OR '.join(map(quoteitem, value))
value = '(%s)' % ' OR '.join(map(quote_iterable_item, value))
elif isinstance(value, set): # sets are taken literally
if len(value) == 1:
query[name] = ''.join(value)
Expand Down

0 comments on commit b0001b3

Please sign in to comment.