Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 70 additions & 53 deletions sdk/search/azure-search-documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:

```PowerShell
az search service create --resource-group <your-resource-group-name> --name <your-resource-name> --sku S
az search service create --resource-group <your-resource-group-name> --name <your-resource-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.
Expand Down Expand Up @@ -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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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
Expand Down Expand Up @@ -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
Expand All @@ -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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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("<service endpoint>", "<index_name>", AzureKeyCredential("<api key>"))

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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -200,6 +205,11 @@
"ScoringFunction",
"ScoringProfile",
"SearchClient",
"SearchDataSourcesClient",
"SearchIndexersClient",
"SearchIndexesClient",
"SearchSkillsetsClient",
"SearchSynonymMapsClient",
"SearchItemPaged",
"SearchQuery",
"SearchServiceClient",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
20 changes: 18 additions & 2 deletions sdk/search/azure-search-documents/azure/search/documents/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)