mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-03-16 22:20:31 +00:00
Four tests passing now. Recursively parsing the search nodes and negated on NOT as required.
This commit is contained in:
parent
35f51e97bc
commit
09ffc6d481
2 changed files with 28 additions and 15 deletions
|
|
@ -61,10 +61,10 @@ class XapianSearchQueryTestCase(TestCase):
|
|||
self.sq.add_filter(SQ(content='world'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((hello AND world))')
|
||||
|
||||
# def test_build_query_multiple_words_not(self):
|
||||
# self.sq.add_filter(~SQ(content='hello'))
|
||||
# self.sq.add_filter(~SQ(content='world'))
|
||||
# self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((NOT hello NOT world))')
|
||||
def test_build_query_multiple_words_not(self):
|
||||
self.sq.add_filter(~SQ(content='hello'))
|
||||
self.sq.add_filter(~SQ(content='world'))
|
||||
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query(((<alldocuments> AND_NOT hello) AND (<alldocuments> AND_NOT world)))')
|
||||
|
||||
# def test_build_query_multiple_words_or(self):
|
||||
# self.sq.add_filter('content', 'hello', use_or=True)
|
||||
|
|
|
|||
|
|
@ -935,19 +935,32 @@ class SearchQuery(BaseSearchQuery):
|
|||
|
||||
def build_query(self):
|
||||
if not self.query_filter:
|
||||
query = xapian.Query('')
|
||||
return xapian.Query('')
|
||||
else:
|
||||
query_list = []
|
||||
|
||||
for child in self.query_filter.children:
|
||||
expression, value = child
|
||||
query_list.append(value)
|
||||
|
||||
query = xapian.Query(xapian.Query.OP_AND, query_list)
|
||||
|
||||
return query
|
||||
return self._query_from_search_node(self.query_filter)
|
||||
|
||||
def build_query_fragment(self, field, filter_type, value):
|
||||
def _query_from_search_node(self, search_node, is_not=False):
|
||||
query_list = []
|
||||
|
||||
for child in search_node.children:
|
||||
if isinstance(child, SearchNode):
|
||||
query_list.append(
|
||||
xapian.Query(
|
||||
xapian.Query.OP_AND,
|
||||
self._query_from_search_node(child, child.negated)
|
||||
)
|
||||
)
|
||||
else:
|
||||
expression, value = child
|
||||
if is_not:
|
||||
# DS_TODO: This can almost definitely be improved.
|
||||
query_list.append(xapian.Query(xapian.Query.OP_AND_NOT, '', value))
|
||||
else:
|
||||
query_list.append(xapian.Query(value))
|
||||
|
||||
return xapian.Query(xapian.Query.OP_AND, query_list)
|
||||
|
||||
def build_sub_query(self, value):
|
||||
return xapian.Query(value)
|
||||
|
||||
#
|
||||
|
|
|
|||
Loading…
Reference in a new issue