1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
use crate::Fields;
use serde::{Deserialize, Serialize};

/**
 * The set of data needed to display search results to a user.
 */
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
pub struct Output {
    pub results: Vec<Result>,
    pub total_hit_count: usize,
    pub url_prefix: String,
}

/**
 * A single document in the list of matches for a search query,
 * along with its display information and excerpts.
 */
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Result {
    pub entry: Entry,
    pub excerpts: Vec<Excerpt>,
    pub title_highlight_ranges: Vec<HighlightRange>,
    pub score: usize,
}

/**
 * A document present in the search results.
 */
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Entry {
    pub url: String,
    pub title: String,
    pub fields: Fields,
}

/**
 * An excerpt of a document's contents, that contains words that
 * were part of the search query.
 */
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Excerpt {
    pub text: String,
    pub highlight_ranges: Vec<HighlightRange>,
    pub score: usize,
    pub internal_annotations: Vec<InternalWordAnnotation>,
    pub fields: Fields,
}

/**
 * An annotation attached to a given excerpt.
 *
 * This should not be displayed directly to users, but instead should
 * change some aspect of how that excerpt is rendered.
 */
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub enum InternalWordAnnotation {
    #[serde(rename = "a")]
    UrlSuffix(String),
}

/**
 * A range of characters in a string that should be highlighted.
 * The start and end indices are inclusive.
 */
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct HighlightRange {
    pub beginning: usize,
    pub end: usize,
}

/**
 * Contains metadata about an index, to be displayed to the user, often for debugging.
 */
#[derive(Serialize, Clone, Debug, PartialEq)]
pub struct IndexMetadata {
    #[serde(rename = "indexVersion")]
    pub index_version: String,
}