Metadata-Version: 2.5
Name: invenio-global-search
Version: 0.8.0
Summary: InvenioRDM module for a Global Search
Project-URL: Repository, https://github.com/tu-graz-library/invenio-global-search
Author: Graz University of Technology.
License-Expression: MIT
License-File: LICENSE
Keywords: invenio,rdm,search
Classifier: Development Status :: 5 - Production/Stable
Requires-Python: >=3.12
Requires-Dist: invenio-records-global-search>=0.0.1
Provides-Extra: lom
Requires-Dist: invenio-records-lom>=0.12.0; extra == 'lom'
Provides-Extra: marc21
Requires-Dist: invenio-records-marc21>=0.17.0; extra == 'marc21'
Provides-Extra: rdm
Requires-Dist: invenio-rdm-records>=18.0.0; extra == 'rdm'
Provides-Extra: tests
Requires-Dist: invenio-app>=2.0.0; extra == 'tests'
Requires-Dist: invenio-search[opensearch2]>=3.0.0; extra == 'tests'
Requires-Dist: pytest-black>=0.6.0; extra == 'tests'
Requires-Dist: pytest-invenio>=3.0.0; extra == 'tests'
Requires-Dist: ruff>=0.11.9; extra == 'tests'
Requires-Dist: ty>=0.0.0a1; extra == 'tests'
Description-Content-Type: text/markdown

<!--
SPDX-FileCopyrightText: 2023-2026 Graz University of Technology.
SPDX-License-Identifier: MIT
-->

# invenio-global-search

Dublin Core data model for InvenioRDM

### Tests

```console
uv run ./run-tests.sh
```

## Installation

This basic installation of this package:

```console
uv pip install invenio-global-search
```

will not give access to any of its features. It is intended to be extended
with the packages needed in a specific Invenio instance.

There are 3 packages handled by ``invenio-global-search``:

- `rdm-records`
- `lom` (OER)
- `marc21` (Publications)

To install any of them or all:

- ```console
  uv pip install invenio-global-search[rdm]
  ```

  This enables the `rdm-records` features.

- ```console
  uv pip install invenio-global-search[rdm, marc21, lom]
  ```

  This enables all the features of the package.


## Configuration

Add the following code blocks to the `invenio.cfg` file.


### Components

If all packages mentioned above are installed, simply add:

```python
from invenio_rdm_records.services.components import DefaultRecordsComponents
from invenio_global_search.components import (
    LOMToGlobalSearchComponent,
    Marc21ToGlobalSearchComponent,
    RDMToGlobalSearchComponent,
)
from invenio_rdm_records.services.components import (
    DefaultRecordsComponents as RDMDefaultRecordsComponents,
)
from invenio_records_lom.services.components import (
    DefaultRecordsComponents as LOMDefaultRecordsComponents,
)
from invenio_records_marc21.services.components import (
    DefaultRecordsComponents as Marc21DefaultRecordsComponents,
)


RDM_RECORDS_SERVICE_COMPONENTS = RDMDefaultRecordsComponents + [
    RDMToGlobalSearchComponent
]
LOM_RECORDS_SERVICE_COMPONENTS = LOMDefaultRecordsComponents + [
    LOMToGlobalSearchComponent
]
MARC21_RECORDS_SERVICE_COMPONENTS = Marc21DefaultRecordsComponents + [
    Marc21ToGlobalSearchComponent
]
```

If there is a chance that one of them is not installed, this can be handled
with `try-except`:

```python

try:
    from invenio_records_marc21.services.components import (
        DefaultRecordsComponents as Marc21DefaultRecordsComponents,
    )
except ImportError:
    Marc21DefaultRecordsComponents = None

if Marc21DefaultRecordsComponents is not None:
    MARC21_RECORDS_SERVICE_COMPONENTS = Marc21DefaultRecordsComponents + [
        Marc21ToGlobalSearchComponent
    ]
else:
    MARC21_RECORDS_SERVICE_COMPONENTS = [Marc21ToGlobalSearchComponent]
```

### Search template

```python

SEARCH_UI_SEARCH_TEMPLATE = "invenio_records_dublin_core/search/search.html"

from invenio_search_ui.views import blueprint
from flask import render_template

@blueprint.route("/records/search")
def records_search():
    """Search page ui."""
    return render_template("invenio_app_rdm/records/search.html")
```

### Schema

As mentioned for components, if all packages are installed, add:

```python

GLOBAL_SEARCH_ORIGINAL_SCHEMAS = {
    "lom": {
        "schema": "lom",
        "name_l10n": _("OER"),
    },
    "rdm": {
        "schema": "rdm",
        "name_l10n": _("Research Result"),
    },
    "marc21": {
        "schema": "marc21",
        "name_l10n": _("Publication"),
    },
}
```

If one or more is missing, simply remove the entry for the respective package.


### OpenAIRE Indexing

TODO

## ListRecords & GetRecord features

An InvenioRDM repository can be harvested via the Open Archives Initiative Protocol for Metadata Harvesting (OAI-PMH). OAI-PMH is a widely used protocol for harvesting metadata and most popular repository software provide support for this protocol.

Because Global search needs to support multiple data models, the default `OAISERVER_` features had to be overridden with custom function and classes that are based mostly on `global-search` index. This works also because global-search keeps track only of open-access records.

Currently supported custom OAI Features:
  - ListRecords and GetRecord for

    - metadataPrefix = oai_dc -> records from all 3 data models are serialized
    - metadataPrefix = lom -> only OER records are serialized
    - metadataPrefix = marc21 -> only Publication records are serialized

Access these by searching for the endpoint `/oai2d` and adding params like `?verb=ListRecords`. Examples:

 - `https://yourinvenio.com/oai2d?verb=ListRecords&metadataPrefix=marc21`
 - `https://yourinvenio.com/oai2d?verb=GetRecord&identifier=oai:yourinvenio.com:46t12-eng12&metadataPrefix=marc21`


## Sets

TODO

Further documentation is available on
https://invenio-global-search.readthedocs.io/
