Skip to content

Commit

Permalink
Fixed Solr backend so that it properly converts native Python types t…
Browse files Browse the repository at this point in the history
…o something Solr can handle. Thanks smulloni for the original patch!
  • Loading branch information
toastdriven committed May 9, 2009
1 parent 1d819f3 commit 513b4c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions haystack/backends/solr_backend.py
Expand Up @@ -200,8 +200,9 @@ def build_query(self):

value = the_filter.value

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

# Check to see if it's a phrase for an exact match.
if ' ' in value:
Expand Down
9 changes: 9 additions & 0 deletions tests/core/tests/backends/solr_query.py
@@ -1,3 +1,4 @@
import datetime
from django.conf import settings
from django.test import TestCase
from haystack.backends.solr_backend import SearchBackend, SearchQuery
Expand Down Expand Up @@ -25,6 +26,14 @@ def test_build_query_single_word(self):
self.sq.add_filter('content', 'hello')
self.assertEqual(self.sq.build_query(), 'hello')

def test_build_query_boolean(self):
self.sq.add_filter('content', True)
self.assertEqual(self.sq.build_query(), 'true')

def test_build_query_datetime(self):
self.sq.add_filter('content', datetime.datetime(2009, 5, 8, 11, 28))
self.assertEqual(self.sq.build_query(), '2009-05-08T11:28:00.000Z')

def test_build_query_multiple_words_and(self):
self.sq.add_filter('content', 'hello')
self.sq.add_filter('content', 'world')
Expand Down

0 comments on commit 513b4c1

Please sign in to comment.