def test_repr(self):
        query = AutocompleteQuery(search_text="foo bar", suggester_name="sg")
        assert repr(query) == "<AutocompleteQuery [foo bar]>"

        query = AutocompleteQuery(search_text="aaaaabbbbb" * 200,
                                  suggester_name="sg")
        assert len(repr(query)) == 1024
 def test_autocomplete(self, api_key, endpoint, index_name, **kwargs):
     client = SearchIndexClient(
         endpoint, index_name, AzureKeyCredential(api_key)
     )
     query = AutocompleteQuery(search_text="mot", suggester_name="sg")
     results = client.autocomplete(query=query)
     assert results == [{"text": "motel", "query_plus_text": "motel"}]
 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 test_filter(self):
        query = AutocompleteQuery(search_text="text", suggester_name="sg")
        assert query.request.filter is None
        query.filter("expr0")
        assert query.request.filter == "expr0"

        query = AutocompleteQuery(search_text="text",
                                  suggester_name="sg",
                                  filter="expr1")
        assert query.request.filter == "expr1"
        query.filter("expr2")
        assert query.request.filter == "expr2"
Beispiel #5
0
def autocomplete_query():
    # [START autocomplete_query]
    from azure.search.documents 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"]))
Beispiel #6
0
async def autocomplete_query():
    # [START autocomplete_query_async]
    from azure.core.credentials import AzureKeyCredential
    from azure.search.documents.aio import SearchIndexClient
    from azure.search.documents import AutocompleteQuery

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

    query = AutocompleteQuery(search_text="bo", suggester_name="sg")

    async with search_client:
        results = await search_client.autocomplete(query=query)

        print("Autocomplete suggestions for 'bo'")
        for result in results:
            print("    Completion: {}".format(result["text"]))
 def test_kwargs_forwarded(self, mock_request):
     mock_request.return_value = None
     AutocompleteQuery(foo=10, bar=20)
     assert mock_request.called
     assert mock_request.call_args[0] == ()
     assert mock_request.call_args[1] == {"foo": 10, "bar": 20}
 def test_init(self):
     query = AutocompleteQuery(search_text="text", suggester_name="sg")
     assert type(query.request) is AutocompleteRequest
     assert query.request.filter is None