Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes es6. #340

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 0 additions & 4 deletions invenio_records_resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

"""Invenio Resources module to create REST APIs."""

from elasticsearch import VERSION as ES_VERSION

lt_es7 = ES_VERSION[0] < 7

SITE_UI_URL = "https://127.0.0.1:5000"

SITE_API_URL = "https://127.0.0.1:5000/api"
9 changes: 0 additions & 9 deletions invenio_records_resources/services/records/facets/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(self, label=None, value_labels=None, **kwargs):
"""Initialize class."""
self._label = label or ''
self._value_labels = value_labels
self._metric = None # Needed only for ES6 (can be removed later)
super().__init__(**kwargs)

def get_value(self, bucket):
Expand Down Expand Up @@ -65,14 +64,6 @@ def get_labelled_values(self, data, filter_values):
})
return {'buckets': out, 'label': str(self._label)}

def get_metric(self, bucket):
"""Compatibility for ES6."""
# This function is defined by elasticsearch-dsl v7, but not v6, so we
# add it here.
if self._metric:
return bucket["metric"]["value"]
return bucket["doc_count"]


class TermsFacet(LabelledFacetMixin, TermsFacetBase):
"""Terms facet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

from elasticsearch_dsl import Q

from invenio_records_resources.config import lt_es7

from .query import QueryParser


Expand Down Expand Up @@ -59,16 +57,9 @@ def __init__(self, identity=None, extra_params=None, **kwargs):
super().__init__(identity=identity, extra_params=extra_params)
self.extra_params.setdefault(
'type',
'phrase_prefix' if lt_es7 else 'bool_prefix'
'bool_prefix'
)

def parse(self, query_str):
"""Parse the query."""
if lt_es7 and self.extra_params.get('fields'):
# On ES v6 we have to filter out field names that uses the
# search_as_you_type field names (ending with ._2gram or ._3gram)
self.extra_params['fields'] = list(filter(
lambda x: not (x.endswith('._2gram') or x.endswith('._3gram')),
self.extra_params['fields']
))
return Q('multi_match', query=query_str, **self.extra_params)
6 changes: 1 addition & 5 deletions invenio_records_resources/services/records/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from invenio_records.dictutils import dict_lookup, dict_merge, dict_set

from ...config import lt_es7
from ...pagination import Pagination
from ..base import ServiceItemResult, ServiceListResult

Expand Down Expand Up @@ -150,10 +149,7 @@ def __iter__(self):
def total(self):
"""Get total number of hits."""
if hasattr(self._results, 'hits'):
if lt_es7:
return self._results.hits.total
else:
return self._results.hits.total["value"]
return self._results.hits.total["value"]
else:
# handle scan(): returns a generator
return None
Expand Down
4 changes: 1 addition & 3 deletions invenio_records_resources/services/records/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from kombu import Queue
from werkzeug.local import LocalProxy

from ...config import lt_es7
from ..base import LinksTemplate, Service
from ..errors import RevisionIdMismatchError
from ..uow import RecordCommitOp, RecordDeleteOp, unit_of_work
Expand Down Expand Up @@ -135,8 +134,7 @@ def create_search(self, identity, record_cls, search_opts,

# Extras
extras = {}
if not lt_es7:
extras["track_total_hits"] = True
extras["track_total_hits"] = True
search = search.extra(**extras)

return search
Expand Down