Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 committed Jun 5, 2020
1 parent 13d56f4 commit a544404
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
65 changes: 38 additions & 27 deletions sdk/search/azure-search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -64,26 +65,41 @@ client = SearchClient(endpoint="<service 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("<api key>")

client = SearchServiceClient(endpoint="<service endpoint>"
client = SearchIndexClient(endpoint="<service 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("<api key>")

client = SearchIndexerClient(endpoint="<service endpoint>"
credential=credential)
```

### Send your first search request

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:
Expand All @@ -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))
Expand All @@ -126,7 +142,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(search_text="spa")
results = client.search(query="spa")

print("Hotels containing 'spa' in the name (or other fields):")
for result in results:
Expand Down Expand Up @@ -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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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:
Expand All @@ -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("<service endpoint>", AzureKeyCredential("<api key>")).get_indexes_client()
from azure.search.documents.indexes import SearchIndexClient, CorsOptions, SearchIndex, ScoringProfile
client = SearchIndexClient("<service endpoint>", AzureKeyCredential("<api key>"))
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,
Expand Down Expand Up @@ -257,7 +268,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(search_text="spa", logging_enable=True)
result = client.search(query="spa", logging_enable=True)
```

## Next steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a544404

Please sign in to comment.