mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-04-27 01:54:50 +00:00
Only thing missing now is query_facets
This commit is contained in:
parent
1fe78fc384
commit
f1b7c04c12
2 changed files with 38 additions and 12 deletions
|
|
@ -352,6 +352,8 @@ class LiveXapianMockSearchIndex(indexes.SearchIndex):
|
|||
text = indexes.CharField(document=True, use_template=True)
|
||||
name = indexes.CharField(model_attr='author')
|
||||
pub_date = indexes.DateField(model_attr='pub_date')
|
||||
created = indexes.DateField()
|
||||
title = indexes.CharField()
|
||||
|
||||
|
||||
class LiveXapianSearchQueryTestCase(TestCase):
|
||||
|
|
@ -385,21 +387,29 @@ class LiveXapianSearchQueryTestCase(TestCase):
|
|||
self.assertEqual([result.pk for result in self.sq.get_results()], [1])
|
||||
|
||||
def test_build_query_gt(self):
|
||||
self.sq.add_filter(SQ(name__gt='a'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query(VALUE_RANGE 2 a zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)')
|
||||
self.sq.add_filter(SQ(name__gt='m'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query((<alldocuments> AND_NOT VALUE_RANGE 3 a m))')
|
||||
|
||||
def test_build_query_gte(self):
|
||||
self.sq.add_filter(SQ(name__gte='m'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query(VALUE_RANGE 3 m zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)')
|
||||
|
||||
def test_build_query_lt(self):
|
||||
self.sq.add_filter(SQ(name__lt='m'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query(VALUE_RANGE 2 a m)')
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query((<alldocuments> AND_NOT VALUE_RANGE 3 m zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz))')
|
||||
|
||||
def test_build_query_lte(self):
|
||||
self.sq.add_filter(SQ(name__lte='m'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query(VALUE_RANGE 3 a m)')
|
||||
|
||||
def test_build_query_multiple_filter_types(self):
|
||||
self.sq.add_filter(SQ(content='why'))
|
||||
# self.sq.add_filter(SQ(pub_date__lte='2009-02-10 01:59:00'))
|
||||
self.sq.add_filter(SQ(pub_date__lte=datetime.datetime(2009, 2, 10, 1, 59, 0)))
|
||||
self.sq.add_filter(SQ(name__gt='david'))
|
||||
# self.sq.add_filter(SQ(created__lt='2009-02-12 12:13:00'))
|
||||
# self.sq.add_filter(SQ(title__gte='B'))
|
||||
self.sq.add_filter(SQ(created__lt=datetime.datetime(2009, 2, 12, 12, 13, 0)))
|
||||
self.sq.add_filter(SQ(title__gte='B'))
|
||||
self.sq.add_filter(SQ(id__in=[1, 2, 3]))
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query((why AND VALUE_RANGE 2 david zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz AND (XID1 OR XID2 OR XID3)))')
|
||||
self.assertEqual(self.sq.build_query().get_description(), u'Xapian::Query((why AND VALUE_RANGE 2 00010101000000 20090210015900 AND (<alldocuments> AND_NOT VALUE_RANGE 3 a david) AND (<alldocuments> AND_NOT VALUE_RANGE 4 20090212121300 99990101000000) AND VALUE_RANGE 1 b zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz AND (XID1 OR XID2 OR XID3)))')
|
||||
|
||||
def test_log_query(self):
|
||||
backends.reset_search_queries()
|
||||
|
|
|
|||
|
|
@ -862,11 +862,11 @@ class SearchQuery(BaseSearchQuery):
|
|||
elif filter_type == 'gt':
|
||||
query_list.append(self._filter_gt(term, field, is_not))
|
||||
elif filter_type == 'gte':
|
||||
pass
|
||||
query_list.append(self._filter_gte(term, field, is_not))
|
||||
elif filter_type == 'lt':
|
||||
query_list.append(self._filter_lt(term, field, is_not))
|
||||
elif filter_type == 'lte':
|
||||
pass
|
||||
query_list.append(self._filter_lte(term, field, is_not))
|
||||
elif filter_type == 'startswith':
|
||||
query_list.append(self._filter_startswith(term, field, is_not))
|
||||
elif filter_type == 'in':
|
||||
|
|
@ -982,21 +982,37 @@ class SearchQuery(BaseSearchQuery):
|
|||
return self._filter_in(list(term_list), field, is_not)
|
||||
|
||||
def _filter_gt(self, term, field, is_not):
|
||||
return self._filter_lte(term, field, is_not=(is_not != True))
|
||||
|
||||
def _filter_lt(self, term, field, is_not):
|
||||
return self._filter_gte(term, field, is_not=(is_not != True))
|
||||
|
||||
def _filter_gte(self, term, field, is_not):
|
||||
"""
|
||||
Private method that returns a xapian.Query that searches for any term
|
||||
that is greater than `term` in a specified `field`.
|
||||
"""
|
||||
vrp = XHValueRangeProcessor(self.backend)
|
||||
pos, begin, end = vrp('%s:%s' % (field, term), '*')
|
||||
pos, begin, end = vrp('%s:%s' % (field, _marshal_value(term)), '*')
|
||||
if is_not:
|
||||
return xapian.Query(xapian.Query.OP_AND_NOT,
|
||||
self._all_query(),
|
||||
xapian.Query(xapian.Query.OP_VALUE_RANGE, pos, begin, end)
|
||||
)
|
||||
return xapian.Query(xapian.Query.OP_VALUE_RANGE, pos, begin, end)
|
||||
|
||||
def _filter_lt(self, term, field, is_not):
|
||||
def _filter_lte(self, term, field, is_not):
|
||||
"""
|
||||
Private method that returns a xapian.Query that searches for any term
|
||||
that is less than `term` in a specified `field`.
|
||||
"""
|
||||
vrp = XHValueRangeProcessor(self.backend)
|
||||
pos, begin, end = vrp('%s:' % field, '%s' % term)
|
||||
pos, begin, end = vrp('%s:' % field, '%s' % _marshal_value(term))
|
||||
if is_not:
|
||||
return xapian.Query(xapian.Query.OP_AND_NOT,
|
||||
self._all_query(),
|
||||
xapian.Query(xapian.Query.OP_VALUE_RANGE, pos, begin, end)
|
||||
)
|
||||
return xapian.Query(xapian.Query.OP_VALUE_RANGE, pos, begin, end)
|
||||
|
||||
def _all_query(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue