From df3077ecc16941caba764e6baebfc524f04a759b Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 12 May 2020 12:45:38 -0700 Subject: [PATCH 1/6] fix top level API ref docs link --- sdk/search/azure-search-documents/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index e4440c9a0f74..66101b77f9cf 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -4,7 +4,7 @@ Azure Cognitive Search is a fully managed cloud search service that provides a r [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/search/azure-search-documents) | [Package (PyPI)](https://pypi.org/project/azure-search-documents/) | -[API reference documentation](https://aka.ms/azsdk-python-search-ref-docs) | +[API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/1.0.0b3/index.html) | [Product documentation](https://docs.microsoft.com/en-us/azure/search/search-what-is-azure-search) | [Samples](samples) From 78683d1dfabacac8f0069fab86129a3e1ee2dde9 Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 12 May 2020 12:47:27 -0700 Subject: [PATCH 2/6] fix az create sample --- sdk/search/azure-search-documents/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index 66101b77f9cf..0d0f597892a8 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -30,7 +30,7 @@ If you need to create the resource, you can use the [Azure Portal][azure_portal] If you use the Azure CLI, replace `` and `` with your own unique names: ```PowerShell -az search service create --resource-group --name --sku S +az search service create --resource-group --name --sku Standard ``` The above creates a resource with the "Standard" pricing tier. See [choosing a pricing tier](https://docs.microsoft.com/en-us/azure/search/search-sku-tier) for more information. From 41679c434f1bbdf80b87afc5aa9d2a286698c96b Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 12 May 2020 12:50:06 -0700 Subject: [PATCH 3/6] improve 'create a service' links --- sdk/search/azure-search-documents/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index 0d0f597892a8..c61a3f400489 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -25,7 +25,7 @@ pip install azure-search-documents --pre * You must have an [Azure subscription][azure_sub] and an existing [Azure Cognitive Search service][search_resource] to use this package. -If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli]. +If you need to create the resource, you can use the [Azure portal][create_search_service_docs], [Azure PowerShell][create_search_service_ps], or the [Azure CLI][create_search_service_cli]. If you use the Azure CLI, replace `` and `` with your own unique names: From 3077db290c0eec7e5eddc2816c902b92b0224e2f Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 12 May 2020 13:01:22 -0700 Subject: [PATCH 4/6] snippet index --- sdk/search/azure-search-documents/README.md | 117 +++++++++++--------- 1 file changed, 67 insertions(+), 50 deletions(-) diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index c61a3f400489..0b3b3811832f 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -107,8 +107,68 @@ There are several types of operations that can be executed against the service: ## Examples +The following sections contain snippets for some common operations: + +* [Perform a simple text search](#perform-a-simple-text-search-on-documents) +* [Retrieve a specific document](#retrieve-a-specific-document-from-an-index) +* [Get search suggestions](#get-search-suggestions) +* [Create an index](#create-an-index) +* [Upload documents to an index](#upload-documents-to-an-index) + +More examples, covering topics such as indexers, skillets, and synonym maps can be found in the [Samples directory](samples). + +### Perform a simple text search on documents +Search the entire index or documents matching a simple search text, e.g. find +hotels with the text "spa": +```python +from azure.core.credentials import AzureKeyCredential +from azure.search.documents import SearchClient +client = SearchClient("", "", AzureKeyCredential("")) + +results = client.search(query="spa") + +print("Hotels containing 'spa' in the name (or other fields):") +for result in results: + print(" Name: {} (rating {})".format(result["HotelName"], result["Rating"])) +``` + +### Retrieve a specific document from an index +Get a specific document from the index, e.f. obtain the document for hotel "23": +```python +from azure.core.credentials import AzureKeyCredential +from azure.search.documents import SearchClient +client = SearchClient("", "", AzureKeyCredential("")) + +result = client.get_document(key="23") + +print("Details for hotel '23' are:") +print(" Name: {}".format(result["HotelName"])) +print(" Rating: {}".format(result["Rating"])) +print(" Category: {}".format(result["Category"])) +``` + +### Get search suggestions + +Get search suggestions for related terms, e.g. find search suggestions for +the term "coffee": +```python +from azure.core.credentials import AzureKeyCredential +from azure.search.documents import SearchClient, SuggestQuery +client = SearchClient("", "", AzureKeyCredential("")) + +query = SuggestQuery(search_text="coffee", suggester_name="sg") + +results = client.suggest(query=query) + +print("Search suggestions for 'coffee'") +for result in results: + hotel = client.get_document(key=result["HotelId"]) + print(" Text: {} for Hotel: {}".format(repr(result["text"]), hotel["HotelName"])) +``` + + ### Create an index -Create a new index + ```python from azure.core.credentials import AzureKeyCredential from azure.search.documents import SearchServiceClient, CorsOptions, Index, ScoringProfile @@ -139,7 +199,9 @@ result = client.create_index(index) ``` ### Upload documents to an index + Add documents (or update existing ones), e.g add a new document for a new hotel: + ```python from azure.core.credentials import AzureKeyCredential from azure.search.documents import SearchClient @@ -158,55 +220,6 @@ result = client.upload_documents(documents=[DOCUMENT]) print("Upload of new document succeeded: {}".format(result[0].succeeded)) ``` -### Retrieve a specific document from an index -Get a specific document from the index, e.f. obtain the document for hotel "23": -```python -from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchClient -client = SearchClient("", "", AzureKeyCredential("")) - -result = client.get_document(key="23") - -print("Details for hotel '23' are:") -print(" Name: {}".format(result["HotelName"])) -print(" Rating: {}".format(result["Rating"])) -print(" Category: {}".format(result["Category"])) -``` - -### Perform a simple text search on documents -Search the entire index or documents matching a simple search text, e.g. find -hotels with the text "spa": -```python -from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchClient -client = SearchClient("", "", AzureKeyCredential("")) - -results = client.search(query="spa") - -print("Hotels containing 'spa' in the name (or other fields):") -for result in results: - print(" Name: {} (rating {})".format(result["HotelName"], result["Rating"])) -``` - -### Get search suggestions - -Get search suggestions for related terms, e.g. find search suggestions for -the term "coffee": -```python -from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchClient, SuggestQuery -client = SearchClient("", "", AzureKeyCredential("")) - -query = SuggestQuery(search_text="coffee", suggester_name="sg") - -results = client.suggest(query=query) - -print("Search suggestions for 'coffee'") -for result in results: - hotel = client.get_document(key=result["HotelId"]) - print(" Text: {} for Hotel: {}".format(repr(result["text"]), hotel["HotelName"])) -``` - ## Troubleshooting ### General @@ -274,6 +287,10 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [search_resource]: https://docs.microsoft.com/en-us/azure/search/search-create-service-portal [azure_portal]: https://portal.azure.com +[create_search_service_docs]: https://docs.microsoft.com/azure/search/search-create-service-portal +[create_search_service_ps]: https://docs.microsoft.com/azure/search/search-manage-powershell#create-or-delete-a-service +[create_search_service_cli]: https://docs.microsoft.com/cli/azure/search/service?view=azure-cli-latest#az-search-service-create + [python_logging]: https://docs.python.org/3.5/library/logging.html [cla]: https://cla.microsoft.com From cd71c0b55c0cf89d886d68b7ff3fc98cb4a6dfca Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 12 May 2020 13:02:16 -0700 Subject: [PATCH 5/6] use non-versioned link for ref docs --- sdk/search/azure-search-documents/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index 0b3b3811832f..ffbb1bff4221 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -4,7 +4,7 @@ Azure Cognitive Search is a fully managed cloud search service that provides a r [Source code](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/search/azure-search-documents) | [Package (PyPI)](https://pypi.org/project/azure-search-documents/) | -[API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/1.0.0b3/index.html) | +[API reference documentation](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/index.html) | [Product documentation](https://docs.microsoft.com/en-us/azure/search/search-what-is-azure-search) | [Samples](samples) From 00d54c1744cc9e42bb1767626325b75270e91875 Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 12 May 2020 13:30:25 -0700 Subject: [PATCH 6/6] add missing subclients from top level --- .../azure/search/documents/__init__.py | 10 ++++++++++ .../search/documents/_service/aio/__init__.py | 15 +++++++++++++- .../azure/search/documents/aio.py | 20 +++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/sdk/search/azure-search-documents/azure/search/documents/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/__init__.py index 02bd8a2266d4..3abdc091320c 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/__init__.py @@ -129,6 +129,11 @@ WordDelimiterTokenFilter, ) from ._service._models import PatternAnalyzer, PatternTokenizer +from ._service._datasources_client import SearchDataSourcesClient +from ._service._indexers_client import SearchIndexersClient +from ._service._indexes_client import SearchIndexesClient +from ._service._skillsets_client import SearchSkillsetsClient +from ._service._synonym_maps_client import SearchSynonymMapsClient from ._version import VERSION __version__ = VERSION @@ -200,6 +205,11 @@ "ScoringFunction", "ScoringProfile", "SearchClient", + "SearchDataSourcesClient", + "SearchIndexersClient", + "SearchIndexesClient", + "SearchSkillsetsClient", + "SearchSynonymMapsClient", "SearchItemPaged", "SearchQuery", "SearchServiceClient", diff --git a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py index 0d3142f14092..28c06ccbb2bb 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py +++ b/sdk/search/azure-search-documents/azure/search/documents/_service/aio/__init__.py @@ -4,4 +4,17 @@ # ------------------------------------ from ._search_service_client_async import SearchServiceClient -__all__ = "SearchServiceClient" +from ._datasources_client import SearchDataSourcesClient +from ._indexers_client import SearchIndexersClient +from ._indexes_client import SearchIndexesClient +from ._skillsets_client import SearchSkillsetsClient +from ._synonym_maps_client import SearchSynonymMapsClient + +__all__ = ( + "SearchServiceClient", + "SearchDataSourcesClient", + "SearchIndexersClient", + "SearchIndexesClient", + "SearchSkillsetsClient", + "SearchSynonymMapsClient", +) diff --git a/sdk/search/azure-search-documents/azure/search/documents/aio.py b/sdk/search/azure-search-documents/azure/search/documents/aio.py index 626fecfd63b9..565c6e7cf240 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/aio.py +++ b/sdk/search/azure-search-documents/azure/search/documents/aio.py @@ -25,6 +25,22 @@ # -------------------------------------------------------------------------- from ._index.aio import AsyncSearchItemPaged, SearchClient -from ._service.aio import SearchServiceClient +from ._service.aio import ( + SearchServiceClient, + SearchDataSourcesClient, + SearchIndexersClient, + SearchIndexesClient, + SearchSkillsetsClient, + SearchSynonymMapsClient, +) -__all__ = ("AsyncSearchItemPaged", "SearchClient", "SearchServiceClient") +__all__ = ( + "AsyncSearchItemPaged", + "SearchClient", + "SearchServiceClient", + "SearchDataSourcesClient", + "SearchIndexersClient", + "SearchIndexesClient", + "SearchSkillsetsClient", + "SearchSynonymMapsClient", +)