Skip to content

Commit

Permalink
Merge pull request #213 from NickolausDS/remove-results-format-version
Browse files Browse the repository at this point in the history
refactor: Remove `result_format_version` from search requests
  • Loading branch information
NickolausDS committed Dec 18, 2023
2 parents 3765580 + 64de00f commit b254233
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 93 deletions.
2 changes: 0 additions & 2 deletions docs/source/tutorial/search/search-settings-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ match directly with Globus Search fields, and match directly with Globus Search.
* sort
* boosts
* bypass_visible_to
* result_format_version

See more information in the `Globus Search documentation <https://docs.globus.org/api/search/reference/post_query/#gsearchrequest>`_

Expand All @@ -33,7 +32,6 @@ sort Sort results of a Globus Search
boosts Increase or decrease values of fields
filter_match Default filtering on 'term' facets. 'match-any' or 'match-all' supported
template_override_dir Directory for using different custom templates per-index on a multi-index portal
result_format_version Version of Search Result documents to return
bypass_visible_to Show all search records regardless visible_to permission (index admins only)
===================== ===========

Expand Down
13 changes: 1 addition & 12 deletions globus_portal_framework/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import globus_sdk

from globus_portal_framework.constants import (
FILTER_TYPES, DEFAULT_RESULT_FORMAT_VERSION
FILTER_TYPES
)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -34,17 +34,6 @@ def check_search_indexes(app_configs, **kwargs):
id='globus_portal_framework.settings.E001'
)
)
rf_version = idata.get('result_format_version')
if rf_version and rf_version != DEFAULT_RESULT_FORMAT_VERSION:
errors.append(Warning(
'Globus Portal Framework does not support '
f'result_format_version=="{rf_version}"',
obj=settings,
hint=('Suggested you unset settings.SEARCH_INDEXES.'
f'{index_name}.result_format_version'),
id='globus_portal_framework.settings.E002'
)
)
fm = idata.get('filter_match', None)
if fm is not None and fm not in FILTER_TYPES.keys():
errors.append(
Expand Down
4 changes: 1 addition & 3 deletions globus_portal_framework/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@

VALID_SEARCH_KEYS = [
'q', 'limit', 'offset', 'facets', 'filters', 'boosts', 'sort',
'query_template', 'advanced', 'bypass_visible_to', 'result_format_version',
'query_template', 'advanced', 'bypass_visible_to',
]

VALID_SEARCH_FACET_KEYS = [
'name', 'type', 'field_name', 'size', 'histogram_range', 'date_interval',
'missing'
]
# https://docs.globus.org/api/search/search/#request_documents
DEFAULT_RESULT_FORMAT_VERSION = '2019-08-27'

BASE_TEMPLATES = 'globus-portal-framework/v2/'

Expand Down
15 changes: 1 addition & 14 deletions globus_portal_framework/gsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

VALID_SEARCH_FACET_KEYS, VALID_SEARCH_KEYS,

DEFAULT_RESULT_FORMAT_VERSION,

DEFAULT_FACET_MODIFIERS,
)
FILTER_RANGE_SEPARATOR = getattr(settings, 'FILTER_RANGE_SEPARATOR',
Expand Down Expand Up @@ -96,8 +94,6 @@ def post_search(index, query, filters, user=None, page=1, search_kwargs=None):
'limit': get_setting('SEARCH_RESULTS_PER_PAGE')
})
search_data.update(search_kwargs or {})
search_data['result_format_version'] = search_data.get(
'result_format_version', DEFAULT_RESULT_FORMAT_VERSION)
try:
result = client.post_search(index_data['uuid'], search_data)
return {
Expand Down Expand Up @@ -443,12 +439,7 @@ def get_subject(index, subject, user=None):
client = load_search_client(user)
try:
idata = get_index(index)
if version.parse(globus_sdk.version.__version__).major < 3:
params = dict(result_format_version=DEFAULT_RESULT_FORMAT_VERSION)
else:
rfv = dict(result_format_version=DEFAULT_RESULT_FORMAT_VERSION)
params = dict(query_params=rfv)
result = client.get_subject(idata['uuid'], unquote(subject), **params)
result = client.get_subject(idata['uuid'], unquote(subject))
return process_search_data(idata.get('fields', {}), [result.data])[0]
except globus_sdk.SearchAPIError:
return {'subject': subject, 'error': 'No data was found for subject'}
Expand All @@ -466,10 +457,6 @@ def process_search_data(field_mappers, results):
"""
structured_results = []
for gmeta_result in results:
if gmeta_result.get('@version') != DEFAULT_RESULT_FORMAT_VERSION:
log.warning('Unsupported result format version '
'{}'.format(gmeta_result['@version']))
continue

entries = gmeta_result['entries']
content = [e['content'] for e in entries]
Expand Down
2 changes: 0 additions & 2 deletions globus_portal_framework/views/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
load_search_client
)
import globus_portal_framework.exc
from globus_portal_framework.constants import DEFAULT_RESULT_FORMAT_VERSION


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -126,7 +125,6 @@ def get_context_data(self, index):
'offset': self.offset,
'sort': self.sort,
'limit': self.results_per_page,
'result_format_version': DEFAULT_RESULT_FORMAT_VERSION,
}
try:
index_info = self.get_index_info(index)
Expand Down
54 changes: 0 additions & 54 deletions tests/data/search_legacy.json

This file was deleted.

6 changes: 0 additions & 6 deletions tests/test_gsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ def test_process_search_data_zero_length_content(mock_data):
assert data == []


def test_process_search_data_skips_legacy(mock_data):
sub = mock_data['search_legacy']['gmeta'][0]
mappers, results = [], [sub]
assert process_search_data(mappers, results) == []


def test_process_search_data_with_one_entry(mock_data):
# First search record
gmeta = mock_data['search']['gmeta'][0]
Expand Down

0 comments on commit b254233

Please sign in to comment.