Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

only return query_fragment if index_fieldname exists, closes #522 #524

Open
wants to merge 2 commits into from

2 participants

@dlo
dlo commented

Additionally, ignore empty results when creating query string.

Sorry about the previous pull request, I left out a necessary change.

#522

@dlo

Any update here?

@toastdriven
Owner

Sorry, this can't go in as-is. It needs tests & I haven't had time to get back here to write them.

@dlo dlo changed the title from only return query_fragment if index_fieldmane exists, closes #522 to only return query_fragment if index_fieldname exists, closes #522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2012
  1. @dlo

    only return query_fragment if index_fieldmane exists, closes #522

    dlo authored
    Additionally, ignore empty results when creating query string.
Commits on Mar 20, 2012
  1. @dlo
This page is out of date. Refresh to see the latest.
View
5 haystack/backends/__init__.py
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
+
+import operator
from copy import deepcopy
from time import time
+
from django.conf import settings
from django.db.models import Q
from django.db.models.base import ModelBase
@@ -224,7 +227,7 @@ def as_query_string(self, query_fragment_callback):
result.append(query_fragment_callback(field, filter_type, value))
conn = ' %s ' % self.connector
- query_string = conn.join(result)
+ query_string = conn.join(filter(operator.truth, result))
if query_string:
if self.negated:
View
6 haystack/backends/solr_backend.py
@@ -111,6 +111,8 @@ def search(self, query_string, sort_by=None, start_offset=0, end_offset=None,
narrow_queries=None, spelling_query=None, within=None,
dwithin=None, distance_point=None, models=None,
limit_to_registered_models=None, result_class=None, **kwargs):
+
+
if len(query_string) == 0:
return {
'results': [],
@@ -583,7 +585,9 @@ def build_query_fragment(self, field, filter_type, value):
if len(query_frag) and not query_frag.startswith('(') and not query_frag.endswith(')'):
query_frag = "(%s)" % query_frag
- return u"%s%s" % (index_fieldname, query_frag)
+ if index_fieldname:
+ return u"%s%s" % (index_fieldname, query_frag)
+ return query_frag
def build_alt_parser_query(self, parser_name, query_string='', **kwargs):
if query_string:
Something went wrong with that request. Please try again.