当前位置: 首页>>代码示例>>Python>>正文


Python SearchConnection.search方法代码示例

本文整理汇总了Python中boto.cloudsearch2.search.SearchConnection.search方法的典型用法代码示例。如果您正苦于以下问题:Python SearchConnection.search方法的具体用法?Python SearchConnection.search怎么用?Python SearchConnection.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.cloudsearch2.search.SearchConnection的用法示例。


在下文中一共展示了SearchConnection.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CloudSearchConnectionTest

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
class CloudSearchConnectionTest(unittest.TestCase):
    cloudsearch = True

    def setUp(self):
        super(CloudSearchConnectionTest, self).setUp()
        self.conn = SearchConnection(
            endpoint='test-domain.cloudsearch.amazonaws.com'
        )

    def test_expose_additional_error_info(self):
        mpo = mock.patch.object
        fake = FakeResponse()
        fake.content = 'Nopenopenope'

        # First, in the case of a non-JSON, non-403 error.
        with mpo(self.conn.session, 'get', return_value=fake) as mock_request:
            with self.assertRaises(SearchServiceException) as cm:
                self.conn.search(q='not_gonna_happen')

            self.assertTrue('non-json response' in str(cm.exception))
            self.assertTrue('Nopenopenope' in str(cm.exception))

        # Then with JSON & an 'error' key within.
        fake.content = json.dumps({
            'error': "Something went wrong. Oops."
        })

        with mpo(self.conn.session, 'get', return_value=fake) as mock_request:
            with self.assertRaises(SearchServiceException) as cm:
                self.conn.search(q='no_luck_here')

            self.assertTrue('Unknown error' in str(cm.exception))
            self.assertTrue('went wrong. Oops' in str(cm.exception))
开发者ID:merckhung,项目名称:libui,代码行数:35,代码来源:test_search.py

示例2: test_cloudsearch_result_fields_multiple

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_result_fields_multiple(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(q='Test', return_fields=['author', 'title'])

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        self.assertEqual(args['return'], ['author,title'])
开发者ID:merckhung,项目名称:libui,代码行数:10,代码来源:test_search.py

示例3: test_cloudsearch_facet_sort_multiple

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_facet_sort_multiple(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(q='Test', facet={'author': {'sort': 'alpha'},
                                       'cat': {'sort': 'count'}})

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        self.assertEqual(args['facet.author'], ['{"sort": "alpha"}'])
        self.assertEqual(args['facet.cat'], ['{"sort": "count"}'])
开发者ID:merckhung,项目名称:libui,代码行数:12,代码来源:test_search.py

示例4: test_cloudsearch_search_details

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_search_details(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(q='Test', size=50, start=20)

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        self.assertEqual(args['q'], ["Test"])
        self.assertEqual(args['size'], ["50"])
        self.assertEqual(args['start'], ["20"])
开发者ID:merckhung,项目名称:libui,代码行数:12,代码来源:test_search.py

示例5: test_cloudsearch_qsearch

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_qsearch(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(q='Test')

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        self.assertEqual(args['q'], ["Test"])
        self.assertEqual(args['start'], ["0"])
        self.assertEqual(args['size'], ["10"])
开发者ID:merckhung,项目名称:libui,代码行数:12,代码来源:test_search.py

示例6: test_cloudsearch_facet_sort_single

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_facet_sort_single(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(q='Test', facet={'author': {'sort': 'alpha'}})

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        print(args)

        self.assertEqual(args[b'facet.author'], [b'{"sort": "alpha"}'])
开发者ID:CashStar,项目名称:boto,代码行数:12,代码来源:test_search.py

示例7: test_cloudsearch_facet_constraint_single

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_facet_constraint_single(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(
            q='Test',
            facet={'author': "'John Smith','Mark Smith'"})

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        self.assertEqual(args['facet.author'],
                         ["'John Smith','Mark Smith'"])
开发者ID:merckhung,项目名称:libui,代码行数:13,代码来源:test_search.py

示例8: test_cloudsearch_facet_constraint_multiple

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_facet_constraint_multiple(self):
        search = SearchConnection(endpoint=HOSTNAME)

        search.search(
            q='Test',
            facet={'author': "'John Smith','Mark Smith'",
                   'category': "'News','Reviews'"})

        args = self.get_args(HTTPretty.last_request.raw_requestline)

        self.assertEqual(args[b'facet.author'],
                         [b"'John Smith','Mark Smith'"])
        self.assertEqual(args[b'facet.category'],
                         [b"'News','Reviews'"])
开发者ID:CashStar,项目名称:boto,代码行数:16,代码来源:test_search.py

示例9: test_cloudsearch_results_internal_consistancy

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_results_internal_consistancy(self):
        """Check the documents length matches the iterator details"""
        search = SearchConnection(endpoint=HOSTNAME)

        results = search.search(q='Test')

        self.assertEqual(len(results), len(results.docs))
开发者ID:merckhung,项目名称:libui,代码行数:9,代码来源:test_search.py

示例10: CloudSearchConnectionTest

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
class CloudSearchConnectionTest(AWSMockServiceTestCase):
    cloudsearch = True
    connection_class = CloudSearchConnection

    def setUp(self):
        super(CloudSearchConnectionTest, self).setUp()
        self.conn = SearchConnection(
            endpoint='test-domain.cloudsearch.amazonaws.com'
        )

    def test_expose_additional_error_info(self):
        mpo = mock.patch.object
        fake = FakeResponse()
        fake.content = b'Nopenopenope'

        # First, in the case of a non-JSON, non-403 error.
        with mpo(self.conn.session, 'get', return_value=fake) as mock_request:
            with self.assertRaises(SearchServiceException) as cm:
                self.conn.search(q='not_gonna_happen')

            self.assertTrue('non-json response' in str(cm.exception))
            self.assertTrue('Nopenopenope' in str(cm.exception))

        # Then with JSON & an 'error' key within.
        fake.content = json.dumps({
            'error': "Something went wrong. Oops."
        }).encode('utf-8')

        with mpo(self.conn.session, 'get', return_value=fake) as mock_request:
            with self.assertRaises(SearchServiceException) as cm:
                self.conn.search(q='no_luck_here')

            self.assertTrue('Unknown error' in str(cm.exception))
            self.assertTrue('went wrong. Oops' in str(cm.exception))

    def test_proxy(self):
        conn = self.service_connection
        conn.proxy = "127.0.0.1"
        conn.proxy_user = "john.doe"
        conn.proxy_pass="p4ssw0rd"
        conn.proxy_port="8180"
        conn.use_proxy = True

        domain = Domain(conn, DEMO_DOMAIN_DATA)
        search = SearchConnection(domain=domain)
        self.assertEqual(search.session.proxies, {'http': 'http://john.doe:[email protected]:8180'})
开发者ID:10sr,项目名称:hue,代码行数:48,代码来源:test_search.py

示例11: test_cloudsearch_results_info

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_results_info(self):
        """Check num_pages_needed is calculated correctly"""
        search = SearchConnection(endpoint=HOSTNAME)

        results = search.search(q='Test')

        # This relies on the default response which is fed into HTTPretty
        self.assertEqual(results.num_pages_needed, 3.0)
开发者ID:merckhung,项目名称:libui,代码行数:10,代码来源:test_search.py

示例12: test_cloudsearch_search_facets

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_search_facets(self):
        #self.response['facets'] = {'tags': {}}

        search = SearchConnection(endpoint=HOSTNAME)

        results = search.search(q='Test', facet={'tags': {}})

        self.assertTrue('tags' not in results.facets)
        self.assertEqual(results.facets['animals'], {u'lions': u'1', u'fish': u'2'})
开发者ID:merckhung,项目名称:libui,代码行数:11,代码来源:test_search.py

示例13: test_cloudsearch_results_iterator

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_results_iterator(self):
        """Check the results iterator"""
        search = SearchConnection(endpoint=HOSTNAME)

        results = search.search(q='Test')
        results_correct = iter(["12341", "12342", "12343", "12344",
                                "12345", "12346", "12347"])
        for x in results:
            self.assertEqual(x['id'], next(results_correct))
开发者ID:merckhung,项目名称:libui,代码行数:11,代码来源:test_search.py

示例14: test_cloudsearch_results_meta

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_results_meta(self):
        """Check returned metadata is parsed correctly"""
        search = SearchConnection(endpoint=HOSTNAME)

        results = search.search(q='Test')

        # These rely on the default response which is fed into HTTPretty
        self.assertEqual(results.hits, 30)
        self.assertEqual(results.docs[0]['fields']['rank'], 1)
开发者ID:merckhung,项目名称:libui,代码行数:11,代码来源:test_search.py

示例15: test_cloudsearch_results_hits

# 需要导入模块: from boto.cloudsearch2.search import SearchConnection [as 别名]
# 或者: from boto.cloudsearch2.search.SearchConnection import search [as 别名]
    def test_cloudsearch_results_hits(self):
        """Check that documents are parsed properly from AWS"""
        search = SearchConnection(endpoint=HOSTNAME)

        results = search.search(q='Test')

        hits = list(map(lambda x: x['id'], results.docs))

        # This relies on the default response which is fed into HTTPretty
        self.assertEqual(
            hits, ["12341", "12342", "12343", "12344",
                   "12345", "12346", "12347"])
开发者ID:merckhung,项目名称:libui,代码行数:14,代码来源:test_search.py


注:本文中的boto.cloudsearch2.search.SearchConnection.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。