diff --git a/sdk/search/azure-search-documents/README.md b/sdk/search/azure-search-documents/README.md index 1de92c0b959..b464d6e63af 100644 --- a/sdk/search/azure-search-documents/README.md +++ b/sdk/search/azure-search-documents/README.md @@ -40,10 +40,11 @@ The above creates a resource with the "Standard" pricing tier. See [choosing a p In order to interact with the Cognitive Search service you'll need to create an instance of the Search Client class. To make this possible you will need an [api-key of the Cognitive Search service](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys). -The SDK provides two clients. +The SDK provides three clients. 1. SearchClient for all document operations. -2. SearchServiceClient for all CRUD operations on service resources. +2. SearchIndexClient for all CRUD operations on index resources. +3. SearchIndexerClient for all CRUD operations on indexer resources. #### Create a SearchClient @@ -64,18 +65,33 @@ client = SearchClient(endpoint="", credential=credential) ``` -#### Create a SearchServiceClient +#### Create a SearchIndexClient Once you have the values of the Cognitive Search Service [service endpoint](https://docs.microsoft.com/en-us/azure/search/search-create-service-portal#get-a-key-and-url-endpoint) and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Service client: ```python from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchServiceClient +from azure.search.documents.indexes import SearchIndexClient credential = AzureKeyCredential("") -client = SearchServiceClient(endpoint="" +client = SearchIndexClient(endpoint="" + credential=credential) +``` + +#### Create a SearchIndexerClient + +Once you have the values of the Cognitive Search Service [service endpoint](https://docs.microsoft.com/en-us/azure/search/search-create-service-portal#get-a-key-and-url-endpoint) +and [api key](https://docs.microsoft.com/en-us/azure/search/search-security-api-keys) you can create the Search Service client: + +```python +from azure.core.credentials import AzureKeyCredential +from azure.search.documents.indexes import SearchIndexerClient + +credential = AzureKeyCredential("") + +client = SearchIndexerClient(endpoint="" credential=credential) ``` @@ -83,7 +99,7 @@ client = SearchServiceClient(endpoint="" You can use the `SearchClient` you created in the first section above to make a basic search request: ```python -results = client.search(search_text="spa") +results = client.search(query="spa") print("Hotels containing 'spa' in the name (or other fields):") for result in results: @@ -100,7 +116,7 @@ source to extract and load data into an index. There are several types of operations that can be executed against the service: - **Index management operations** Create, delete, update, or configure a search index. ([API Reference](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/azure.search.documents.html#azure.search.documents.SearchIndexesClient), [Service Docs](https://docs.microsoft.com/en-us/rest/api/searchservice/index-operations)) -- **Document operations** Add, update, or delete documents in the index, query the index, or look up specific documents by ID. ([API Reference](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/azure.search.documents.html#azure.search.documents.SearchClient), [Service Docs](https://docs.microsoft.com/en-us/rest/api/searchservice/document-operations)) +- **Document operations** Add, update, or delete documents in the index, query the index, or look up specific documents by ID. ([API Reference](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/azure.search.documents.html#azure.search.documents.SearchClient), [Service Docs](https://docs.microsoft.com/en-us/rest/api/searchservice/document-operations)) - **Datasource operations** Create, delete, update, or configure data sources for Search Indexers ([API Reference](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/azure.search.documents.html#azure.search.documents.SearchDataSourcesClient), [Service Docs](https://docs.microsoft.com/en-us/rest/api/searchservice/indexer-operations)) - **Indexer operations** Automate aspects of an indexing operation by configuring a data source and an indexer that you can schedule or run on demand. This feature is supported for a limited number of data source types. ([API Reference](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/azure.search.documents.html#azure.search.documents.SearchIndexersClient), [Service Docs](https://docs.microsoft.com/en-us/rest/api/searchservice/indexer-operations)) - **Skillset operations** Part of a cognitive search workload, a skillset defines a series of a series of enrichment processing steps. A skillset is consumed by an indexer. ([API Reference](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-search-documents/latest/azure.search.documents.html#azure.search.documents.SearchSkillsetsClient), [Service Docs](https://docs.microsoft.com/en-us/rest/api/searchservice/skillset-operations)) @@ -126,7 +142,7 @@ from azure.core.credentials import AzureKeyCredential from azure.search.documents import SearchClient client = SearchClient("", "", AzureKeyCredential("")) -results = client.search(search_text="spa") +results = client.search(query="spa") print("Hotels containing 'spa' in the name (or other fields):") for result in results: @@ -154,12 +170,10 @@ 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 +from azure.search.documents import SearchClient client = SearchClient("", "", AzureKeyCredential("")) -query = SuggestQuery(search_text="coffee", suggester_name="sg") - -results = client.suggest(query=query) +results = client.suggest(search_text="coffee", suggester_name="sg") print("Search suggestions for 'coffee'") for result in results: @@ -172,25 +186,22 @@ for result in results: ```python from azure.core.credentials import AzureKeyCredential -from azure.search.documents import SearchServiceClient, CorsOptions, Index, ScoringProfile -client = SearchServiceClient("", AzureKeyCredential("")).get_indexes_client() +from azure.search.documents.indexes import SearchIndexClient, CorsOptions, SearchIndex, ScoringProfile +client = SearchIndexClient("", AzureKeyCredential("")) name = "hotels" fields = [ - { - "name": "hotelId", - "type": "Edm.String", - "key": True, - "searchable": False - }, - { - "name": "baseRate", - "type": "Edm.Double" - } -] + SimpleField(name="hotelId", type=SearchFieldDataType.String, key=True), + SimpleField(name="baseRate", type=SearchFieldDataType.Double), + SearchableField(name="description", type=SearchFieldDataType.String), + ComplexField(name="address", fields=[ + SimpleField(name="streetAddress", type=SearchFieldDataType.String), + SimpleField(name="city", type=SearchFieldDataType.String), + ]) + ] cors_options = CorsOptions(allowed_origins=["*"], max_age_in_seconds=60) scoring_profiles = [] -index = Index( +index = SearchIndex( name=name, fields=fields, scoring_profiles=scoring_profiles, @@ -257,7 +268,7 @@ client = SearchClient("", "", 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(search_text="spa", logging_enable=True) +result = client.search(query="spa", logging_enable=True) ``` ## Next steps diff --git a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_models.py b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_models.py index 9df7969fb92..6da11c7146d 100644 --- a/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_models.py +++ b/sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_models.py @@ -87,7 +87,10 @@ def to_analyze_request(self): class CustomAnalyzer(LexicalAnalyzer): - """Allows you to take control over the process of converting text into indexable/searchable tokens. It's a user-defined configuration consisting of a single predefined tokenizer and one or more filters. The tokenizer is responsible for breaking text into tokens, and the filters for modifying tokens emitted by the tokenizer. + """Allows you to take control over the process of converting text into indexable/searchable tokens. + It's a user-defined configuration consisting of a single predefined tokenizer and one or more filters. + The tokenizer is responsible for breaking text into tokens, and the filters for modifying tokens + emitted by the tokenizer. All required parameters must be populated in order to send to Azure.