diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index e4440c9a0f74..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://aka.ms/azsdk-python-search-ref-docs) | +[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) @@ -25,12 +25,12 @@ 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: ```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. @@ -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 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", +)