本文整理汇总了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