def test_range_filter(): """Test range filter.""" f = range_filter('test', start_date_math='startmath', end_date_math='endmath') assert f(['1821--1940']) == Range(test={ 'gte': '1821||startmath', 'lte': '1940||endmath', }) assert f(['>1821--']) == Range(test={'gt': '1821||startmath'}) assert f(['1821--<1940']) == Range(test={'gte': '1821||startmath', 'lt': '1940||endmath'}) assert pytest.raises(RESTValidationError, f, ['2016']) assert pytest.raises(RESTValidationError, f, ['--'])
def seminars_start_date_range_filter(timezone): date_range_filter = range_filter("start_datetime", time_zone=timezone) def inner(values): value = values and values[0] if value == "upcoming": now = datetime.utcnow().isoformat() return Range(**{"start_datetime": {"gte": now}}) if value == "all": return Q() return date_range_filter(values) return inner
def conferences_start_date_range_filter(): date_range_filter = range_filter("opening_date") def inner(values): value = values and values[0] if value == "upcoming": today = datetime.utcnow().strftime("%Y-%m-%d") return Range(**{"opening_date": {"gte": today}}) if value == "all": return Q() return date_range_filter(values) return inner
def test_range_filter(): """Test range filter.""" f = range_filter('test', start_date_math='startmath', end_date_math='endmath') assert f(['1821--1940']) == Range(test={ 'gte': '1821||startmath', 'lte': '1940||endmath', }) assert f(['>1821--']) == Range(test={'gt': '1821||startmath'}) assert f(['1821--<1940']) == Range(test={ 'gte': '1821||startmath', 'lt': '1940||endmath' }) assert pytest.raises(RESTValidationError, f, ['2016']) assert pytest.raises(RESTValidationError, f, ['--'])
and_term_filter('organisation.pid'), 'language': and_term_filter('language.value'), 'subject': and_term_filter('facet_subjects'), 'specific_collection': and_term_filter('specificCollections'), 'document_type': and_term_filter('documentType'), 'controlled_affiliation': and_term_filter('contribution.controlledAffiliation.raw'), 'author': and_term_filter('contribution.agent.preferred_name.raw'), 'year': range_filter('provisionActivity.startDate', format='yyyy', end_date_math='/y') }), 'deposits': dict(aggs=dict( status=dict(terms=dict(field='status', size=DEFAULT_AGGREGATION_SIZE)), user=dict(terms=dict(field='user.full_name.keyword', size=DEFAULT_AGGREGATION_SIZE)), contributor=dict(terms=dict(field='facet_contributors', size=DEFAULT_AGGREGATION_SIZE))), filters={ _('pid'): and_term_filter('pid'), _('status'): and_term_filter('status'), _('user'): and_term_filter('user.full_name.keyword'), _('contributor'): and_term_filter('facet_contributors'), }),
"embargoed access", "restricted access", "metadata only access" ], })), _('resourceType'): nested_filter('resourceType', language_aware_text_terms_filter('resourceType.title')), _('keywords'): language_aware_text_terms_filter('keywords'), _('subject'): language_aware_text_terms_filter('subjectAll'), _('language'): nested_filter('language', language_aware_text_terms_filter('language.title')), _('date'): range_filter('dateAll.date'), _('dateIssued'): range_filter('dateIssued.date'), _('dateDefended'): range_filter('dateDefended.date'), _('dateModified'): range_filter('dateModified.date'), } CURATOR_FILTERS = { _('accessRightsCurator'): nested_filter('accessRights', language_aware_text_terms_filter('accessRights.title')), _('rights'): nested_filter('rights', language_aware_text_terms_filter('rights.title')), _('provider'):
experiment=terms_filter('experiment.keyword'), type=terms_filter('type.primary.keyword'), subtype=terms_filter('type.secondary.keyword'), year=terms_filter('date_created.keyword'), tags=terms_filter('tags.keyword'), keywords=terms_filter('keywords.keyword'), collision_type=terms_filter('collision_information.type.keyword'), collision_energy=terms_filter('collision_information.energy' '.keyword'), category=terms_filter('categories.primary.keyword'), subcategory=terms_filter('categories.secondary.keyword'), file_type=terms_filter('distribution.formats.keyword'), collections=terms_filter('collections.keyword'), availability=terms_filter('distribution.availability.keyword'), signature=terms_filter('signature.keyword'), event_number=range_filter('distribution.number_events') ) } } """Facets per index for the default facets factory.""" # Generated by scripts/get_facet_hierarchy.py FACET_HIERARCHY = { "availability": {}, "category": { "B physics and Quarkonia": {"subcategory": set()}, "Exotica": {"subcategory": {"Miscellaneous", "Gravitons"}}, "Higgs Physics": { "subcategory": { "Beyond Standard Model",
'noquery': '-record_creation_date' }, } RECORDS_REST_FACETS = { "records-record": { "filters": { "journal": terms_filter("publication_info.journal_title"), "country": terms_filter_with_must("authors.affiliations.country"), "collaboration": terms_filter("facet_collaboration"), "record_creation_date": range_filter('record_creation_date', format='yyyy', end_date_math='/y') }, "aggs": { "journal": { "terms": { "field": "publication_info.journal_title", "size": 20, "order": { "_term": "asc" } } }, "country": { "terms": { "field": "authors.affiliations.country",
def inner(values): range_values = [f'{v}-01--{v}-12' for v in values] return range_filter(field, start_date_math, end_date_math, **kwargs)(range_values)
) ), post_filters=dict( identifier=terms_filter( 'other_standard_identifier.source_of_number_or_code' ), language=terms_filter( ('language_code.language_code_of_text_sound_track_or' '_separate_title') ), affiliation=terms_filter( 'main_entry_personal_name.affiliation' ), years=range_filter( '_created', format='yyyy', end_date_math='/y' ), ) ) ) # TODO: Remove once schema validation issue is fixed. INDEXER_DEFAULT_INDEX = 'marc21-bibliographic-bd-v1.0.0' INDEXER_DEFAULT_DOCTYPE = 'bd-v1.0.0' # TODO: Remove me once the problem with email is solved in flask-security: # https://github.com/mattupstate/flask-security/issues/685 SECURITY_EMAIL_SENDER = 'no-reply@localhost' # OAI-PMH Server
document_type=dict(terms=dict(field='type', size=1000)), author=dict(terms=dict(field='facet_authors', size=5)), years=dict(date_histogram=dict( field='publicationYear', interval='year', format='yyyy')), ), # can be also post_filter filters={ _('status'): terms_filter('itemslist._circulation.status'), _('location'): terms_filter('itemslist.location_name'), _('language'): terms_filter('languages.language'), _('document_type'): terms_filter('type'), _('author'): terms_filter('facet_authors') }, post_filters={ _('years'): range_filter('publicationYear', format='yyyy', end_date_math='/y') }), 'patrons': dict(aggs=dict(roles=dict(terms=dict(field='roles', size=100))), filters={_('roles'): terms_filter('roles')}) } # sort RECORDS_REST_SORT_OPTIONS = { 'documents': dict( bestmatch=dict(fields=['_score'], title='Best match', default_order='asc'), mostrecent=dict(fields=['-_created'], title='Most recent',
order=2, ), album=dict( fields=['sort_album'], title='Album', default_order='asc', order=3, ), artist=dict( fields=['facet_artist'], title='Artist', default_order='asc', order=4, ))) RECORDS_REST_DEFAULT_SORT = dict(records=dict(query='bestmatch', noquery='album'), ) RECORDS_REST_FACETS = dict(records=dict( aggs={ 'mime': dict(terms=dict(field='mime')), 'genre': dict(terms=dict(field='genre', size=30)), 'years': dict(date_histogram=dict(field='year', interval='year', format='yyyy')) }, filters=dict(mime=terms_filter('mime'), genre=terms_filter('genre')), post_filters=dict(years=range_filter( 'year', format='yyyy', end_date_math='/y'), )))
def hep_author_publications(): exclude_value = request.values.get('exclude_author_value', '', type=str) return { "filters": { "author": must_match_all_filter('facet_author_name'), "author_count": range_author_count_filter('author_count'), "doc_type": must_match_all_filter('facet_inspire_doc_type'), "earliest_date": range_filter( 'earliest_date', format='yyyy', end_date_math='/y') }, "aggs": { "earliest_date": { "date_histogram": { "field": "earliest_date", "interval": "year", "format": "yyyy", "min_doc_count": 1, }, "meta": { "title": "Date", "order": 1, }, }, "author_count": { "range": { "field": "author_count", "ranges": [ { "key": "10 authors or less", "from": 1, "to": 11, }, ], }, "meta": { "title": "Number of authors", "order": 2, }, }, "author": { "terms": { "field": "facet_author_name", "size": 20, "exclude": exclude_value, }, "meta": { "title": "Collaborators", "order": 3, "split": True, }, }, "doc_type": { "terms": { "field": "facet_inspire_doc_type", "size": 20 }, "meta": { "title": "Document Type", "order": 4, }, }, }, }
def hep_author_publications(): exclude_value = request.values.get('exclude_author_value', '', type=str) return { "filters": { "author": must_match_all_filter('facet_author_name'), "author_count": range_author_count_filter('author_count'), "doc_type": must_match_all_filter('facet_inspire_doc_type'), "earliest_date": range_filter('earliest_date', format='yyyy', end_date_math='/y') }, "aggs": { "earliest_date": { "date_histogram": { "field": "earliest_date", "interval": "year", "format": "yyyy", "min_doc_count": 1, }, "meta": { "title": "Date", "order": 1, }, }, "author_count": { "range": { "field": "author_count", "ranges": [ { "key": "10 authors or less", "from": 1, "to": 11, }, ], }, "meta": { "title": "Number of authors", "order": 2, }, }, "author": { "terms": { "field": "facet_author_name", "size": 20, "exclude": exclude_value, }, "meta": { "title": "Collaborators", "order": 3, "split": True, }, }, "doc_type": { "terms": { "field": "facet_inspire_doc_type", "size": 20 }, "meta": { "title": "Document Type", "order": 4, }, }, }, }
#: Default sort for records REST API. RECORDS_REST_DEFAULT_SORT = { "records-record": { 'query': '-record_creation_date', 'noquery': '-record_creation_date' }, } RECORDS_REST_FACETS = { "records-record": { "filters": { "journal": terms_filter("publication_info.journal_title"), "country": terms_filter_with_must("authors.affiliations.country"), "collaboration": terms_filter("facet_collaboration"), "record_creation_date": range_filter( 'record_creation_date', format='yyyy', end_date_math='/y') }, "aggs": { "journal": { "terms": { "field": "publication_info.journal_title", "size": 20, "order": {"_term": "asc"} } }, "country": { "terms": { "field": "authors.affiliations.country", "size": 150, "order": {"_term": "asc"}
field='subject_added_entry_topical_term.' 'topical_term_or_geographic_name_entry_element')), years=dict(date_histogram=dict(field='imprint.complete_date', interval='year', format='yyyy')), ), post_filters=dict( authors=terms_filter( 'added_entry_personal_name.personal_name'), languages=terms_filter('language_code.language_code_of_text_' 'sound_track_or_separate_title'), topic=terms_filter( 'subject_added_entry_topical_term.' 'topical_term_or_geographic_name_entry_element'), years=range_filter('imprint.complete_date', format='yyyy', end_date_math='/y'), ))), RECORDS_REST_SORT_OPTIONS=dict( testrecords=dict(bestmatch=dict( title='Best match', fields=['-_score'], default_order='asc', order=1, ), controlnumber=dict( title='Control number', fields=['control_number'], default_order='desc', order=2, ))),
years=dict(date_histogram=dict( field='imprint.complete_date', interval='year', format='yyyy')), ), post_filters=dict( authors=terms_filter( 'added_entry_personal_name.personal_name'), languages=terms_filter( 'language_code.language_code_of_text_' 'sound_track_or_separate_title'), topic=terms_filter( 'subject_added_entry_topical_term.' 'topical_term_or_geographic_name_entry_element'), years=range_filter( 'imprint.complete_date', format='yyyy', end_date_math='/y'), ) ) ), RECORDS_REST_SORT_OPTIONS=dict( testrecords=dict( bestmatch=dict( title='Best match', fields=['-_score'], default_order='asc', order=1, ), controlnumber=dict( title='Control number', fields=['control_number'],
#: Default sort for records REST API. RECORDS_REST_DEFAULT_SORT = { "scoap3-records-record": { 'query': '-date', 'noquery': '-date' }, } RECORDS_REST_FACETS = { "scoap3-records-record": { "filters": { "journal": terms_filter("publication_info.journal_title"), "country": terms_filter_with_must("authors.affiliations.country"), "collaboration": terms_filter("facet_collaboration"), "year": range_filter( 'year', format='yyyy', end_date_math='/y') }, "aggs": { "journal": { "terms": { "field": "publication_info.journal_title", "size": 20, "order": {"_term": "asc"} } }, "country": { "terms": { "field": "authors.affiliations.country", "size": 150, "order": {"_term": "asc"}
}, }, 'years': { 'date_histogram': { 'field': 'date', 'interval': 'year', 'format': 'yyyy' } } }, 'filters': { 'keyword': terms_filter('keywords.name'), 'category': terms_filter('category.untouched'), 'type': terms_filter('type.untouched'), 'language': terms_filter('language'), 'years': range_filter('date', format='yyyy', end_date_math='/y'), }, } } # Deposit search index. DEPOSIT_UI_SEARCH_INDEX = 'deposits-records-videos-project' # Options for sorting deposits. DEPOSIT_REST_SORT_OPTIONS = { 'deposits-records-videos-project': dict(bestmatch=dict(fields=['-_score'], title='Best match', default_order='asc', order=1), mostrecent=dict(
}, }, }, }, 'post_filters': { 'type': regex_filter('_type'), 'type_version': terms_filter('_type'), 'cms_working_group': prefix_filter('basic_info.cadi_id'), 'cadi_status': terms_filter('cadi_info.status'), 'next_deadline_date': range_filter('analysis_context.next_deadline_date', format='yyyy', end_date_math='/y'), 'collision_system': terms_filter('basic_info.analysis_keywords.collision_system.keyword'), 'accelerator_parameters': terms_filter( 'basic_info.analysis_keywords.accelerator_parameters.keyword'), 'physics_theme': terms_filter('basic_info.analysis_keywords.physics_theme.keyword'), 'final_states': terms_filter('basic_info.analysis_keywords.final_states.keyword'), 'sm_analysis_characteristics': terms_filter( 'basic_info.analysis_keywords.sm_analysis_characteristics.keyword' ), # noqa 'interpretation':
"jobs_facets": JOBS_FACETS, "journals": JOURNALS, "experiments": EXPERIMENTS, "conferences": CONFERENCES, "conferences_facets": CONFERENCES_FACETS, "data": DATA, "institutions": INSTITUTIONS, "seminars": SEMINARS, "seminars_facets": SEMINARS_FACETS, } HEP_FILTERS = { "author": must_match_all_filter("facet_author_name"), "author_count": range_author_count_filter("author_count"), "doc_type": must_match_all_filter("facet_inspire_doc_type"), "earliest_date": range_filter("earliest_date", format="yyyy", end_date_math="/y"), "citation_count": range_filter("citation_count"), "citation_count_without_self_citations": range_filter( "citation_count_without_self_citations" ), "collaboration": must_match_all_filter("facet_collaborations"), "refereed": must_match_all_filter("refereed"), "citeable": must_match_all_filter("citeable"), "collection": must_match_all_filter("_collections"), "subject": must_match_all_filter("facet_inspire_categories"), "arxiv_categories": must_match_all_filter("facet_arxiv_categories"), "rpp": filter_from_filters_aggregation(hep_rpp(order=1)), } JOBS_FILTERS = { "field_of_interest": terms_filter("arxiv_categories"),
op='lte'), relation=enum_term_filter(label='relation', field='RelationshipType', choices={ 'isCitedBy': 'Cites', 'isSupplementedBy': 'IsSupplementTo', 'isRelatedTo': 'IsRelatedTo' }), keyword=simple_query_string_filter('Source.Keywords_all'), journal=nested_terms_filter('Source.Publisher.Name', 'Source.Publisher'), ), post_filters=dict( type=terms_filter('Source.Type.Name'), publication_year=range_filter('Source.PublicationDate', format='yyyy', start_date_math='/y', end_date_math='/y'), )), # The topHits agg can't be addded here due to limitations in elasticsearch_dsl aggs function so that is added in query.py metadata=dict( aggs=dict( NumberOfTargets=dict(cardinality=dict(field='Target.ID')), publication_year=dict(date_histogram=dict( field='Source.PublicationDate', interval='year', format='yyyy', ), ), ), filters=dict( group_by=enum_term_filter(label='group_by',
"journals": JOURNALS, "experiments": EXPERIMENTS, "conferences": CONFERENCES, "data": DATA, "institutions": INSTITUTIONS, } HEP_COMMON_FILTERS = { "author": must_match_all_filter("facet_author_name"), "author_count": range_author_count_filter("author_count"), "doc_type": must_match_all_filter("facet_inspire_doc_type"), "earliest_date": range_filter("earliest_date", format="yyyy", end_date_math="/y"), "citation_count": range_filter("citation_count"), "collaboration": must_match_all_filter("facet_collaborations"), "refereed": must_match_all_filter("refereed"), "citeable": must_match_all_filter("citeable"), } HEP_FILTERS = { "subject": must_match_all_filter("facet_inspire_categories"), "arxiv_categories": must_match_all_filter("facet_arxiv_categories"), }
#: Default sort for records REST API. RECORDS_REST_DEFAULT_SORT = { "scoap3-records-record": { "query": "-date", "noquery": "-date" }, } RECORDS_REST_FACETS = { "scoap3-records-record": { "filters": { "journal": terms_filter("publication_info.journal_title"), "country": terms_filter_with_must("authors.affiliations.country"), "collaboration": terms_filter("facet_collaboration"), "year": range_filter("year", format="yyyy", end_date_math="/y"), }, "aggs": { "journal": { "terms": { "field": "publication_info.journal_title", "size": 20, "order": { "_term": "asc" }, } }, "country": { "terms": { "field": "authors.affiliations.country", "size": 150,