Both document types and full schemas can be inherited to make it easy to
design a structured application package with little duplication.
Document type inheritance defines a type hierarchy which is also useful for applications that
federate queries
as queries can be written to the common supertype.
This guide covers the different elements in the schema that supports inheritance:
Schemas
Document types
Rank profiles
Document summaries
Note:
Inheritance is not to be confused with parent/child,
which is a feature to import field values at query time.
Schema inheritance
A schema that inherits another gets all the content of the parent schema
as if it was defined inside the inheriting schema.
A schema that inherits another must also (explicitly) inherit its document type:
A document type can inherit another document type. This will include all fields, also fields declared outside the
document block in the schema, rank-profiles defined in the super-schema can then be inherited in the schema of this
document, see Rank profile inheritance below.
Both schemas music and books have the title field through inheritance:
my-app/schemas/items.sd:
documentitems{field title typestring{indexing:summary|index}}
Where fields define the document types, rank profiles define the computations over the documents.
Rank profiles can be inherited from rank-profiles defined in the same schema, or defined in another schema when this
document inherits the document defined in the schema where the rank profile is defined:
my-app/schemas/items.sd:
schemaitems{documentitems{field title typestring{indexing:summary|index}}rank-profileitems_ranking_base{functiontitle_score(){expression:fieldLength(title)}first-phase{expression:title_score}summary-features{title_score}}}
schemamusic{documentmusicinheritsitems{field artist typestring{indexing:summary|index}}rank-profileitems_rankinginheritsitems_ranking_base{}rank-profileitems_subschema_rankinginheritsitems_ranking_base{first-phase{expression:title_score+fieldMatch(artist)}summary-featuresinheritsitems_ranking_base{fieldMatch(artist)}}}
items_ranking can be considered the "base" ranking.
Pro-tip: Set this as the default rank profile
by modifying the default query profile:
Queries using ranking.profile=default will then use the first-phase ranking defined in items.sd.
Another way to inherit behavior is to override the first-phase ranking in the sub-schemas,
still using functions defined in the super-schema (e.g. title_score).
Summary features
Summary-features and
match-features
are rank features computed during ranking,
to be included in results.
These features can be inherited from parent rank profiles - the
above example uses inherits to include scores from
features in super- and sub-schema - example result:
In the examples above, both books and music schemas implement rank profiles
with same names (e.g. items_subschema_ranking),
so they can be used in queries spanning both.
If a query's rank profile can not be found in a given schema,
Vespa's default rank profile nativerank is used.
Inputs to a rank profile are automatically inherited from
the parent rank profile. If a new inputs block is defined in a child rank profile, those inputs will be
added cumulatively to those defined in the parent.
Document summary inheritance
Document summaries can inherit others defined in the same
or an inherited schema.
my-app/schemas/books.sd:
schemabooks{documentbooks{field title typestring{indexing:summary|index}field author typestring{indexing:summary|index}}document-summaryitems_summary_tiny{summary title {}}document-summaryitems_summary_fullinheritsitems_summary_tiny{summary author {}}}