Skip to content

Commit

Permalink
ext: readability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
carantunes committed Nov 25, 2019
1 parent 48e699f commit acf4f5b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions invenio_search/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .cli import index as index_cmd
from .errors import IndexAlreadyExistsError
from .utils import build_alias_name, build_index_from_parts, \
build_index_name, timestamp_suffix, unsuffix_index
build_index_name, timestamp_suffix, unsuffix_index, suffix_index


class _SearchState(object):
Expand Down Expand Up @@ -316,8 +316,10 @@ def _exists_alias(name, index):
raise IndexAlreadyExistsError(
'alias with name "{}" already exists'.format(name))

def _unsuffix_indices_with_wildcard(indices):
return [unsuffix_index(index) + "*" for index in indices]
def _build_match_any_suffix_indices(indices):
return [
suffix_index(unsuffix_index(index), "-*") for index in indices
]

def _build(tree_or_filename, alias=None):
"""Build a list of index/alias actions to perform."""
Expand Down Expand Up @@ -357,10 +359,10 @@ def _build(tree_or_filename, alias=None):
]
if alias_indices:
alias_name = build_alias_name(alias, app=self.app)
wildcard_indices = _unsuffix_indices_with_wildcard(
any_suffix_indices = _build_match_any_suffix_indices(
alias_indices
)
ensure_alias_not_exists(alias_name, wildcard_indices)
ensure_alias_not_exists(alias_name, any_suffix_indices)
actions.append(dict(
type='create_alias',
index=alias_indices,
Expand Down

0 comments on commit acf4f5b

Please sign in to comment.