Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
 async def test_autocomplete(self, api_key, endpoint, index_name, **kwargs):
     client = SearchIndexClient(
         endpoint, index_name, SearchApiKeyCredential(api_key)
     )
     async with client:
         query = AutocompleteQuery(search_text="mot", suggester_name="sg")
         results = await client.autocomplete(query=query)
         assert results == [{'text': 'motel', 'query_plus_text': 'motel'}]
Ejemplo n.º 4
0
    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"
Ejemplo n.º 5
0
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"]))
Ejemplo n.º 6
0
 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}
Ejemplo n.º 7
0
 def test_init(self):
     query = AutocompleteQuery(search_text="text", suggester_name="sg")
     assert type(query.request) is AutocompleteRequest
     assert query.request.filter is None
Ejemplo n.º 8
0
 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"}]