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


Python elasticsearch.ElasticSearchQuery类代码示例

本文整理汇总了Python中wagtail.wagtailsearch.backends.elasticsearch.ElasticSearchQuery的典型用法代码示例。如果您正苦于以下问题:Python ElasticSearchQuery类的具体用法?Python ElasticSearchQuery怎么用?Python ElasticSearchQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_lte_lookup

    def test_lte_lookup(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.filter(published_date__lte=datetime.datetime(2014, 4, 29)), "Hello")

        # Check it
        expected_result = {'filtered': {'filter': {'and': [{'prefix': {'content_type': 'searchtests_searchtest'}}, {'range': {'published_date_filter': {'lte': '2014-04-29'}}}]}, 'query': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例2: test_custom_ordering_multiple

    def test_custom_ordering_multiple(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.order_by('published_date', 'live'), "Hello", order_by_relevance=False)

        # Check it
        expected_result = [{'published_date_filter': 'asc'}, {'live_filter': 'asc'}]
        self.assertDictEqual(query.get_sort(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例3: test_multiple_fields_with_and_operator

    def test_multiple_fields_with_and_operator(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.all(), "Hello", fields=['title', 'content'], operator='and')

        # Check it
        expected_result = {'filtered': {'filter': {'prefix': {'content_type': 'searchtests_searchtest'}}, 'query': {'multi_match': {'fields': ['title', 'content'], 'query': 'Hello', 'operator': 'and'}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例4: test_startswith_lookup

    def test_startswith_lookup(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.filter(title__startswith="Test"), "Hello")

        # Check it
        expected_result = {'filtered': {'filter': {'and': [{'prefix': {'content_type': 'searchtests_searchtest'}}, {'prefix': {'title_filter': 'Test'}}]}, 'query': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例5: test_fields

    def test_fields(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.all(), "Hello", fields=['title'])

        # Check it
        expected_result = {'filtered': {'filter': {'prefix': {'content_type': 'searchtests_searchtest'}}, 'query': {'match': {'title': 'Hello'}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例6: test_negated_filter

    def test_negated_filter(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.exclude(live=True), "Hello")

        # Check it
        expected_result = {'filtered': {'filter': {'and': [{'prefix': {'content_type': 'searchtests_searchtest'}}, {'not': {'term': {'live_filter': True}}}]}, 'query': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例7: test_none_query_string

    def test_none_query_string(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.all(), None)

        # Check it
        expected_result = {'filtered': {'filter': {'prefix': {'content_type': 'searchtests_searchtest'}}, 'query': {'match_all': {}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例8: test_simple

    def test_simple(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.all(), "Hello")

        # Check it
        expected_result = {'filtered': {'filter': {'prefix': {'content_type': 'searchtests_searchtest'}}, 'query': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
        self.assertDictEqual(query.get_query(), expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:7,代码来源:test_elasticsearch_backend.py

示例9: test_or_filter

    def test_or_filter(self):
        # Create a query
        query = ElasticSearchQuery(models.SearchTest.objects.filter(Q(title="Test") | Q(live=True)), "Hello")

        # Make sure field filters are sorted (as they can be in any order which may cause false positives)
        query = query.get_query()
        field_filters = query['filtered']['filter']['and'][1]['or']
        field_filters[:] = sorted(field_filters, key=lambda f: list(f['term'].keys())[0])

        # Check it
        expected_result = {'filtered': {'filter': {'and': [{'prefix': {'content_type': 'searchtests_searchtest'}}, {'or': [{'term': {'live_filter': True}}, {'term': {'title_filter': 'Test'}}]}]}, 'query': {'multi_match': {'query': 'Hello', 'fields': ['_all', '_partials']}}}}
        self.assertDictEqual(query, expected_result)
开发者ID:albertoconnor,项目名称:wagtail,代码行数:12,代码来源:test_elasticsearch_backend.py


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