Skip to content

Commit

Permalink
Support for legacy urls
Browse files Browse the repository at this point in the history
  • Loading branch information
psaiz committed Jan 10, 2024
1 parent 7e05047 commit 2041ed2
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 507 deletions.
174 changes: 16 additions & 158 deletions cernopendata/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import warnings

from flask import request
from invenio_records_files.api import _Record
from invenio_records_rest.config import RECORDS_REST_ENDPOINTS
from invenio_records_rest.facets import nested_filter, range_filter, terms_filter
Expand All @@ -38,6 +39,8 @@
from cernopendata.modules.search_ui.helpers import CODSearchAppInvenioRestConfigHelper
from cernopendata.modules.theme.config import *

from .views import search_legacy

# Disable opensearch warning of connecting without checking certificates
warnings.filterwarnings(action="ignore", category=UserWarning, module=r".*urllib3")
warnings.filterwarnings(
Expand Down Expand Up @@ -216,14 +219,18 @@
def _query_parser_and(qstr=None):
"""Parser that uses the Q() with AND from search engine dsl."""
if qstr:
return dsl.Q("query_string", query=qstr.replace("/", "\\/"), default_operator="AND")
return dsl.Q()
_query = dsl.Q(
"query_string", query=qstr.replace("/", "\\/"), default_operator="AND"
)
else:
_query = dsl.Q()
if request.values.get("ondemand") != "true":
_query = _query & ~dsl.Q("match", **{"distribution.availability": "ondemand"})
return _query


RECORDS_REST_ENDPOINTS["recid"].update(
{
# 'search_factory_imp': 'cernopendata.modules.records.search.query'
# ':cernopendata_search_factory',
"search_query_parser": _query_parser_and,
"pid_minter": "cernopendata_recid_minter",
"pid_fetcher": "cernopendata_recid_fetcher",
Expand Down Expand Up @@ -337,7 +344,9 @@ def _query_parser_and(qstr=None):
),
),
experiment=dict(terms=dict(field="experiment", order=dict(_key="asc"))),
year=dict(terms=dict(field="date_created", size=70, order=dict(_key="asc"))),
year=dict(
terms=dict(field="date_created", size=70, order=dict(_key="asc"))
),
file_type=dict(
terms=dict(
field="distribution.formats", size=50, order=dict(_key="asc")
Expand Down Expand Up @@ -404,159 +413,6 @@ def _query_parser_and(qstr=None):

"""Facets per index for the default facets factory."""

# # Generated by scripts/get_facet_hierarchy.py
# FACET_HIERARCHY = {
# "category": {
# "B physics and Quarkonia": {"subcategory": set()},
# "Exotica": {"subcategory": {"Miscellaneous", "Gravitons"}},
# "Higgs Physics": {
# "subcategory": {
# "Beyond Standard Model",
# "Standard Model"
# }
# },
# "Physics Modelling": {"subcategory": set()},
# "Standard Model Physics": {
# "subcategory": {
# "Drell-Yan",
# "ElectroWeak",
# "Forward and Small-x " "QCD Physics",
# "Minimum Bias",
# "QCD",
# "Top physics",
# }
# },
# "Supersymmetry": {"subcategory": set()},
# },
# "collision_energy": {
# "0.9TeV": {},
# "0TeV": {},
# "13TeV": {},
# "2.76TeV": {},
# "7TeV": {},
# "8TeV": {},
# },
# "collision_type": {"Interfill": {}, "PbPb": {}, "pp": {}},
# "event_number": {
# "0--999": {},
# "1000--9999": {},
# "10000--99999": {},
# "100000--999999": {},
# "1000000--9999999": {},
# "10000000--": {},
# },
# "experiment": {
# "ALICE": {},
# "ATLAS": {},
# "CMS": {},
# "LHCb": {},
# "OPERA": {}
# },
# "file_type": {
# "C": {},
# "aod": {},
# "aodsim": {},
# "cc": {},
# "csv": {},
# "docx": {},
# "fevtdebughlt": {},
# "gen-sim": {},
# "gen-sim-digi-raw": {},
# "gen-sim-reco": {},
# "gz": {},
# "h5": {},
# "html": {},
# "ig": {},
# "ipynb": {},
# "jpg": {},
# "json": {},
# "m4v": {},
# "miniaodsim": {},
# "nanoaod": {},
# "ova": {},
# "pdf": {},
# "png": {},
# "py": {},
# "raw": {},
# "reco": {},
# "root": {},
# "tar": {},
# "tar.gz": {},
# "txt": {},
# "xls": {},
# "xml": {},
# "zip": {},
# },
# "keywords": {
# "datascience": {},
# "education": {},
# "external resource": {},
# "heavy-ion physics": {},
# "masterclass": {},
# "teaching": {},
# },
# "signature": {
# "H": {},
# "Jpsi": {},
# "W": {},
# "Y": {},
# "Z": {},
# "electron": {},
# "missing transverse energy": {},
# "muon": {},
# "photon": {},
# },
# "type": {
# "Dataset": {"subtype": {"Simulated", "Derived", "Collision"}},
# "Documentation": {
# "subtype": {
# "About",
# "Activities",
# "Authors",
# "Guide",
# "Help",
# "Policy",
# "Report",
# }
# },
# "Environment": {"subtype": {"VM", "Condition", "Validation"}},
# "Glossary": {"subtype": set()},
# "News": {"subtype": set()},
# "Software": {
# "subtype": {
# "Analysis",
# "Framework",
# "Tool",
# "Validation",
# "Workflow"
# }
# },
# "Supplementaries": {
# "subtype": {
# "Configuration",
# "Configuration HLT",
# "Configuration LHE",
# "Configuration RECO",
# "Configuration SIM",
# "Luminosity",
# "Trigger",
# }
# },
# },
# "year": {
# "2008": {},
# "2009": {},
# "2010": {},
# "2011": {},
# "2012": {},
# "2016": {},
# "2018": {},
# "2019": {},
# },
# }

"""Hierarchy of facets containing subfacets."""

# Files
# ======
#: Permission factory to control the files access from the REST interface.
Expand Down Expand Up @@ -587,6 +443,8 @@ def _query_parser_and(qstr=None):
"invenio_records_rest": CODSearchAppInvenioRestConfigHelper,
}


SEARCH_UI_DEFAULT_FUNC = search_legacy
# OAI-PMH
# =======
#: Default Elasticsearch index.
Expand Down

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions cernopendata/modules/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import pkg_resources
from flask import (
Blueprint,
Response,
abort,
current_app,
escape,
Expand All @@ -37,10 +38,9 @@
render_template,
request,
url_for,
Response,
)
from invenio_i18n import lazy_gettext as _
from flask_breadcrumbs import default_breadcrumb_root
from invenio_i18n import lazy_gettext as _
from jinja2.exceptions import TemplateNotFound
from speaklater import make_lazy_string

Expand Down Expand Up @@ -173,7 +173,7 @@ def record_redirect(recid):
@blueprint.route("/glossary")
def glossary():
"""Display glossary terms."""
return redirect("/search?type=Glossary&sort=title")
return redirect("/search?f=type%3AGlossary&sort=title")


@blueprint.route("/glossary/json")
Expand Down
Loading

0 comments on commit 2041ed2

Please sign in to comment.