Skip to content

Commit

Permalink
Added support to search for null fields in Solr
Browse files Browse the repository at this point in the history
  • Loading branch information
user1 committed Nov 23, 2011
1 parent b8a23d4 commit 9332a91
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions haystack/backends/solr_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,19 @@ def build_query_fragment(self, field, filter_type, value):
if hasattr(value, 'values_list'):
value = list(value)

index_fieldname = connections[self._using].get_unified_index().get_index_fieldname(field)

if value is None:
# The filter is for a document field with the value of None.
# As an optimization, we wouldn't have stored that field on the document,
# so we're really looking for documents without this field at all.
# Return solr's search filter for the empty fields
return ': -%s:[* TO *]' % index_fieldname

if not isinstance(value, (set, list, tuple)):
# Convert whatever we find to what pysolr wants.
value = self.backend.conn._from_python(value)

index_fieldname = connections[self._using].get_unified_index().get_index_fieldname(field)

filter_types = {
'contains': u'%s:%s',
'exact': u'%s:"%s"',
Expand Down

0 comments on commit 9332a91

Please sign in to comment.