Skip to content

Commit

Permalink
Remove unused Multidict class
Browse files Browse the repository at this point in the history
This class reimplemented the behaviour of the doseq=True parameter,
converting {"a", [1,2]} into &a=1&a=2
This syntax was previously used in the custom solr backend, but since we
started using pysolr we now use the to_kwargs method to serialise the
parameters in the SolrQuery object
  • Loading branch information
alastair committed Jan 12, 2023
1 parent f7853b4 commit b629ee7
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions utils/search/backends/solr_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,6 @@
from utils.search import SearchEngineException


class Multidict(dict):
"""A dictionary that represents a query string. If values in the dics are tuples, they are expanded.
None values are skipped and all values are utf-encoded. We need this because in solr, we can have multiple
fields with the same value, like facet.field
>>> [ (key, value) for (key,value) in Multidict({"a": 1, "b": (2,3,4), "c":None, "d":False}).items() ]
[('a', 1), ('b', 2), ('b', 3), ('b', 4), ('d', 'false')]
"""

def items(self):
# generator that retuns all items
def all_items():
for (key, value) in dict.items(self):
if isinstance(value, tuple) or isinstance(value, list):
for v in value:
yield key, v
else:
yield key, value

# generator that filters all items: drop (key, value) pairs with value=None and convert bools to lower case strings
for (key, value) in filter(lambda key_value: key_value[1] != None and key_value[1] != "", all_items()):
if isinstance(value, bool):
value = str(value).lower()
else:
value = str(value).encode('utf-8')

yield (key, value)


class SolrQuery(object):
"""A wrapper around a lot of Solr query funcionality.
"""
Expand Down Expand Up @@ -282,7 +253,7 @@ def set_highlighting_options(self, field, snippets=None, fragment_size=None, mer
self.params['f.%s.hl.simple.post' % field] = post

def __unicode__(self):
return urllib.parse.urlencode(Multidict(self.params))
return urllib.parse.urlencode(self.params, doseq=True)

def set_group_field(self, group_field=None):
self.params['group.field'] = group_field
Expand Down

0 comments on commit b629ee7

Please sign in to comment.