Skip to content

Commit

Permalink
Add (non)separator token sub routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ellnix committed Oct 24, 2023
1 parent cfe5bb0 commit f988c0b
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions meilisearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Paths:
pagination = "pagination"
faceting = "faceting"
dictionary = "dictionary"
separator_tokens = "separator-tokens"
non_separator_tokens = "non-separator-tokens"
swap = "swap-indexes"

def __init__(
Expand Down
118 changes: 118 additions & 0 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,124 @@ def reset_dictionary(self) -> TaskInfo:

return TaskInfo(**task)

# TEXT SEPARATOR SUB-ROUTES

def get_separator_tokens(self) -> List[str]:
"""Get the additional text separator tokens set on this index.
Returns
-------
settings:
List containing the separator tokens of the index.
Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
return self.http.get(self.__settings_url_for(self.config.paths.separator_tokens))

def get_non_separator_tokens(self) -> List[str]:
"""Get the list of disabled text separator tokens on this index.
Returns
-------
settings:
List containing the disabled separator tokens of the index.
Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
return self.http.get(self.__settings_url_for(self.config.paths.non_separator_tokens))

def update_separator_tokens(self, body: List[str]) -> TaskInfo:
"""Update the additional separator tokens of the index.
Parameters
----------
body:
List of the new separator tokens.
Returns
-------
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
task = self.http.put(self.__settings_url_for(self.config.paths.separator_tokens), body)

return TaskInfo(**task)

def update_non_separator_tokens(self, body: List[str]) -> TaskInfo:
"""Update the disabled separator tokens of the index.
Parameters
----------
body:
List of the newly disabled separator tokens.
Returns
-------
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
task = self.http.put(self.__settings_url_for(self.config.paths.non_separator_tokens), body)

return TaskInfo(**task)

def reset_separator_tokens(self) -> TaskInfo:
"""Clear all additional separator tokens
Returns
-------
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
task = self.http.delete(
self.__settings_url_for(self.config.paths.separator_tokens),
)

return TaskInfo(**task)

def reset_non_separator_tokens(self) -> TaskInfo:
"""Clear all disabled separator tokens
Returns
-------
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
task = self.http.delete(
self.__settings_url_for(self.config.paths.non_separator_tokens),
)

return TaskInfo(**task)

@staticmethod
def _batch(
documents: List[Dict[str, Any]], batch_size: int
Expand Down

0 comments on commit f988c0b

Please sign in to comment.