Search
Domain package for searching transcribed documents via the Riksarkivet Search API.
Models
models
Data models for Riksarkivet search operations.
Models are designed to closely match the Search API JSON structure.
DocumentLinks
Bases: BaseModel
Links from API _links field.
GenericReference
Bases: BaseModel
Generic reference (archival institution, hierarchy level, provenance).
Maps to the GenericReference type in the Swagger spec. All fields are nullable.
Metadata
Bases: BaseModel
Document metadata from API.
PageInfo
Bases: BaseModel
Page information from snippet.
Note: id is marked nullable in the Swagger spec but is always present in search results. We default to "" for safety.
RecordsResponse
Bases: BaseModel
Search API response matching /api/records endpoint.
Maps to the full API response structure from /api/records.
count_snippets()
Count total snippets across all records.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
155 156 157 | |
SearchRecord
Bases: BaseModel
Record from search API matching JSON structure (objectType: Record, type: Volume).
get_collection_url()
Get collection URL for this document.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
117 118 119 | |
get_manifest_url()
Get manifest URL from links.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
111 112 113 114 115 | |
get_snippet_count()
Get number of snippets returned for this document.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
129 130 131 | |
get_title()
Get document title or default.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
121 122 123 | |
get_total_hits()
Get total number of hits in this document.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
125 126 127 | |
SearchResult
Bases: BaseModel
Search result with query context.
Wraps RecordsResponse with the search parameters used to execute the search. Parameter names match the Search API specification.
items
property
Get records from response.
keyword
property
Alias for transcribed_text for backward compatibility.
total_hits
property
Get total hits from response.
count_snippets()
Count total snippets across all records.
Source code in packages/search-lib/src/ra_mcp_search_lib/models.py
189 190 191 | |
Snippet
Bases: BaseModel
Text snippet with search match.
Note: text and pages are marked nullable in the Swagger spec but are always present in search results. We use safe defaults.
TranscribedText
Bases: BaseModel
Transcribed text information.
Note: snippets is marked nullable in the Swagger spec but is always present (possibly empty) in search results.
Client
SearchClient(http_client)
Client for Riksarkivet Search API.
Handles searching transcribed documents and returns structured responses that directly map to the API's JSON structure.
Source code in packages/search-lib/src/ra_mcp_search_lib/search_client.py
29 30 31 | |
search(text=None, transcribed_text=None, only_digitised_materials=True, limit=DEFAULT_LIMIT, offset=0, max_snippets_per_record=None, sort='relevance', year_min=None, year_max=None, name=None, place=None)
async
Search for records using various search parameters.
Parameter names match the Search API specification for clarity. You can search either transcribed materials or general text (metadata, names, places).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | None
|
General free-text search across all fields |
None
|
transcribed_text
|
str | None
|
Search specifically in AI-transcribed text (requires only_digitised_materials=True) |
None
|
only_digitised_materials
|
bool
|
Limit results to digitised materials (default: True, API default: False) |
True
|
limit
|
int
|
Maximum number of records to return |
DEFAULT_LIMIT
|
offset
|
int
|
Pagination offset (API parameter name) |
0
|
max_snippets_per_record
|
int | None
|
Client-side snippet limiting per record (not sent to API) |
None
|
sort
|
str
|
Sort order — one of: relevance, timeAsc, timeDesc, alphaAsc, alphaDesc |
'relevance'
|
year_min
|
int | None
|
Filter results to this start year or later |
None
|
year_max
|
int | None
|
Filter results to this end year or earlier |
None
|
name
|
str | None
|
Search by person name (API field, can combine with text) |
None
|
place
|
str | None
|
Search by place name (API field, can combine with text) |
None
|
Returns:
| Type | Description |
|---|---|
RecordsResponse
|
RecordsResponse with all API fields populated |
Raises:
| Type | Description |
|---|---|
ValueError
|
If transcribed_text is used without only_digitised_materials=True |
Source code in packages/search-lib/src/ra_mcp_search_lib/search_client.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
search_transcribed_text(transcribed_text, limit=DEFAULT_LIMIT, offset=0, max_snippets_per_record=None)
async
Search for keyword in transcribed materials (convenience method).
This is a convenience wrapper around the main search() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transcribed_text
|
str
|
Search term or Solr query (API parameter name) |
required |
limit
|
int
|
Maximum number of records to return |
DEFAULT_LIMIT
|
offset
|
int
|
Pagination offset (API parameter name) |
0
|
max_snippets_per_record
|
int | None
|
Client-side snippet limiting per record (not sent to API) |
None
|
Returns:
| Type | Description |
|---|---|
RecordsResponse
|
RecordsResponse with all API fields populated |
Source code in packages/search-lib/src/ra_mcp_search_lib/search_client.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
Operations
SearchOperations(http_client)
Search operations for Riksarkivet document collections.
Provides keyword search functionality.
Attributes:
| Name | Type | Description |
|---|---|---|
search_api |
Client for executing text searches. |
Source code in packages/search-lib/src/ra_mcp_search_lib/search_operations.py
30 31 | |
search(keyword, transcribed_only=True, only_digitised=True, offset=0, limit=10, max_snippets_per_record=None, sort='relevance', year_min=None, year_max=None, name=None, place=None, research_context=None, session_id=None)
async
Search for records in document collections.
Executes a keyword search across Riksarkivet collections. Can search either transcribed text specifically or general metadata (titles, names, places, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keyword
|
str
|
Search term or phrase to look for. |
required |
transcribed_only
|
bool
|
If True, search in transcribed text only. If False, search all fields. |
True
|
only_digitised
|
bool
|
Limit results to digitized materials (default: True). |
True
|
offset
|
int
|
Number of results to skip for pagination. |
0
|
limit
|
int
|
Maximum number of documents to return. |
10
|
max_snippets_per_record
|
int | None
|
Limit snippets per document (None for unlimited). |
None
|
sort
|
str
|
Sort order — one of: relevance, timeAsc, timeDesc, alphaAsc, alphaDesc. |
'relevance'
|
year_min
|
int | None
|
Filter results to this start year or later. |
None
|
year_max
|
int | None
|
Filter results to this end year or earlier. |
None
|
name
|
str | None
|
Search by person name (can combine with keyword). |
None
|
place
|
str | None
|
Search by place name (can combine with keyword). |
None
|
research_context
|
str | None
|
User's research goal (recorded as span attribute for telemetry). |
None
|
Returns:
| Type | Description |
|---|---|
SearchResult
|
SearchResult containing documents, total count, and metadata. |
Source code in packages/search-lib/src/ra_mcp_search_lib/search_operations.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
search_transcribed(keyword, offset=0, limit=10, max_snippets_per_record=None)
async
Search for transcribed text across document collections (convenience method).
Executes a keyword search across all transcribed documents in the Riksarkivet collections. This is a convenience wrapper around the main search() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keyword
|
str
|
Search term or phrase to look for in transcribed text. |
required |
offset
|
int
|
Number of results to skip for pagination. |
0
|
limit
|
int
|
Maximum number of documents to return. |
10
|
max_snippets_per_record
|
int | None
|
Limit snippets per document (None for unlimited). |
None
|
Returns:
| Type | Description |
|---|---|
SearchResult
|
SearchResult containing documents, total count, and metadata. |
Source code in packages/search-lib/src/ra_mcp_search_lib/search_operations.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |