Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 committed Jun 4, 2020
1 parent 0e8db7f commit 2cb3750
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 39 deletions.
6 changes: 3 additions & 3 deletions sdk/search/azure-search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ client = SearchServiceClient(endpoint="<service endpoint>"

You can use the `SearchClient` you created in the first section above to make a basic search request:
```python
results = client.search(query="spa")
results = client.search(search_text="spa")

print("Hotels containing 'spa' in the name (or other fields):")
for result in results:
Expand Down Expand Up @@ -126,7 +126,7 @@ from azure.core.credentials import AzureKeyCredential
from azure.search.documents import SearchClient
client = SearchClient("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

results = client.search(query="spa")
results = client.search(search_text="spa")

print("Hotels containing 'spa' in the name (or other fields):")
for result in results:
Expand Down Expand Up @@ -257,7 +257,7 @@ client = SearchClient("<service endpoint>", "<index_name>", AzureKeyCredential("
Similarly, `logging_enable` can enable detailed logging for a single operation,
even when it isn't enabled for the client:
```python
result = client.search(query="spa", logging_enable=True)
result = client.search(search_text="spa", logging_enable=True)
```

## Next steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,41 @@ def search(self, search_text, **kwargs):
:dedent: 4
:caption: Get search result facets.
"""
query = SearchQuery(search_text=search_text, **kwargs)
include_total_result_count = kwargs.pop("include_total_result_count", None)
facets = kwargs.pop("facets", None)
filter = kwargs.pop("filter", None)
highlight_fields = kwargs.pop("highlight_fields", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
order_by = kwargs.pop("order_by", None)
query_type = kwargs.pop("query_type", None)
scoring_parameters = kwargs.pop("scoring_parameters", None)
scoring_profile = kwargs.pop("scoring_profile", None)
search_fields = kwargs.pop("search_fields", None)
search_mode = kwargs.pop("search_mode", None)
select = kwargs.pop("select", None)
skip = kwargs.pop("skip", None)
top = kwargs.pop("top", None)
query = SearchQuery(
search_text=search_text,
include_total_result_count=include_total_result_count,
facets=facets,
filter=filter,
highlight_fields=highlight_fields,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
order_by=order_by,
query_type=query_type,
scoring_parameters=scoring_parameters,
scoring_profile=scoring_profile,
search_fields=search_fields,
search_mode=search_mode,
select=select,
skip=skip,
top=top
)

kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
return SearchItemPaged(
Expand All @@ -194,7 +228,28 @@ def suggest(self, search_text, suggester_name, **kwargs):
:dedent: 4
:caption: Get search suggestions.
"""
query = SuggestQuery(search_text=search_text, suggester_name=suggester_name, **kwargs)
filter = kwargs.pop("filter", None)
use_fuzzy_matching = kwargs.pop("use_fuzzy_matching", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
order_by = kwargs.pop("order_by", None)
search_fields = kwargs.pop("search_fields", None)
select = kwargs.pop("select", None)
top = kwargs.pop("top", None)
query = SuggestQuery(
search_text=search_text,
suggester_name=suggester_name,
filter=filter,
use_fuzzy_matching=use_fuzzy_matching,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
order_by=order_by,
search_fields=search_fields,
select=select,
top=top
)

kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
response = self._client.documents.suggest_post(
Expand Down Expand Up @@ -222,7 +277,26 @@ def autocomplete(self, search_text, suggester_name, **kwargs):
:dedent: 4
:caption: Get a auto-completions.
"""
query = AutocompleteQuery(search_text=search_text, suggester_name=suggester_name, **kwargs)
autocomplete_mode = kwargs.pop("autocomplete_mode", None)
filter = kwargs.pop("filter", None)
use_fuzzy_matching = kwargs.pop("use_fuzzy_matching", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
search_fields = kwargs.pop("search_fields", None)
top = kwargs.pop("top", None)
query = AutocompleteQuery(
search_text=search_text,
suggester_name=suggester_name,
autocomplete_mode=autocomplete_mode,
filter=filter,
use_fuzzy_matching=use_fuzzy_matching,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
search_fields=search_fields,
top=top
)

kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
response = self._client.documents.autocomplete_post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
# --------------------------------------------------------------------------
from typing import cast, List, TYPE_CHECKING

import six

from azure.core.tracing.decorator_async import distributed_trace_async
from ._paging import AsyncSearchItemPaged, AsyncSearchPageIterator
from .._generated.aio import SearchIndexClient
from .._generated.models import IndexBatch, IndexingResult, SearchRequest
from .._generated.models import IndexBatch, IndexingResult
from .._index_documents_batch import IndexDocumentsBatch
from .._queries import AutocompleteQuery, SearchQuery, SuggestQuery
from ..._headers_mixin import HeadersMixin
Expand Down Expand Up @@ -139,7 +137,41 @@ async def search(self, search_text, **kwargs):
:dedent: 4
:caption: Get search result facets.
"""
query = SearchQuery(search_text=search_text, **kwargs)
include_total_result_count = kwargs.pop("include_total_result_count", None)
facets = kwargs.pop("facets", None)
filter = kwargs.pop("filter", None)
highlight_fields = kwargs.pop("highlight_fields", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
order_by = kwargs.pop("order_by", None)
query_type = kwargs.pop("query_type", None)
scoring_parameters = kwargs.pop("scoring_parameters", None)
scoring_profile = kwargs.pop("scoring_profile", None)
search_fields = kwargs.pop("search_fields", None)
search_mode = kwargs.pop("search_mode", None)
select = kwargs.pop("select", None)
skip = kwargs.pop("skip", None)
top = kwargs.pop("top", None)
query = SearchQuery(
search_text=search_text,
include_total_result_count=include_total_result_count,
facets=facets,
filter=filter,
highlight_fields=highlight_fields,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
order_by=order_by,
query_type=query_type,
scoring_parameters=scoring_parameters,
scoring_profile=scoring_profile,
search_fields=search_fields,
search_mode=search_mode,
select=select,
skip=skip,
top=top
)

kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
return AsyncSearchItemPaged(
Expand All @@ -148,7 +180,7 @@ async def search(self, search_text, **kwargs):

@distributed_trace_async
async def suggest(self, search_text, suggester_name, **kwargs):
# type: (Union[str, SuggestQuery], **Any) -> List[dict]
# type: (str, str, **Any) -> List[dict]
"""Get search suggestion results from the Azure search index.
:param str search_text: Required. The search text to use to suggest documents. Must be at least 1
Expand All @@ -166,7 +198,28 @@ async def suggest(self, search_text, suggester_name, **kwargs):
:dedent: 4
:caption: Get search suggestions.
"""
query = SuggestQuery(search_text=search_text, suggester_name=suggester_name, **kwargs)
filter = kwargs.pop("filter", None)
use_fuzzy_matching = kwargs.pop("use_fuzzy_matching", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
order_by = kwargs.pop("order_by", None)
search_fields = kwargs.pop("search_fields", None)
select = kwargs.pop("select", None)
top = kwargs.pop("top", None)
query = SuggestQuery(
search_text=search_text,
suggester_name=suggester_name,
filter=filter,
use_fuzzy_matching=use_fuzzy_matching,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
order_by=order_by,
search_fields=search_fields,
select=select,
top=top
)

kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
response = await self._client.documents.suggest_post(
Expand Down Expand Up @@ -194,7 +247,26 @@ async def autocomplete(self, search_text, suggester_name, **kwargs):
:dedent: 4
:caption: Get a auto-completions.
"""
query = AutocompleteQuery(search_text=search_text, suggester_name=suggester_name, **kwargs)
autocomplete_mode = kwargs.pop("autocomplete_mode", None)
filter = kwargs.pop("filter", None)
use_fuzzy_matching = kwargs.pop("use_fuzzy_matching", None)
highlight_post_tag = kwargs.pop("highlight_post_tag", None)
highlight_pre_tag = kwargs.pop("highlight_pre_tag", None)
minimum_coverage = kwargs.pop("minimum_coverage", None)
search_fields = kwargs.pop("search_fields", None)
top = kwargs.pop("top", None)
query = AutocompleteQuery(
search_text=search_text,
suggester_name=suggester_name,
autocomplete_mode=autocomplete_mode,
filter=filter,
use_fuzzy_matching=use_fuzzy_matching,
highlight_post_tag=highlight_post_tag,
highlight_pre_tag=highlight_pre_tag,
minimum_coverage=minimum_coverage,
search_fields=search_fields,
top=top
)

kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
response = await self._client.documents.autocomplete_post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ async def filter_query():

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

select = ("HotelName", "Rating")
async with search_client:
results = await search_client.search(
search_text="WiFi",
filter="Address/StateProvince eq 'FL' and Address/Country eq 'USA'",
select=",".join("HotelName", "Rating"),
select=",".join(select),
order_by="Rating desc"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def simple_text_query():
search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(key))

async with search_client:
results = await search_client.search(query="spa")
results = await search_client.search(search_text="spa")

print("Hotels containing 'spa' in the name (or other fields):")
async for result in results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ def filter_query():

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

select = ("HotelName", "Rating")
results = search_client.search(
search_text="WiFi",
filter="Address/StateProvince eq 'FL' and Address/Country eq 'USA'",
select=",".join("HotelName", "Rating"),
select=",".join(select),
order_by="Rating desc"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ async def test_get_search_simple(self, api_key, endpoint, index_name, **kwargs):
)
async with client:
results = []
async for x in await client.search(query="hotel"):
async for x in await client.search(search_text="hotel"):
results.append(x)
assert len(results) == 7

results = []
async for x in await client.search(query="motel"):
async for x in await client.search(search_text="motel"):
results.append(x)
assert len(results) == 2

Expand All @@ -104,10 +104,11 @@ async def test_get_search_filter(self, api_key, endpoint, index_name, **kwargs):

async with client:
results = []
select = ("hotelName", "category", "description")
async for x in await client.search(
search_text="WiFi",
filter="category eq 'Budget'",
select=",".join("hotelName", "category", "description"),
select=",".join(select),
order_by="hotelName desc"
):
results.append(x)
Expand Down Expand Up @@ -162,9 +163,10 @@ async def test_get_search_facets_none(
)

async with client:
select = ("hotelName", "category", "description")
results = await client.search(
search_text="WiFi",
select=",".join("hotelName", "category", "description")
select=",".join(select)
)
assert await results.get_facets() is None

Expand All @@ -178,10 +180,11 @@ async def test_get_search_facets_result(
)

async with client:
select = ("hotelName", "category", "description")
results = await client.search(
search_text="WiFi",
facets=["category"],
select=",".join("hotelName", "category", "description")
select=",".join(select)
)
assert await results.get_facets() == {
"category": [
Expand Down
14 changes: 9 additions & 5 deletions sdk/search/azure-search-documents/tests/test_index_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def test_get_search_simple(self, api_key, endpoint, index_name, **kwargs):
client = SearchClient(
endpoint, index_name, AzureKeyCredential(api_key)
)
results = list(client.search(query="hotel"))
results = list(client.search(search_text="hotel"))
assert len(results) == 7

results = list(client.search(query="motel"))
results = list(client.search(search_text="motel"))
assert len(results) == 2

@ResourceGroupPreparer(random_name_enabled=True)
Expand All @@ -74,10 +74,11 @@ def test_get_search_filter(self, api_key, endpoint, index_name, **kwargs):
endpoint, index_name, AzureKeyCredential(api_key)
)

select = ("hotelName", "category", "description")
results = list(client.search(
search_text="WiFi",
filter="category eq 'Budget'",
select=",".join("hotelName", "category", "description"),
select=",".join(select),
order_by="hotelName desc"
))
assert [x["hotelName"] for x in results] == sorted(
Expand All @@ -104,6 +105,7 @@ def test_get_search_counts(self, api_key, endpoint, index_name, **kwargs):
assert results.get_count() is None

results = client.search(search_text="hotel", include_total_result_count=True)
temp = list(results)
assert results.get_count() == 7

@ResourceGroupPreparer(random_name_enabled=True)
Expand All @@ -128,7 +130,8 @@ def test_get_search_facets_none(self, api_key, endpoint, index_name, **kwargs):
endpoint, index_name, AzureKeyCredential(api_key)
)

results = client.search(search_text="WiFi", select=",".join("hotelName", "category", "description"))
select = ("hotelName", "category", "description")
results = client.search(search_text="WiFi", select=",".join(select))
assert results.get_facets() is None

@ResourceGroupPreparer(random_name_enabled=True)
Expand All @@ -138,9 +141,10 @@ def test_get_search_facets_result(self, api_key, endpoint, index_name, **kwargs)
endpoint, index_name, AzureKeyCredential(api_key)
)

select = ("hotelName", "category", "description")
results = client.search(search_text="WiFi",
facets=["category"],
select=",".join("hotelName", "category", "description")
select=",".join(select)
)
assert results.get_facets() == {
"category": [
Expand Down
Loading

0 comments on commit 2cb3750

Please sign in to comment.