stork_lib/
output.rs

1use crate::Fields;
2use serde::{Deserialize, Serialize};
3
4/**
5 * The set of data needed to display search results to a user.
6 */
7#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
8pub struct Output {
9    pub results: Vec<Result>,
10    pub total_hit_count: usize,
11    pub url_prefix: String,
12}
13
14/**
15 * A single document in the list of matches for a search query,
16 * along with its display information and excerpts.
17 */
18#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
19pub struct Result {
20    pub entry: Entry,
21    pub excerpts: Vec<Excerpt>,
22    pub title_highlight_ranges: Vec<HighlightRange>,
23    pub score: usize,
24}
25
26/**
27 * A document present in the search results.
28 */
29#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
30pub struct Entry {
31    pub url: String,
32    pub title: String,
33    pub fields: Fields,
34}
35
36/**
37 * An excerpt of a document's contents, that contains words that
38 * were part of the search query.
39 */
40#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
41pub struct Excerpt {
42    pub text: String,
43    pub highlight_ranges: Vec<HighlightRange>,
44    pub score: usize,
45    pub internal_annotations: Vec<InternalWordAnnotation>,
46    pub fields: Fields,
47}
48
49/**
50 * An annotation attached to a given excerpt.
51 *
52 * This should not be displayed directly to users, but instead should
53 * change some aspect of how that excerpt is rendered.
54 */
55#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
56pub enum InternalWordAnnotation {
57    #[serde(rename = "a")]
58    UrlSuffix(String),
59}
60
61/**
62 * A range of characters in a string that should be highlighted.
63 * The start and end indices are inclusive.
64 */
65#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
66pub struct HighlightRange {
67    pub beginning: usize,
68    pub end: usize,
69}
70
71/**
72 * Contains metadata about an index, to be displayed to the user, often for debugging.
73 */
74#[derive(Serialize, Clone, Debug, PartialEq)]
75pub struct IndexMetadata {
76    #[serde(rename = "indexVersion")]
77    pub index_version: String,
78}