Content Search¶
iiiris can search the text of the annotations in its annotation store and answer with the IIIF Content Search API 2.0 and 1.0, plus the matching autocomplete services. A viewer (Mirador, Universal Viewer) finds the search box through a service entry in the manifest.
This is phase A: search within one object, that is, within one derived manifest. Search is built in and off by default. It uses an embedded index (Bleve); there is no separate search server to run.
Enabling search¶
annotations:
enabled: true
dir: /var/lib/iiiris/annotations
search:
enabled: true
dir: /var/lib/iiiris/search
search.enabled: true and search.dir are the whole minimum configuration.
Search requires the annotation store: iiirisd refuses to start with
search: requires annotations.enabled if annotations.enabled is false. It
also refuses to start if search.dir is empty or not writable, or if shards
is less than 1.
| Key | Env var | Default | Meaning |
|---|---|---|---|
search.enabled |
IIIRIS_SEARCH_ENABLED |
false |
Build and serve the index. |
search.dir |
IIIRIS_SEARCH_DIR |
empty | Directory the index is kept in. Required when enabled. |
search.shards |
IIIRIS_SEARCH_SHARDS |
32 |
Number of index shards. Changing it rebuilds the index. |
search.default_languages |
none | empty | Map of image identifier prefix to language, for annotation text that declares no language. See Languages. |
default_languages has no environment variable; set it in the YAML file:
The longest matching prefix wins. See Configuration for the full reference.
Routes and manifest services¶
| Route | API |
|---|---|
GET /iiif/search/2/{id} |
Content Search 2.0 |
GET /iiif/search/1/{id} |
Content Search 1.0 |
GET /iiif/autocomplete/2/{id} |
Autocomplete 2.0 |
GET /iiif/autocomplete/1/{id} |
Autocomplete 1.0 |
{id} is the same identifier used in /iiif/presentation/3/{id}.
Derived Presentation 3.0 manifests advertise the services when search is
enabled: a SearchService2 with a nested AutoCompleteService2, and a
SearchService1 with a nested AutoCompleteService1. Derived 2.1 manifests do
not advertise search. The services always declare exact matching. With
search off, manifests are unchanged.
Search requests¶
qis required. An emptyqor one longer than 256 characters returns 400.- The query is always literal text. There are no operators or query syntax. A
quoted query such as
"grey heron"is an exact phrase. A CJK query matches consecutive characters. A query that mixes scripts (Latin and CJK together) is matched as a phrase in untagged text. motivationrestricts hits to the given motivations: a space-separated list, matching annotations that have any of them.dateanduserare accepted but not applied; they are listed in the response'signoredfield.pageis the 0-based page number. A page holds 100 annotations.- Hits come back in page (canvas) order, then position in the text. They are not ranked by relevance.
- Each hit carries a snippet of up to 30 characters on each side of the match. A snippet never runs into a neighbouring annotation. Matches that overlap in one annotation are reported as one hit.
- The text searched is that of
TextualBodybodies (andbodyValue). A body with notypebut a stringvaluecounts as aTextualBody, as the Web Annotation model implies.
Autocomplete requests¶
q must be at least 2 characters. A response lists up to 10 terms.
motivation, date, user and min are not applied and appear in
ignored, and the response id echoes them after q. In phase A,
autocomplete does not suggest terms for CJK text.
Languages¶
Matching has three layers:
- Folding, for all text: case, accents and character width are ignored.
- Stemming (Snowball), only for text with a language tag, or for untagged
text whose image identifier matches a
search.default_languagesprefix. - CJK bigrams for Chinese, Japanese and Korean text.
Untagged text with no matching default language gets folding only.
Access¶
A reader only finds annotations they could read with a GET on the
annotation store.
- Annotations of an image that is hard-denied to the reader never appear in hits, counts or autocomplete suggestions. Substitute access (an image served in a reduced form) counts as access.
- When an authorization hook takes part in the decision,
total(2.0) andwithin.total(1.0) are omitted from search responses, and autocomplete counts are omitted (terms are then ordered by how many readable hits they have). Each hit is checked through the same decision annotation reads use (the hook sees the annotation read path,/annotations/{container}/). The access rules and the reader's session are checked on every request, so a logout or a revoked session removes gated hits at once. Only the hook's own answer is cached, for 30 seconds per reader (credentials and client IP address) and image, so a change in what the hook decides can take that long to reach search. If the hook returns an error, search drops the hit (an annotationGETwould return 500), and the error is not cached: the next request asks the hook again. - Requests with the annotation write token (
Authorization: Bearer <write_token>) search every container of the manifest. - Responses for gated manifests, when a hook takes part, or to a write-token
request are sent with
Cache-Control: private, no-cacheandVary: Cookie, Authorization.
Indexing and operation¶
Indexing is asynchronous. An annotation write becomes searchable within about
a second (writes are batched every 500 ms). The words of a just-deleted
annotation may still be suggested by autocomplete for a short time, but its
search hit is dropped. If indexing a container after a write fails, iiirisd
logs it at ERROR. That container's results stay stale until its next write,
and iiirisd writes the rebuilding marker (logged at WARN), so the next
start rebuilds the index.
At shutdown iiirisd drains HTTP requests for up to server.shutdown_timeout,
then indexes every queued write and closes the index. A request still running
after that gets a 503 (the index is closed). An annotation write that
finishes after that is stored but not indexed. iiirisd writes the
rebuilding marker instead (logged at WARN), so the next start rebuilds
the index and the write becomes searchable.
search.dir needs no backup. The index is derived data, rebuilt from the
annotation store when it is:
- missing,
- written by a different index format version,
- opened with a different
shardsvalue, - damaged, or
- left by an interrupted build or rebuild (a
rebuildingmarker file is present).
A rebuild removes only the index's own files (meta.json, shard-NN
directories, rebuilding and their temporary files). Do not share
search.dir with other data. Back up annotations.dir, not the search
directory.
This is a single-node feature. Do not point several replicas at one
search.dir.
Not yet available¶
Later phases, not in this release:
- Search across a collection or across manifests.
- Searching manifest metadata.
- A search page, a source walk that indexes text outside the annotation store, a re-index trigger and an admin panel (phase B).
- Elasticsearch and OpenSearch backends (phase C).
- Benchmarks and a documented size ceiling (phase D).