def test_autocomplete_bad_argument(self): client = SearchIndexClient("endpoint", "index name", CREDENTIAL) with pytest.raises(TypeError) as e: client.autocomplete("bad_query") assert str( e ) == "Expected a AutocompleteQuery for 'query', but got {}".format( repr("bad_query"))
def test_autocomplete_query_argument(self, mock_autocomplete_post): client = SearchIndexClient("endpoint", "index name", CREDENTIAL) result = client.autocomplete( AutocompleteQuery(search_text="search text", suggester_name="sg")) assert mock_autocomplete_post.called assert mock_autocomplete_post.call_args[0] == () assert (mock_autocomplete_post.call_args[1] ["autocomplete_request"].search_text == "search text")
def autocomplete_query(): # [START autocomplete_query] from azure.search import AutocompleteQuery, SearchApiKeyCredential, SearchIndexClient search_client = SearchIndexClient(service_endpoint, index_name, SearchApiKeyCredential(key)) query = AutocompleteQuery(search_text="bo", suggester_name="sg") results = search_client.autocomplete(query=query) print("Autocomplete suggestions for 'bo'") for result in results: print(" Completion: {}".format(result["text"]))
def test_autocomplete(self, api_key, endpoint, index_name, **kwargs): client = SearchIndexClient(endpoint, index_name, SearchApiKeyCredential(api_key)) query = AutocompleteQuery(search_text="mot", suggester_name="sg") results = client.autocomplete(query=query) assert results == [{"text": "motel", "query_plus_text": "motel"}]