def test_suggest_bad_argument(self): client = SearchIndexClient("endpoint", "index name", CREDENTIAL) with pytest.raises(TypeError) as e: client.suggest("bad_query") assert str( e) == "Expected a SuggestQuery for 'query', but got {}".format( repr("bad_query"))
def test_suggest_query_argument(self, mock_suggest_post): client = SearchIndexClient("endpoint", "index name", CREDENTIAL) result = client.suggest( SuggestQuery(search_text="search text", suggester_name="sg")) assert mock_suggest_post.called assert mock_suggest_post.call_args[0] == () assert (mock_suggest_post.call_args[1]["suggest_request"].search_text == "search text")
def test_suggest(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexClient( endpoint, index_name, AzureKeyCredential(api_key) ) query = SuggestQuery(search_text="mot", suggester_name="sg") results = client.suggest(query=query) assert results == [ {"hotelId": "2", "text": "Cheapest hotel in town. Infact, a motel."}, {"hotelId": "9", "text": "Secret Point Motel"}, ]
def suggest_query(): # [START suggest_query] from azure.search.documents import SearchApiKeyCredential, SearchIndexClient, SuggestQuery search_client = SearchIndexClient(service_endpoint, index_name, SearchApiKeyCredential(key)) query = SuggestQuery(search_text="coffee", suggester_name="sg") results = search_client.suggest(query=query) print("Search suggestions for 'coffee'") for result in results: hotel = search_client.get_document(key=result["HotelId"]) print(" Text: {} for Hotel: {}".format(repr(result["text"]), hotel["HotelName"]))