Added support for not in 'in' based queries
This commit is contained in:
parent
09c12d88f7
commit
d197014a82
|
@ -125,16 +125,21 @@ class XapianSearchQueryTestCase(TestCase):
|
|||
self.sq.add_filter(SQ(title__in=["Dune", "Jaws"]))
|
||||
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((why AND (XTITLEdune OR XTITLEjaws)))')
|
||||
|
||||
def test_build_query_not_in_filter_single_words(self):
|
||||
self.sq.add_filter(SQ(content='why'))
|
||||
self.sq.add_filter(~SQ(title__in=["Dune", "Jaws"]))
|
||||
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((why AND (<alldocuments> AND_NOT (XTITLEdune OR XTITLEjaws))))')
|
||||
|
||||
def test_build_query_in_filter_multiple_words(self):
|
||||
self.sq.add_filter(SQ(content='why'))
|
||||
self.sq.add_filter(SQ(title__in=["A Famous Paper", "An Infamous Article"]))
|
||||
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((why AND ((XTITLEa PHRASE 3 XTITLEfamous PHRASE 3 XTITLEpaper) OR (XTITLEan PHRASE 3 XTITLEinfamous PHRASE 3 XTITLEarticle))))')
|
||||
|
||||
# def test_build_query_not_in_filter_multiple_words(self):
|
||||
# self.sq.add_filter(SQ(content='why'))
|
||||
# self.sq.add_filter(~SQ(title__in=["A Famous Paper", "An Infamous Article"]))
|
||||
# self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((why AND_NOT (XTITLEa famous paper OR XTITLEan infamous article)))')
|
||||
#
|
||||
def test_build_query_not_in_filter_multiple_words(self):
|
||||
self.sq.add_filter(SQ(content='why'))
|
||||
self.sq.add_filter(~SQ(title__in=["A Famous Paper", "An Infamous Article"]))
|
||||
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((why AND (<alldocuments> AND_NOT ((XTITLEa PHRASE 3 XTITLEfamous PHRASE 3 XTITLEpaper) OR (XTITLEan PHRASE 3 XTITLEinfamous PHRASE 3 XTITLEarticle)))))')
|
||||
|
||||
# def test_build_query_in_filter_datetime(self):
|
||||
# self.sq.add_filter(SQ(content='why'))
|
||||
# self.sq.add_filter(SQ(pub_date__in=[datetime.datetime(2009, 7, 6, 1, 56, 21)]))
|
||||
|
|
|
@ -1003,7 +1003,10 @@ class SearchQuery(BaseSearchQuery):
|
|||
xapian.Query.OP_OR, self._term_query(value, field)
|
||||
)
|
||||
)
|
||||
return xapian.Query(xapian.Query.OP_OR, query_list)
|
||||
if is_not:
|
||||
return xapian.Query(xapian.Query.OP_AND_NOT, self._all_query(), xapian.Query(xapian.Query.OP_OR, query_list))
|
||||
else:
|
||||
return xapian.Query(xapian.Query.OP_OR, query_list)
|
||||
|
||||
def _all_query(self):
|
||||
return xapian.Query('')
|
||||
|
|
Loading…
Reference in New Issue