本文整理汇总了Python中haystack.backends.solr_backend.SearchQuery.get_results方法的典型用法代码示例。如果您正苦于以下问题:Python SearchQuery.get_results方法的具体用法?Python SearchQuery.get_results怎么用?Python SearchQuery.get_results使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haystack.backends.solr_backend.SearchQuery
的用法示例。
在下文中一共展示了SearchQuery.get_results方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LiveSolrSearchQueryTestCase
# 需要导入模块: from haystack.backends.solr_backend import SearchQuery [as 别名]
# 或者: from haystack.backends.solr_backend.SearchQuery import get_results [as 别名]
class LiveSolrSearchQueryTestCase(TestCase):
fixtures = ["initial_data.json"]
def setUp(self):
super(LiveSolrSearchQueryTestCase, self).setUp()
# Stow.
self.old_solr_url = getattr(settings, "HAYSTACK_SOLR_URL", "http://localhost:9001/solr/test_default")
settings.HAYSTACK_SOLR_URL = "http://localhost:9001/solr/test_default"
self.sq = SearchQuery(backend=SearchBackend())
# Force indexing of the content.
for mock in MockModel.objects.all():
mock.save()
def tearDown(self):
settings.HAYSTACK_SOLR_URL = self.old_solr_url
super(LiveSolrSearchQueryTestCase, self).tearDown()
def test_get_spelling(self):
self.sq.add_filter("content", "Indx")
self.assertEqual(self.sq.get_spelling_suggestion(), u"index")
self.assertEqual(self.sq.get_spelling_suggestion("indexy"), 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=SearchBackend())
self.sq.add_filter("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=SearchBackend())
self.sq.add_filter("name", "bar")
self.sq.add_filter("text", "moof")
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:bar AND text:moof")
# Restore.
settings.DEBUG = old_debug
示例2: LiveSolrSearchQueryTestCase
# 需要导入模块: from haystack.backends.solr_backend import SearchQuery [as 别名]
# 或者: from haystack.backends.solr_backend.SearchQuery import get_results [as 别名]
class LiveSolrSearchQueryTestCase(TestCase):
fixtures = ["initial_data.json"]
def setUp(self):
super(LiveSolrSearchQueryTestCase, self).setUp()
# Wipe it clean.
clear_solr_index()
site = SearchSite()
site.register(MockModel, SolrMockSearchIndex)
sb = SearchBackend(site=site)
smmi = SolrMockSearchIndex(MockModel, backend=sb)
self.sq = SearchQuery(backend=sb)
# Force indexing of the content.
mockmodel_index = site.get_index(MockModel)
mockmodel_index.update()
def test_get_spelling(self):
self.sq.add_filter(SQ(content="Indexy"))
self.assertEqual(self.sq.get_spelling_suggestion(), u"index")
self.assertEqual(self.sq.get_spelling_suggestion("indexy"), 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=SearchBackend())
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=SearchBackend())
self.sq.add_filter(SQ(name="bar"))
self.sq.add_filter(SQ(text="moof"))
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:bar AND text:moof)")
# Restore.
settings.DEBUG = old_debug
示例3: LiveSolrSearchQueryTestCase
# 需要导入模块: from haystack.backends.solr_backend import SearchQuery [as 别名]
# 或者: from haystack.backends.solr_backend.SearchQuery import get_results [as 别名]
class LiveSolrSearchQueryTestCase(TestCase):
fixtures = ['initial_data.json']
def setUp(self):
super(LiveSolrSearchQueryTestCase, self).setUp()
# Stow.
self.old_solr_url = getattr(settings, 'HAYSTACK_SOLR_URL', 'http://localhost:9001/solr/test_default')
settings.HAYSTACK_SOLR_URL = 'http://localhost:9001/solr/test_default'
self.sq = SearchQuery(backend=SearchBackend())
# Force indexing of the content.
for mock in MockModel.objects.all():
mock.save()
def tearDown(self):
settings.HAYSTACK_SOLR_URL = self.old_solr_url
super(LiveSolrSearchQueryTestCase, self).tearDown()
def test_get_spelling(self):
self.sq.add_filter(SQ(content='Indx'))
self.assertEqual(self.sq.get_spelling_suggestion(), u'index')
self.assertEqual(self.sq.get_spelling_suggestion('indexy'), 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=SearchBackend())
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=SearchBackend())
self.sq.add_filter(SQ(name='bar'))
self.sq.add_filter(SQ(text='moof'))
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:bar AND text:moof)')
# Restore.
settings.DEBUG = old_debug