diff --git a/.changeset/search-rank-and-file.md b/.changeset/search-rank-and-file.md new file mode 100644 index 0000000000..bfad6a63ad --- /dev/null +++ b/.changeset/search-rank-and-file.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search-common': patch +--- + +Added an optional `rank` attribute to the `Result` type. This represents the result rank (starting at 1) for a given result in a result set for a given search. diff --git a/plugins/search-common/api-report.md b/plugins/search-common/api-report.md index bb049742f7..ea9fc2d26e 100644 --- a/plugins/search-common/api-report.md +++ b/plugins/search-common/api-report.md @@ -52,11 +52,9 @@ export type QueryTranslator = (query: SearchQuery) => unknown; // @public (undocumented) export interface Result { - // (undocumented) document: TDocument; - // (undocumented) highlight?: ResultHighlight; - // (undocumented) + rank?: number; type: string; } diff --git a/plugins/search-common/src/types.ts b/plugins/search-common/src/types.ts index fdcc06287c..4b4c25d423 100644 --- a/plugins/search-common/src/types.ts +++ b/plugins/search-common/src/types.ts @@ -56,9 +56,27 @@ export interface ResultHighlight { * @public */ export interface Result { + /** + * The "type" of the given document. See: {@link DocumentCollatorFactory."type"} + */ type: string; + + /** + * The raw value of the document, as indexed. + */ document: TDocument; + + /** + * Optional result highlight. Useful for improving the search result + * display/experience. + */ highlight?: ResultHighlight; + + /** + * Optional result rank, where 1 is the first/top result returned. Useful for + * understanding search effectiveness in analytics. + */ + rank?: number; } /**