Skip to content

Commit 3a05ac7

Browse files
authored
update samples & rename datasource methods (Azure#11683)
* update samples * rename datasource methods
1 parent 4a56209 commit 3a05ac7

27 files changed

+377
-355
lines changed

sdk/search/azure-search-documents/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Renamed `edm` to `SearchFieldDataType` #11511
1010
- Now Search Synonym Map creation/update returns a model #11514
1111
- Renaming #11565
12+
1213
SearchIndexerDataSource -> SearchIndexerDataSourceConnection
1314
SearchField.SynonymMaps -> SearchField.SynonymMapNames
1415
SearchField.Analyzer -> SearchField.AnalyzerName
@@ -21,7 +22,7 @@
2122
Similarity -> SimilarityAlgorithm
2223
Suggester -> SearchSuggester
2324
PathHierarchyTokenizerV2 -> PathHierarchyTokenizer
24-
25+
- Renamed DataSource methods to DataSourceConnection #11693
2526

2627

2728
## 1.0.0b3 (2020-05-04)

sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/_search_indexer_client.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -255,50 +255,50 @@ def get_indexer_status(self, name, **kwargs):
255255
return self._client.indexers.get_status(name, **kwargs)
256256

257257
@distributed_trace
258-
def create_datasource(self, data_source, **kwargs):
258+
def create_data_source_connection(self, data_source_connection, **kwargs):
259259
# type: (SearchIndexerDataSourceConnection, **Any) -> SearchIndexerDataSourceConnection
260-
"""Creates a new datasource.
260+
"""Creates a new data source connection.
261261
262-
:param data_source: The definition of the datasource to create.
263-
:type data_source: ~search.models.SearchIndexerDataSourceConnection
262+
:param data_source_connection: The definition of the data source connection to create.
263+
:type data_source_connection: ~search.models.SearchIndexerDataSourceConnection
264264
:return: The created SearchIndexerDataSourceConnection
265265
:rtype: ~search.models.SearchIndexerDataSourceConnection
266266
267267
.. admonition:: Example:
268268
269269
.. literalinclude:: ../samples/sample_data_source_operations.py
270-
:start-after: [START create_data_source]
271-
:end-before: [END create_data_source]
270+
:start-after: [START create_data_source_connection]
271+
:end-before: [END create_data_source_connection]
272272
:language: python
273273
:dedent: 4
274274
:caption: Create a Data Source
275275
"""
276276
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
277-
packed_data_source = pack_search_indexer_data_source(data_source)
277+
packed_data_source = pack_search_indexer_data_source(data_source_connection)
278278
result = self._client.data_sources.create(packed_data_source, **kwargs)
279279
return unpack_search_indexer_data_source(result)
280280

281281
@distributed_trace
282-
def create_or_update_datasource(self, data_source, name=None, **kwargs):
282+
def create_or_update_data_source_connection(self, data_source_connection, name=None, **kwargs):
283283
# type: (SearchIndexerDataSourceConnection, Optional[str], **Any) -> SearchIndexerDataSourceConnection
284-
"""Creates a new datasource or updates a datasource if it already exists.
285-
:param name: The name of the datasource to create or update.
284+
"""Creates a new data source connection or updates a data source connection if it already exists.
285+
:param name: The name of the data source connection to create or update.
286286
:type name: str
287-
:param data_source: The definition of the datasource to create or update.
288-
:type data_source: ~search.models.SearchIndexerDataSourceConnection
287+
:param data_source_connection: The definition of the data source connection to create or update.
288+
:type data_source_connection: ~search.models.SearchIndexerDataSourceConnection
289289
:keyword match_condition: The match condition to use upon the etag
290290
:type match_condition: ~azure.core.MatchConditions
291291
:return: The created SearchIndexerDataSourceConnection
292292
:rtype: ~search.models.SearchIndexerDataSourceConnection
293293
"""
294294
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
295295
error_map, access_condition = get_access_conditions(
296-
data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally)
296+
data_source_connection, kwargs.pop("match_condition", MatchConditions.Unconditionally)
297297
)
298298
kwargs.update(access_condition)
299299
if not name:
300-
name = data_source.name
301-
packed_data_source = pack_search_indexer_data_source(data_source)
300+
name = data_source_connection.name
301+
packed_data_source = pack_search_indexer_data_source(data_source_connection)
302302
result = self._client.data_sources.create_or_update(
303303
data_source_name=name,
304304
data_source=packed_data_source,
@@ -308,20 +308,20 @@ def create_or_update_datasource(self, data_source, name=None, **kwargs):
308308
return unpack_search_indexer_data_source(result)
309309

310310
@distributed_trace
311-
def get_datasource(self, name, **kwargs):
311+
def get_data_source_connection(self, name, **kwargs):
312312
# type: (str, **Any) -> SearchIndexerDataSourceConnection
313-
"""Retrieves a datasource definition.
313+
"""Retrieves a data source connection definition.
314314
315-
:param name: The name of the datasource to retrieve.
315+
:param name: The name of the data source connection to retrieve.
316316
:type name: str
317317
:return: The SearchIndexerDataSourceConnection that is fetched.
318318
:rtype: ~search.models.SearchIndexerDataSourceConnection
319319
320320
.. admonition:: Example:
321321
322322
.. literalinclude:: ../samples/sample_data_source_operations.py
323-
:start-after: [START get_data_source]
324-
:end-before: [END get_data_source]
323+
:start-after: [START get_data_source_connection]
324+
:end-before: [END get_data_source_connection]
325325
:language: python
326326
:dedent: 4
327327
:caption: Retrieve a SearchIndexerDataSourceConnection
@@ -331,18 +331,18 @@ def get_datasource(self, name, **kwargs):
331331
return unpack_search_indexer_data_source(result)
332332

333333
@distributed_trace
334-
def get_datasources(self, **kwargs):
334+
def get_data_source_connections(self, **kwargs):
335335
# type: (**Any) -> Sequence[SearchIndexerDataSourceConnection]
336-
"""Lists all datasources available for a search service.
336+
"""Lists all data source connections available for a search service.
337337
338-
:return: List of all the data sources.
338+
:return: List of all the data source connections.
339339
:rtype: `list[~search.models.SearchIndexerDataSourceConnection]`
340340
341341
.. admonition:: Example:
342342
343343
.. literalinclude:: ../samples/sample_data_source_operations.py
344-
:start-after: [START list_data_source]
345-
:end-before: [END list_data_source]
344+
:start-after: [START list_data_source_connection]
345+
:end-before: [END list_data_source_connection]
346346
:language: python
347347
:dedent: 4
348348
:caption: List all the SearchIndexerDataSourceConnections
@@ -352,14 +352,14 @@ def get_datasources(self, **kwargs):
352352
return [unpack_search_indexer_data_source(x) for x in result.data_sources]
353353

354354
@distributed_trace
355-
def delete_datasource(self, data_source, **kwargs):
355+
def delete_data_source_connection(self, data_source_connection, **kwargs):
356356
# type: (Union[str, SearchIndexerDataSourceConnection], **Any) -> None
357-
"""Deletes a datasource. To use access conditions, the Datasource model must be
358-
provided instead of the name. It is enough to provide the name of the datasource
357+
"""Deletes a data source connection. To use access conditions, the SearchIndexerDataSourceConnection
358+
model must be provided instead of the name. It is enough to provide the name of the data source connection
359359
to delete unconditionally
360360
361-
:param data_source: The datasource to delete.
362-
:type data_source: str or ~search.models.SearchIndexerDataSourceConnection
361+
:param data_source_connection: The data source connection to delete.
362+
:type data_source_connection: str or ~search.models.SearchIndexerDataSourceConnection
363363
:keyword match_condition: The match condition to use upon the etag
364364
:type match_condition: ~azure.core.MatchConditions
365365
:return: None
@@ -368,21 +368,21 @@ def delete_datasource(self, data_source, **kwargs):
368368
.. admonition:: Example:
369369
370370
.. literalinclude:: ../samples/sample_data_source_operations.py
371-
:start-after: [START delete_data_source]
372-
:end-before: [END delete_data_source]
371+
:start-after: [START delete_data_source_connection]
372+
:end-before: [END delete_data_source_connection]
373373
:language: python
374374
:dedent: 4
375375
:caption: Delete a SearchIndexerDataSourceConnection
376376
"""
377377
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
378378
error_map, access_condition = get_access_conditions(
379-
data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally)
379+
data_source_connection, kwargs.pop("match_condition", MatchConditions.Unconditionally)
380380
)
381381
kwargs.update(access_condition)
382382
try:
383-
name = data_source.name
383+
name = data_source_connection.name
384384
except AttributeError:
385-
name = data_source
385+
name = data_source_connection
386386
self._client.data_sources.delete(
387387
data_source_name=name, error_map=error_map, **kwargs
388388
)

sdk/search/azure-search-documents/azure/search/documents/indexes/_internal/aio/_search_indexer_client.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -255,49 +255,49 @@ async def get_indexer_status(self, name, **kwargs):
255255
return await self._client.indexers.get_status(name, **kwargs)
256256

257257
@distributed_trace_async
258-
async def create_datasource(self, data_source, **kwargs):
258+
async def create_data_source_connection(self, data_source_connection, **kwargs):
259259
# type: (SearchIndexerDataSourceConnection, **Any) -> SearchIndexerDataSourceConnection
260-
"""Creates a new datasource.
261-
:param data_source: The definition of the datasource to create.
262-
:type data_source: ~search.models.SearchIndexerDataSourceConnection
260+
"""Creates a new data source connection.
261+
:param data_source_connection: The definition of the data source connection to create.
262+
:type data_source_connection: ~search.models.SearchIndexerDataSourceConnection
263263
:return: The created SearchIndexerDataSourceConnection
264264
:rtype: ~search.models.SearchIndexerDataSourceConnection
265265
266266
.. admonition:: Example:
267267
268268
.. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py
269-
:start-after: [START create_data_source_async]
270-
:end-before: [END create_data_source_async]
269+
:start-after: [START create_data_source_connection_async]
270+
:end-before: [END create_data_source_connection_async]
271271
:language: python
272272
:dedent: 4
273273
:caption: Create a SearchIndexerDataSourceConnection
274274
"""
275275
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
276-
packed_data_source = pack_search_indexer_data_source(data_source)
276+
packed_data_source = pack_search_indexer_data_source(data_source_connection)
277277
result = await self._client.data_sources.create(packed_data_source, **kwargs)
278278
return unpack_search_indexer_data_source(result)
279279

280280
@distributed_trace_async
281-
async def create_or_update_datasource(self, data_source, name=None, **kwargs):
281+
async def create_or_update_data_source_connection(self, data_source_connection, name=None, **kwargs):
282282
# type: (SearchIndexerDataSourceConnection, Optional[str], **Any) -> SearchIndexerDataSourceConnection
283-
"""Creates a new datasource or updates a datasource if it already exists.
284-
:param name: The name of the datasource to create or update.
283+
"""Creates a new data source connection or updates a data source connection if it already exists.
284+
:param name: The name of the data source connection to create or update.
285285
:type name: str
286-
:param data_source: The definition of the datasource to create or update.
287-
:type data_source: ~search.models.SearchIndexerDataSourceConnection
286+
:param data_source_connection: The definition of the data source connection to create or update.
287+
:type data_source_connection: ~search.models.SearchIndexerDataSourceConnection
288288
:keyword match_condition: The match condition to use upon the etag
289289
:type match_condition: ~azure.core.MatchConditions
290290
:return: The created SearchIndexerDataSourceConnection
291291
:rtype: ~search.models.SearchIndexerDataSourceConnection
292292
"""
293293
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
294294
error_map, access_condition = get_access_conditions(
295-
data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally)
295+
data_source_connection, kwargs.pop("match_condition", MatchConditions.Unconditionally)
296296
)
297297
kwargs.update(access_condition)
298298
if not name:
299-
name = data_source.name
300-
packed_data_source = pack_search_indexer_data_source(data_source)
299+
name = data_source_connection.name
300+
packed_data_source = pack_search_indexer_data_source(data_source_connection)
301301
result = await self._client.data_sources.create_or_update(
302302
data_source_name=name,
303303
data_source=packed_data_source,
@@ -307,14 +307,14 @@ async def create_or_update_datasource(self, data_source, name=None, **kwargs):
307307
return unpack_search_indexer_data_source(result)
308308

309309
@distributed_trace_async
310-
async def delete_datasource(self, data_source, **kwargs):
310+
async def delete_data_source_connection(self, data_source_connection, **kwargs):
311311
# type: (Union[str, SearchIndexerDataSourceConnection], **Any) -> None
312-
"""Deletes a datasource. To use access conditions, the Datasource model must be
313-
provided instead of the name. It is enough to provide the name of the datasource
314-
to delete unconditionally
312+
"""Deletes a data source connection. To use access conditions, the
313+
SearchIndexerDataSourceConnection model must be provided instead of the name.
314+
It is enough to provide the name of the data source connection to delete unconditionally
315315
316-
:param data_source: The datasource to delete.
317-
:type data_source: str or ~search.models.SearchIndexerDataSourceConnection
316+
:param data_source_connection: The data source connection to delete.
317+
:type data_source_connection: str or ~search.models.SearchIndexerDataSourceConnection
318318
:keyword match_condition: The match condition to use upon the etag
319319
:type match_condition: ~azure.core.MatchConditions
320320
:return: None
@@ -331,30 +331,30 @@ async def delete_datasource(self, data_source, **kwargs):
331331
"""
332332
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
333333
error_map, access_condition = get_access_conditions(
334-
data_source, kwargs.pop("match_condition", MatchConditions.Unconditionally)
334+
data_source_connection, kwargs.pop("match_condition", MatchConditions.Unconditionally)
335335
)
336336
kwargs.update(access_condition)
337337
try:
338-
name = data_source.name
338+
name = data_source_connection.name
339339
except AttributeError:
340-
name = data_source
340+
name = data_source_connection
341341
await self._client.data_sources.delete(
342342
data_source_name=name, error_map=error_map, **kwargs
343343
)
344344

345345
@distributed_trace_async
346-
async def get_datasource(self, name, **kwargs):
346+
async def get_data_source_connection(self, name, **kwargs):
347347
# type: (str, **Any) -> SearchIndexerDataSourceConnection
348-
"""Retrieves a datasource definition.
348+
"""Retrieves a data source connection definition.
349349
350-
:param name: The name of the datasource to retrieve.
350+
:param name: The name of the data source connection to retrieve.
351351
:type name: str
352352
:return: The SearchIndexerDataSourceConnection that is fetched.
353353
:rtype: ~search.models.SearchIndexerDataSourceConnection
354354
355355
.. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py
356-
:start-after: [START get_data_source_async]
357-
:end-before: [END get_data_source_async]
356+
:start-after: [START get_data_source_connection_async]
357+
:end-before: [END get_data_source_connection_async]
358358
:language: python
359359
:dedent: 4
360360
:caption: Retrieve a SearchIndexerDataSourceConnection
@@ -364,18 +364,18 @@ async def get_datasource(self, name, **kwargs):
364364
return unpack_search_indexer_data_source(result)
365365

366366
@distributed_trace_async
367-
async def get_datasources(self, **kwargs):
367+
async def get_data_source_connections(self, **kwargs):
368368
# type: (**Any) -> Sequence[SearchIndexerDataSourceConnection]
369-
"""Lists all datasources available for a search service.
369+
"""Lists all data source connections available for a search service.
370370
371-
:return: List of all the data sources.
371+
:return: List of all the data source connections.
372372
:rtype: `list[~search.models.SearchIndexerDataSourceConnection]`
373373
374374
.. admonition:: Example:
375375
376376
.. literalinclude:: ../samples/async_samples/sample_data_source_operations_async.py
377-
:start-after: [START list_data_source_async]
378-
:end-before: [END list_data_source_async]
377+
:start-after: [START list_data_source_connection_async]
378+
:end-before: [END list_data_source_connection_async]
379379
:language: python
380380
:dedent: 4
381381
:caption: List all SearchIndexerDataSourceConnections

sdk/search/azure-search-documents/samples/async_samples/sample_analyze_text_async.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
async def simple_analyze_text():
3030
# [START simple_analyze_text_async]
3131
from azure.core.credentials import AzureKeyCredential
32-
from azure.search.documents.aio import SearchServiceClient
33-
from azure.search.documents import AnalyzeRequest
32+
from azure.search.documents.indexes.aio import SearchIndexClient
33+
from azure.search.documents.indexes.models import AnalyzeRequest
3434

35-
service_client = SearchServiceClient(service_endpoint, AzureKeyCredential(key))
36-
client = service_client.get_indexes_client()
35+
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
3736

3837
analyze_request = AnalyzeRequest(text="One's <two/>", analyzer="standard.lucene")
3938

40-
async with service_client:
39+
async with client:
4140
result = await client.analyze_text(index_name, analyze_request)
4241
print(result.as_dict())
4342
# [END simple_analyze_text_async]

sdk/search/azure-search-documents/samples/async_samples/sample_authentication_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ async def authentication_with_api_key_credential_async():
4242
async def authentication_service_client_with_api_key_credential_async():
4343
# [START create_search_service_with_key_async]
4444
from azure.core.credentials import AzureKeyCredential
45-
from azure.search.documents.aio import SearchServiceClient
45+
from azure.search.documents.indexes.aio import SearchIndexClient
4646
service_endpoint = os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT")
4747
key = os.getenv("AZURE_SEARCH_API_KEY")
4848

49-
client = SearchServiceClient(service_endpoint, AzureKeyCredential(key))
49+
client = SearchIndexClient(service_endpoint, AzureKeyCredential(key))
5050
# [END create_search_service_with_key_async]
5151

5252
if __name__ == '__main__':

sdk/search/azure-search-documents/samples/async_samples/sample_autocomplete_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def autocomplete_query():
3232
# [START autocomplete_query_async]
3333
from azure.core.credentials import AzureKeyCredential
3434
from azure.search.documents.aio import SearchClient
35-
from azure.search.documents import AutocompleteQuery
35+
from azure.search.documents.models import AutocompleteQuery
3636

3737
search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(key))
3838

sdk/search/azure-search-documents/samples/async_samples/sample_crud_operations_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from azure.core.credentials import AzureKeyCredential
3131
from azure.search.documents.aio import SearchClient
32-
from azure.search.documents import SearchQuery
32+
from azure.search.documents.models import SearchQuery
3333

3434
search_client = SearchClient(service_endpoint, index_name, AzureKeyCredential(key))
3535

0 commit comments

Comments
 (0)