__startswith has been implemented in new branch

This commit is contained in:
David Sauve 2009-12-04 15:41:32 -05:00
parent 4ea6f5eda1
commit 253382b41a
2 changed files with 18 additions and 3 deletions

View file

@ -373,6 +373,14 @@ class LiveXapianSearchQueryTestCase(TestCase):
self.assertEqual(self.sq.get_spelling_suggestion(), u'indexed')
self.assertEqual(self.sq.get_spelling_suggestion('indxd'), u'indexed')
def test_startswith(self):
self.sq.add_filter(SQ(name__startswith='da*'))
self.assertEqual([result.pk for result in self.sq.get_results()], [1, 2, 3])
self.sq = SearchQuery(backend=SearchBackend())
self.sq.add_filter(SQ(name__startswith='daniel1'))
self.assertEqual([result.pk for result in self.sq.get_results()], [1])
def test_log_query(self):
backends.reset_search_queries()
self.assertEqual(len(backends.queries), 0)

View file

@ -480,6 +480,11 @@ class SearchBackend(BaseSearchBackend):
Returns a xapian.Query
"""
if query_string == '*':
return xapian.Query('') # Match everything
elif query_string == '':
return xapian.Query() # Match nothing
flags = xapian.QueryParser.FLAG_PARTIAL \
| xapian.QueryParser.FLAG_PHRASE \
| xapian.QueryParser.FLAG_BOOLEAN \
@ -969,10 +974,12 @@ class SearchQuery(BaseSearchQuery):
A xapian.Query
"""
sb = SearchBackend()
term_list = set()
for t in sb._database().allterms():
print t
term_list = [term, 'foo']
return self._filter_in(term_list, field, is_not)
if t.term.startswith(term.rstrip('*')):
term_list.add(t.term)
return self._filter_in(list(term_list), field, is_not)
def _all_query(self):