當前位置: 首頁>>代碼示例>>Python>>正文


Python SearchQuery.get_results方法代碼示例

本文整理匯總了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
開發者ID:wxtr,項目名稱:django-haystack,代碼行數:60,代碼來源:solr_backend.py

示例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
開發者ID:pombredanne,項目名稱:haystack-with-only,代碼行數:60,代碼來源:solr_backend.py

示例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
開發者ID:smulloni,項目名稱:django-haystack,代碼行數:59,代碼來源:solr_backend.py


注:本文中的haystack.backends.solr_backend.SearchQuery.get_results方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。