本文整理匯總了Python中haystack.backends.whoosh_backend.SearchQuery.get_spelling_suggestion方法的典型用法代碼示例。如果您正苦於以下問題:Python SearchQuery.get_spelling_suggestion方法的具體用法?Python SearchQuery.get_spelling_suggestion怎麽用?Python SearchQuery.get_spelling_suggestion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類haystack.backends.whoosh_backend.SearchQuery
的用法示例。
在下文中一共展示了SearchQuery.get_spelling_suggestion方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: LiveWhooshSearchQueryTestCase
# 需要導入模塊: from haystack.backends.whoosh_backend import SearchQuery [as 別名]
# 或者: from haystack.backends.whoosh_backend.SearchQuery import get_spelling_suggestion [as 別名]
class LiveWhooshSearchQueryTestCase(TestCase):
def setUp(self):
super(LiveWhooshSearchQueryTestCase, self).setUp()
# Stow.
temp_path = os.path.join('tmp', 'test_whoosh_query')
self.old_whoosh_path = getattr(settings, 'HAYSTACK_WHOOSH_PATH', temp_path)
settings.HAYSTACK_WHOOSH_PATH = temp_path
self.site = WhooshSearchSite()
self.sb = SearchBackend(site=self.site)
self.smmi = WhooshMockSearchIndex(MockModel, backend=self.sb)
self.site.register(MockModel, WhooshMockSearchIndex)
self.sb.setup()
self.raw_whoosh = self.sb.index
self.parser = QueryParser(self.sb.content_field_name, schema=self.sb.schema)
self.sb.delete_index()
self.sample_objs = []
for i in xrange(1, 4):
mock = MockModel()
mock.id = i
mock.author = 'daniel%s' % i
mock.pub_date = date(2009, 2, 25) - timedelta(days=i)
self.sample_objs.append(mock)
self.sq = SearchQuery(backend=self.sb)
def tearDown(self):
if os.path.exists(settings.HAYSTACK_WHOOSH_PATH):
shutil.rmtree(settings.HAYSTACK_WHOOSH_PATH)
settings.HAYSTACK_WHOOSH_PATH = self.old_whoosh_path
super(LiveWhooshSearchQueryTestCase, self).tearDown()
def test_get_spelling(self):
self.sb.update(self.smmi, self.sample_objs)
self.sq.add_filter('content', 'Indx')
self.assertEqual(self.sq.get_spelling_suggestion(), u'index')
示例2: LiveWhooshSearchQueryTestCase
# 需要導入模塊: from haystack.backends.whoosh_backend import SearchQuery [as 別名]
# 或者: from haystack.backends.whoosh_backend.SearchQuery import get_spelling_suggestion [as 別名]
class LiveWhooshSearchQueryTestCase(TestCase):
def setUp(self):
super(LiveWhooshSearchQueryTestCase, self).setUp()
# Stow.
temp_path = os.path.join('tmp', 'test_whoosh_query')
self.old_whoosh_path = getattr(settings, 'HAYSTACK_WHOOSH_PATH', temp_path)
settings.HAYSTACK_WHOOSH_PATH = temp_path
self.site = SearchSite()
self.sb = SearchBackend(site=self.site)
self.smmi = WhooshMockSearchIndex(MockModel, backend=self.sb)
self.site.register(MockModel, WhooshMockSearchIndex)
self.sb.setup()
self.raw_whoosh = self.sb.index
self.parser = QueryParser(self.sb.content_field_name, schema=self.sb.schema)
self.sb.delete_index()
self.sample_objs = []
for i in xrange(1, 4):
mock = MockModel()
mock.id = i
mock.author = 'daniel%s' % i
mock.pub_date = date(2009, 2, 25) - timedelta(days=i)
self.sample_objs.append(mock)
self.sq = SearchQuery(backend=self.sb)
def tearDown(self):
if os.path.exists(settings.HAYSTACK_WHOOSH_PATH):
shutil.rmtree(settings.HAYSTACK_WHOOSH_PATH)
settings.HAYSTACK_WHOOSH_PATH = self.old_whoosh_path
super(LiveWhooshSearchQueryTestCase, self).tearDown()
def test_get_spelling(self):
self.sb.update(self.smmi, self.sample_objs)
self.sq.add_filter(SQ(content='Indx'))
self.assertEqual(self.sq.get_spelling_suggestion(), u'index')
def test_log_query(self):
from django.conf import settings
from haystack import backends
backends.reset_search_queries()
self.assertEqual(len(backends.queries), 0)
# Stow.
old_debug = settings.DEBUG
settings.DEBUG = False
len(self.sq.get_results())
self.assertEqual(len(backends.queries), 0)
settings.DEBUG = True
# Redefine it to clear out the cached results.
self.sq = SearchQuery(backend=self.sb)
self.sq.add_filter(SQ(name='bar'))
len(self.sq.get_results())
self.assertEqual(len(backends.queries), 1)
self.assertEqual(backends.queries[0]['query_string'], 'name:bar')
# And again, for good measure.
self.sq = SearchQuery(backend=self.sb)
self.sq.add_filter(SQ(name='baz'))
self.sq.add_filter(SQ(text='foo'))
len(self.sq.get_results())
self.assertEqual(len(backends.queries), 2)
self.assertEqual(backends.queries[0]['query_string'], 'name:bar')
self.assertEqual(backends.queries[1]['query_string'], u'(name:baz AND text:foo)')
# Restore.
settings.DEBUG = old_debug