コード例 #1
0
    def test_filter(self):
        query = SearchQuery()
        assert query.request.filter is None
        query.filter("expr0")
        assert query.request.filter == "expr0"

        query = SearchQuery(filter="expr0")
        assert query.request.filter == "expr0"
        query.filter("expr1")
        assert query.request.filter == "expr1"
コード例 #2
0
def filter_query():
    # [START filter_query]
    from azure.search import SearchApiKeyCredential, SearchIndexClient, SearchQuery

    search_client = SearchIndexClient(service_endpoint, index_name,
                                      SearchApiKeyCredential(key))

    query = SearchQuery(search_text="WiFi")
    query.filter("Address/StateProvince eq 'FL' and Address/Country eq 'USA'")
    query.select("HotelName", "Rating")
    query.order_by("Rating desc")

    results = search_client.search(query=query)

    print("Florida hotels containing 'WiFi', sorted by Rating:")
    for result in results:
        print("    Name: {} (rating {})".format(result["HotelName"],
                                                result["Rating"]))
コード例 #3
0
    async def test_get_search_filter(self, api_key, endpoint, index_name, **kwargs):
        client = SearchIndexClient(
            endpoint, index_name, SearchApiKeyCredential(api_key)
        )

        query = SearchQuery(search_text="WiFi")
        query.filter("category eq 'Budget'")
        query.select("hotelName", "category", "description")
        query.order_by("hotelName desc")

        async with client:
            results = []
            async for x in await client.search(query=query):
                results.append(x)
            assert [x['hotelName'] for x in results] == sorted([x['hotelName'] for x in results], reverse=True)
            expected = {"category", "hotelName", "description", "@search.score", "@search.highlights"}
            assert all(set(x) == expected for x in results)
            assert all(x['category'] == "Budget" for x in results)