mirror of
https://github.com/Hopiu/xapian-haystack.git
synced 2026-05-13 01:33:11 +00:00
__startswith has been implemented in new branch
This commit is contained in:
parent
4ea6f5eda1
commit
253382b41a
2 changed files with 18 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue