Skip to content

Commit 9b385ef

Browse files
authored
[Search] Add reset_documents and reset_skills operations (Azure#21475)
* Add reset_skills and reset_documents calls. * Update changelog. * Add async operations. Allow name or object invocation. * Code review comment. * Expose DocumentKeysOrIds and update typehints. * Add reset_skills tests. * Code review feedback.
1 parent 116e162 commit 9b385ef

File tree

8 files changed

+251
-76
lines changed

8 files changed

+251
-76
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Added properties to `SearchIndexerDataSourceConnection`: `identity`, `encryption_key`.
99
- Added `select` property to the following `SearchIndexClient` operations: `get_synonym_maps`, `list_indexes`.
1010
- Added `select` property to the following `SearchIndexersClient` operations: `get_data_source_connections`, `get_indexers`, `get_skillsets`.
11+
- Added operations to `SearchIndexerClient`: `reset_skills`, `reset_documents`.
12+
- Added model: `DocumentKeysOrIds`
1113

1214
### Other Changes
1315

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
if TYPE_CHECKING:
2929
# pylint:disable=unused-import,ungrouped-imports
30-
from ._generated.models import SearchIndexer, SearchIndexerStatus
30+
from ._generated.models import SearchIndexer, SearchIndexerStatus, DocumentKeysOrIds
3131
from typing import Any, Optional, Sequence, Union
3232
from azure.core.credentials import TokenCredential
3333

@@ -285,6 +285,30 @@ def reset_indexer(self, name, **kwargs):
285285
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
286286
self._client.indexers.reset(name, **kwargs)
287287

288+
@distributed_trace
289+
def reset_documents(self, indexer, keys_or_ids, **kwargs):
290+
# type: (Union[str, SearchIndexer], DocumentKeysOrIds, **Any) -> None
291+
"""Resets specific documents in the datasource to be selectively re-ingested by the indexer.
292+
293+
:param indexer: The indexer to reset documents for.
294+
:type indexer: str or ~azure.search.documents.indexes.models.SearchIndexer
295+
:param keys_or_ids:
296+
:type keys_or_ids: ~azure.search.documents.indexes.models.DocumentKeysOrIds
297+
:return: None, or the result of cls(response)
298+
:keyword overwrite: If false, keys or ids will be appended to existing ones. If true, only the
299+
keys or ids in this payload will be queued to be re-ingested. The default is false.
300+
:paramtype overwrite: bool
301+
:rtype: None
302+
:raises: ~azure.core.exceptions.HttpResponseError
303+
"""
304+
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
305+
kwargs["keys_or_ids"] = keys_or_ids
306+
try:
307+
name = indexer.name
308+
except AttributeError:
309+
name = indexer
310+
return self._client.indexers.reset_docs(name, **kwargs)
311+
288312
@distributed_trace
289313
def get_indexer_status(self, name, **kwargs):
290314
# type: (str, **Any) -> SearchIndexerStatus
@@ -547,8 +571,8 @@ def delete_skillset(self, skillset, **kwargs):
547571
the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide
548572
the name of the skillset to delete unconditionally
549573
550-
:param name: The SearchIndexerSkillset to delete
551-
:type name: str or ~azure.search.documents.indexes.models.SearchIndexerSkillset
574+
:param skillset: The SearchIndexerSkillset to delete
575+
:type skillset: str or ~azure.search.documents.indexes.models.SearchIndexerSkillset
552576
:keyword match_condition: The match condition to use upon the etag
553577
:type match_condition: ~azure.core.MatchConditions
554578
@@ -635,6 +659,26 @@ def create_or_update_skillset(self, skillset, **kwargs):
635659
)
636660
return SearchIndexerSkillset._from_generated(result) # pylint:disable=protected-access
637661

662+
@distributed_trace
663+
def reset_skills(self, skillset, skill_names, **kwargs):
664+
# type: (Union[str, SearchIndexerSkillset], List[str], **Any) -> None
665+
"""Reset an existing skillset in a search service.
666+
667+
:param skillset: The SearchIndexerSkillset to reset
668+
:type skillset: str or ~azure.search.documents.indexes.models.SearchIndexerSkillset
669+
:param skill_names: the names of skills to be reset.
670+
:type skill_names: list[str]
671+
:return: None, or the result of cls(response)
672+
:rtype: None
673+
:raises: ~azure.core.exceptions.HttpResponseError
674+
"""
675+
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
676+
try:
677+
name = skillset.name
678+
except AttributeError:
679+
name = skillset
680+
return self._client.skillsets.reset_skills(name, skill_names, **kwargs)
681+
638682
def _validate_skillset(skillset):
639683
"""Validates any multi-version skills in the skillset to verify that unsupported
640684
parameters are not supplied by the user.

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

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
if TYPE_CHECKING:
2727
# pylint:disable=unused-import,ungrouped-imports
28-
from .._generated.models import SearchIndexer, SearchIndexerStatus
28+
from .._generated.models import SearchIndexer, SearchIndexerStatus, DocumentKeysOrIds
2929
from typing import Any, Optional, Sequence
3030
from azure.core.credentials_async import AsyncTokenCredential
3131

@@ -278,6 +278,31 @@ async def reset_indexer(self, name, **kwargs):
278278
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
279279
await self._client.indexers.reset(name, **kwargs)
280280

281+
@distributed_trace_async
282+
async def reset_documents(self, indexer, keys_or_ids, **kwargs):
283+
# type: (Union[str, SearchIndexer], DocumentKeysOrIds, **Any) -> None
284+
"""Resets specific documents in the datasource to be selectively re-ingested by the indexer.
285+
286+
:param indexer: The indexer to reset documents for.
287+
:type indexer: str or ~azure.search.documents.indexes.models.SearchIndexer
288+
:param keys_or_ids:
289+
:type keys_or_ids: ~azure.search.documents.indexes.models.DocumentKeysOrIds
290+
:return: None, or the result of cls(response)
291+
:keyword overwrite: If false, keys or ids will be appended to existing ones. If true, only the
292+
keys or ids in this payload will be queued to be re-ingested. The default is false.
293+
:paramtype overwrite: bool
294+
:rtype: None
295+
:raises: ~azure.core.exceptions.HttpResponseError
296+
"""
297+
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
298+
kwargs["keys_or_ids"] = keys_or_ids
299+
try:
300+
name = indexer.name
301+
except AttributeError:
302+
name = indexer
303+
result = await self._client.indexers.reset_docs(name, **kwargs)
304+
return result
305+
281306
@distributed_trace_async
282307
async def get_indexer_status(self, name, **kwargs):
283308
# type: (str, **Any) -> SearchIndexerStatus
@@ -535,8 +560,8 @@ async def delete_skillset(self, skillset, **kwargs):
535560
the SearchIndexerSkillset model must be provided instead of the name. It is enough to provide
536561
the name of the skillset to delete unconditionally
537562
538-
:param name: The SearchIndexerSkillset to delete
539-
:type name: str or ~azure.search.documents.indexes.models.SearchIndexerSkillset
563+
:param skillset: The SearchIndexerSkillset to delete
564+
:type skillset: str or ~azure.search.documents.indexes.models.SearchIndexerSkillset
540565
:keyword match_condition: The match condition to use upon the etag
541566
:type match_condition: ~azure.core.MatchConditions
542567
@@ -619,3 +644,24 @@ async def create_or_update_skillset(self, skillset, **kwargs):
619644
**kwargs
620645
)
621646
return SearchIndexerSkillset._from_generated(result) # pylint:disable=protected-access
647+
648+
@distributed_trace_async
649+
async def reset_skills(self, skillset, skill_names, **kwargs):
650+
# type: (Union[str, SearchIndexerSkillset], List[str], **Any) -> None
651+
"""Reset an existing skillset in a search service.
652+
653+
:param skillset: The SearchIndexerSkillset to reset
654+
:type skillset: str or ~azure.search.documents.indexes.models.SearchIndexerSkillset
655+
:param skill_names: the names of skills to be reset.
656+
:type skill_names: list[str]
657+
:return: None, or the result of cls(response)
658+
:rtype: None
659+
:raises: ~azure.core.exceptions.HttpResponseError
660+
"""
661+
kwargs["headers"] = self._merge_client_headers(kwargs.get("headers"))
662+
try:
663+
name = skillset.name
664+
except AttributeError:
665+
name = skillset
666+
result = await self._client.skillsets.reset_skills(name, skill_names, **kwargs)
667+
return result

sdk/search/azure-search-documents/azure/search/documents/indexes/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
DistanceScoringFunction,
5353
DistanceScoringParameters,
5454
DocumentExtractionSkill,
55+
DocumentKeysOrIds,
5556
EdgeNGramTokenFilter,
5657
EdgeNGramTokenizer,
5758
EdgeNGramTokenFilterSide,
@@ -199,6 +200,7 @@
199200
"DistanceScoringFunction",
200201
"DistanceScoringParameters",
201202
"DocumentExtractionSkill",
203+
"DocumentKeysOrIds",
202204
"EdgeNGramTokenFilter",
203205
"EdgeNGramTokenizer",
204206
"ElisionTokenFilter",

0 commit comments

Comments
 (0)