Skip to main content

Suggestions

Introduction

A suggestion is a keyword or name displayed as a user types. For example: if a user types 'rem', suggestions might be 'Rembrandt' or 'Rem Koolhaas'. Suggestions help users save time. A user can select one of the suggested keywords or names and find entities matching the suggestion. This functionality is also known as autocompletion or typeahead.

Suggestions are tied to a heritage collection, ensuring that results remain within the context of a specific collection.

Suggestions are an OPTIONAL extension. A data layer may choose whether or not to implement them.

Data model

NameDescription
Root Suggestion CollectionA collection of suggestion collections.
Suggestion CollectionA collection of suggestions.
Keyword Suggestion CollectionA collection of keyword suggestions. Specialization of Suggestion Collection.
Entity Suggestion CollectionA collection of entity suggestions. Specialization of Suggestion Collection.
Combined Suggestion CollectionA collection of keyword and entity suggestions. Specialization of Suggestion Collection.
Suggestion TermA selectable option within a suggestion collection, e.g. a keyword or entity.
Keyword SuggestionA keyword matching a suggestion query, e.g. 'windmill'. The keyword can be used as input to search for entities and find all that match it.
EntityAn entity matching a suggestion query, e.g. a heritage object named 'A Watermill'.

The following entity-relationship diagram visualizes the data model:

note

To be discussed: replace the ER diagram with a class diagram to make the relationships clearer (e.g. inheritance).

Search strategies

Suggestions can be found by using different search strategies. The data layer decides which strategy fits best. Common strategies include:

  1. Prefix search. Prefix search restricts results to strings that start with the user's input. For example, the query mil will return mill, but not windmill. This strategy is optimized for speed and predictability; it is best suited for scenarios where users are searching for specific entities by their primary name or when the data layer wants to encourage an 'autocomplete-as-you-type' experience starting from the first letter.
  2. Infix search. Infix search is a more flexible matching that looks for a query anywhere within a string. For example, the query mil will return mill and windmill. This is the recommended strategy when the data layer wants users to discover entities using parts of a name, even if they do not know exactly how the name begins. Be aware that infix search can be more computationally expensive than prefix search.

Endpoint: Retrieve a root suggestion collection

The endpoint retrieves a root suggestion collection belonging to a heritage collection. The API MUST implement this endpoint if it supports suggestions.

This is a discovery endpoint: it allows presentation layers to identify the suggestion collections and their endpoint URIs.

HTTP request

GET /{version}/{collections}(/{...collections})/{collection}/{extensions}/{suggestions}

Path parameters

NameData typeCardinalityDescription
versionstring1The version of the API. Example: v1.
collectionsstring1The path identifier of the top root heritage collection. Example: collections.
...collectionsstring0 or moreThe path identifier(s) of further root heritage collections. Example: objects.
collectionstring1The path identifier of the heritage collection. Example: masterpieces.
extensionsstring1The path identifier of the extension collection. Example: extensions.
suggestionsstring1The path identifier of the root suggestion collection. Example: suggestions.

Query parameters

None.

Request body

None.

Response body

The response body MUST contain at least the following fields:

NameData typeCardinalityDescription
idstring1The identifier of the collection.
typestring1The type of the collection. It MUST be RootSuggestionCollection.
namestring1A short, human-readable name of the collection.
totalItemsnumber1The total number of suggestion collections in the collection.
itemsarray1A list of all suggestion collections. The API defines the order.
items[*]SuggestionCollection1A suggestion collection.
items[*].idstring1The identifier of the suggestion collection.
items[*].typestring1The type of the suggestion collection. It MAY be one of KeywordSuggestionCollection, EntitySuggestionCollection, CombinedSuggestionCollection or a suggestion collection type defined by the API.
items[*].namestring1A short, human-readable name of the suggestion collection.
partOfExtensionCollection1The extension collection of which this extension is a part.
partOf.idstring1The identifier of the extension collection.
partOf.typestring1The type of the extension collection. It MUST be ExtensionCollection.

Example

An example request from a presentation layer:

GET /v1/collections/objects/extensions/suggestions HTTP/2
Host: example.org

The request indicates that the API should return the suggestion collection belonging to a heritage collection (objects).

An example of the response body of the API:

{
"id": "https://example.org/v1/collections/objects/extensions/suggestions",
"type": "RootSuggestionCollection",
"name": "Suggestions",
"totalItems": 3,
"items": [
{
"id": "https://example.org/v1/collections/objects/extensions/suggestions/keywords",
"type": "KeywordSuggestionCollection",
"name": "Keyword suggestions"
},
{
"id": "https://example.org/v1/collections/objects/extensions/suggestions/entities",
"type": "EntitySuggestionCollection",
"name": "Entity suggestions"
},
{
"id": "https://example.org/v1/collections/objects/extensions/suggestions/combinations",
"type": "CombinedSuggestionCollection",
"name": "Keyword and entity suggestions"
}
],
"partOf": {
"id": "https://example.org/v1/collections/objects/extensions",
"type": "ExtensionCollection"
}
}

The response indicates that the API supports three suggestion collections for a heritage collection (objects): keyword suggestions, entity suggestions and combined suggestions.

Endpoint: Suggest keywords

The endpoint retrieves a list of keywords matching a query. A presentation layer can use a keyword as input to search for entities and find all entities that match the keyword. The endpoint is OPTIONAL: it MAY be implemented by the API.

HTTP request

GET /{version}/{collections}(/{...collections})/{collection}/{extensions}/{suggestions}/{suggestion}

Path parameters

NameData typeCardinalityDescription
versionstring1The version of the API. Example: v1.
collectionsstring1The path identifier of the top root heritage collection. Example: collections.
...collectionsstring0 or moreThe path identifier(s) of further root heritage collections. Example: objects.
collectionstring1The path identifier of the heritage collection. Example: masterpieces.
extensionsstring1The path identifier of the extension collection. Example: extensions.
suggestionsstring1The path identifier of the root suggestion collection. Example: suggestions.
suggestionstring1The path identifier of the keyword suggestion collection. Example: keywords.

Query parameters

NameData typeCardinalityDescription
qstring1A keyword query for filtering the suggestion terms. Minimum length: defined by the data layer (e.g. 3 characters). Maximum length: defined by the API (e.g. 25 characters). The API defines how the query is matched, e.g. by using prefix or infix search.
sizenumber0 or 1The maximum number of suggestion terms to retrieve. Minimum: 1. Default: 10. Maximum: defined by the API (e.g. 25).
orderBystring0 or 1The sorting order of the suggestion terms. It MUST be one of relevance, value. Default: relevance:desc (most relevant suggestion first). The API defines which value is used to sort by value (e.g. the name of a keyword).

Request body

None.

Response body

The response body MUST contain at least the following fields:

NameData typeCardinalityDescription
idstring1The identifier of the collection.
typestring1The type of the collection. It MUST be KeywordSuggestionCollection.
namestring1A short, human-readable name of the collection.
totalItemsnumber1The total number of suggestion terms in the collection.
itemsarray1A list of suggestion terms. Empty if no suggestions matched the query.
items[*]SuggestionTerm1A suggestion term.
items[*].typestring1The type of the suggestion term. It MUST be SuggestionTerm.
items[*].relevancenumber1The relevance of the suggestion to the query. It MUST be a whole number between 0 (not relevant) and 100 (relevant).
items[*].valueKeywordSuggestion1The suggested keyword.
items[*].value.typestring1The type of the keyword. It MUST be KeywordSuggestion.
items[*].value.namestring1The name of the keyword.
partOfRootSuggestionCollection1The root suggestion collection of which this suggestion collection is a part.
partOf.idstring1The identifier of the root suggestion collection.
partOf.typestring1The type of the root suggestion collection. It MUST be RootSuggestionCollection.

Example

An example request from a presentation layer:

GET /v1/collections/objects/extensions/suggestions/keywords?q=mil HTTP/2
Host: example.org

The request indicates that the API should return keyword suggestions from a heritage collection (objects) matching a specific query (mil).

An example of the response body of the API:

{
"id": "https://example.org/v1/collections/objects/extensions/suggestions/keywords?q=mil",
"type": "KeywordSuggestionCollection",
"name": "Keyword suggestions",
"totalItems": 2,
"items": [
{
"type": "SuggestionTerm",
"relevance": 98,
"value": {
"type": "KeywordSuggestion",
"name": "mill"
}
},
{
"type": "SuggestionTerm",
"relevance": 92,
"value": {
"type": "KeywordSuggestion",
"name": "windmill"
}
}
],
"partOf": {
"id": "https://example.org/v1/collections/objects/extensions/suggestions",
"type": "RootSuggestionCollection"
}
}

Endpoint: Suggest entities

The endpoint retrieves a list of entities matching a query. An entity in the list can then be directly retrieved. The endpoint is OPTIONAL: it MAY be implemented by the API.

HTTP request

GET /{version}/{collections}(/{...collections})/{collection}/{extensions}/{suggestions}/{suggestion}

Path parameters

NameData typeCardinalityDescription
versionstring1The version of the API. Example: v1.
collectionsstring1The path identifier of the top root heritage collection. Example: collections.
...collectionsstring0 or moreThe path identifier(s) of further root heritage collections. Example: objects.
collectionstring1The path identifier of the heritage collection. Example: masterpieces.
extensionsstring1The path identifier of the extension collection. Example: extensions.
suggestionsstring1The path identifier of the root suggestion collection. Example: suggestions.
suggestionstring1The path identifier of the entity suggestion collection. Example: entities.

Query parameters

NameData typeCardinalityDescription
qstring1A keyword query for filtering the suggestion terms. Minimum length: defined by the data layer (e.g. 3 characters). Maximum length: defined by the API (e.g. 25 characters). The API defines how the query is matched, e.g. by using prefix or infix search.
sizenumber0 or 1The maximum number of suggestion terms to retrieve. Minimum: 1. Default: 10. Maximum: defined by the API (e.g. 25).
orderBystring0 or 1The sorting order of the suggestion terms. One of relevance, value. Default: relevance:desc (most relevant suggestion first). The API defines which value is used to sort by value (e.g. the name of an entity).

Request body

None.

Response body

The response body MUST contain at least the following fields:

NameData typeCardinalityDescription
idstring1The identifier of the collection.
typestring1The type of the collection. It MUST be EntitySuggestionCollection.
namestring1A short, human-readable name of the collection.
totalItemsnumber1The total number of suggestion terms in the collection.
itemsarray1A list of suggestions terms. Empty if no suggestions matched the query.
items[*]SuggestionTerm1A suggestion term.
items[*].typestring1The type of the suggestion term. It MUST be SuggestionTerm.
items[*].relevancenumber1The relevance of the suggestion to the query. It MUST be a whole number between 0 (not relevant) and 100 (relevant).
items[*].valueEntity1The suggested entity.
items[*].value.idstring1The identifier of the entity.
items[*].value.typestring1The type of the entity.
items[*].value.namestring1The name of the entity.
partOfRootSuggestionCollection1The root suggestion collection of which this suggestion collection is a part.
partOf.idstring1The identifier of the root suggestion collection.
partOf.typestring1The type of the root suggestion collection. It MUST be RootSuggestionCollection.

The API may expose additional fields about a suggested entity.

Example

An example request from a presentation layer:

GET /v1/collections/objects/extensions/suggestions/entities?q=mil HTTP/2
Host: example.org

The request indicates that the API should return entity suggestions from a heritage collection (objects) matching a specific query (mil).

An example of the response body of the API:

{
"id": "https://example.org/v1/collections/objects/extensions/suggestions/entities?q=mil",
"type": "EntitySuggestionCollection",
"name": "Entity suggestions",
"totalItems": 2,
"items": [
{
"type": "SuggestionTerm",
"relevance": 98,
"value": {
"id": "https://example.org/v1/entities/objects/1234",
"type": "HeritageObject",
"name": "A Watermill"
// Optionally: other fields
}
},
{
"type": "SuggestionTerm",
"relevance": 92,
"value": {
"id": "https://example.org/v1/entities/objects/5678",
"type": "HeritageObject",
"name": "Windmill at Wijk bij Duurstede"
// Optionally: other fields
}
}
],
"partOf": {
"id": "https://example.org/v1/collections/objects/extensions/suggestions",
"type": "RootSuggestionCollection"
}
}

Endpoint: Suggest keywords and entities, combined

The endpoint retrieves a list of both keywords and entities matching a query. The API determines the distribution between keywords and entities returned (e.g. proportional or based on relevance). The endpoint is OPTIONAL: it MAY be implemented by the API.

note

To be discussed: is this endpoint useful or do the separate endpoints - one for keywords, one for entities - suffice?

HTTP request

GET /{version}/{collections}(/{...collections})/{collection}/{extensions}/{suggestions}/{suggestion}

Path parameters

NameData typeCardinalityDescription
versionstring1The version of the API. Example: v1.
collectionsstring1The path identifier of the top root heritage collection. Example: collections.
...collectionsstring0 or moreThe path identifier(s) of further root heritage collections. Example: objects.
collectionstring1The path identifier of the heritage collection. Example: masterpieces.
extensionsstring1The path identifier of the extension collection. Example: extensions.
suggestionsstring1The path identifier of the root suggestion collection. Example: suggestions.
suggestionstring1The path identifier of the keyword and entity suggestion collection. Example: combinations.

Query parameters

NameData typeCardinalityDescription
qstring1A keyword query for filtering the suggestion terms. Minimum length: defined by the data layer (e.g. 3 characters). Maximum length: defined by the data layer (e.g. 25 characters). The API defines how the query is matched, e.g. by using prefix or infix search.
sizenumber0 or 1The maximum number of suggestion terms to retrieve. Default: 10. Maximum: 25.
orderBystring0 or 1The sorting order of the suggestion terms. One of relevance, value. Default: relevance:desc (most relevant suggestion first). The API defines which value is used to sort by value (e.g. the name of a keyword or the name of an entity).

Request body

None.

Response body

The response body MUST contain at least the following fields:

NameData typeCardinalityDescription
idstring1The identifier of the collection.
typestring1The type of the collection. It MUST be CombinedSuggestionCollection.
namestring1A short, human-readable name of the collection.
totalItemsnumber1The total number of suggestion terms in the collection.
itemsarray1A list of suggestions terms. Empty if no suggestions matched the query.
items[*]SuggestionTerm1A suggestion term.
items[*].typestring1The type of the suggestion term. It MUST be SuggestionTerm.
items[*].relevancenumber1The relevance of the suggestion to the query. It MUST be a whole number between 0 (not relevant) and 100 (relevant).
items[*].valueKeywordSuggestion, Entity1The suggested keyword or entity.
items[*].value.idstring0 or 1The identifier of the entity. Not set if the type is KeywordSuggestion; a keyword has no identity.
items[*].value.typestring1The type of the keyword (it MUST be KeywordSuggestion) or the type of the entity.
items[*].value.namestring1The name of the keyword or entity.
partOfRootSuggestionCollection1The root suggestion collection of which this suggestion collection is a part.
partOf.idstring1The identifier of the root suggestion collection.
partOf.typestring1The type of the root suggestion collection. It MUST be RootSuggestionCollection.

The API may expose additional fields about a suggested entity.

Example

An example request from a presentation layer:

GET /v1/collections/objects/extensions/suggestions/combinations?q=mil HTTP/2
Host: example.org

The request indicates that the API should return keyword and entity suggestions from a heritage collection (objects) matching a specific query (mil).

An example of the response body of the API:

{
"id": "https://example.org/v1/collections/objects/extensions/suggestions/combinations?q=mil",
"type": "CombinedSuggestionCollection",
"name": "Keyword and entity suggestions",
"totalItems": 2,
"items": [
{
"type": "SuggestionTerm",
"relevance": 98,
"value": {
"type": "KeywordSuggestion",
"name": "windmill"
}
},
{
"type": "SuggestionTerm",
"relevance": 95,
"value": {
"id": "https://example.org/v1/entities/objects/1234",
"type": "HeritageObject",
"name": "A Watermill"
// Optionally: other fields
}
}
],
"partOf": {
"id": "https://example.org/v1/collections/objects/extensions/suggestions",
"type": "RootSuggestionCollection"
}
}