Converted model filtering to use pure boolean subquery

This commit is contained in:
David Sauve 2009-11-29 19:12:59 -05:00
parent 2a4b32f03b
commit 184f10af2d
2 changed files with 8 additions and 6 deletions

View file

@ -114,7 +114,7 @@ class XapianSearchQueryTestCase(TestCase):
def test_build_query_with_models(self):
self.sq.add_filter(SQ(content='hello'))
self.sq.add_model(MockModel)
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((hello AND XCONTENTTYPEcore.mockmodel))')
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((hello AND 0 * XCONTENTTYPEcore.mockmodel))')
self.sq.add_model(AnotherMockModel)
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((hello AND (XCONTENTTYPEcore.anothermockmodel OR XCONTENTTYPEcore.mockmodel)))')
self.assertEqual(self.sq.build_query().get_description(), 'Xapian::Query((hello AND (0 * XCONTENTTYPEcore.anothermockmodel OR 0 * XCONTENTTYPEcore.mockmodel)))')

View file

@ -890,10 +890,12 @@ class SearchQuery(BaseSearchQuery):
if self.models:
subqueries = [
xapian.Query('%s%s.%s' % (
DOCUMENT_CT_TERM_PREFIX,
model._meta.app_label, model._meta.module_name
)
xapian.Query(
xapian.Query.OP_SCALE_WEIGHT, xapian.Query('%s%s.%s' % (
DOCUMENT_CT_TERM_PREFIX,
model._meta.app_label, model._meta.module_name
)
), 0
) for model in self.models
]
query = xapian.Query(