|
17 | 17 | * under the License. |
18 | 18 | */ |
19 | 19 |
|
20 | | -import { Dictionary, SingleKeyDictionary } from '@spec_utils/Dictionary' |
21 | | -import { UserDefinedValue } from '@spec_utils/UserDefinedValue' |
22 | 20 | import { Field, Fields } from '@_types/common' |
23 | 21 | import { integer } from '@_types/Numeric' |
24 | 22 | import { QueryContainer } from '@_types/query_dsl/abstractions' |
| 23 | +import { Dictionary, SingleKeyDictionary } from '@spec_utils/Dictionary' |
| 24 | +import { UserDefinedValue } from '@spec_utils/UserDefinedValue' |
25 | 25 |
|
26 | 26 | export enum BoundaryScanner { |
27 | | - /** |
28 | | - * Use the characters specified by `boundary_chars` as highlighting boundaries. |
29 | | - * The `boundary_max_scan` setting controls how far to scan for boundary characters. |
30 | | - * Only valid for the `fvh` highlighter. |
31 | | - */ |
32 | | - chars, |
33 | | - /** |
34 | | - * Break highlighted fragments at the next sentence boundary, as determined by Java’s `BreakIterator`. |
35 | | - * You can specify the locale to use with `boundary_scanner_locale`. |
36 | | - * When used with the `unified` highlighter, the `sentence` scanner splits sentences bigger than `fragment_size` at the first word boundary next to fragment_size. |
37 | | - * You can set `fragment_size` to `0` to never split any sentence. |
38 | | - */ |
39 | | - sentence, |
40 | | - /** |
41 | | - * Break highlighted fragments at the next word boundary, as determined by Java’s `BreakIterator`. |
42 | | - * You can specify the locale to use with `boundary_scanner_locale`. |
43 | | - */ |
44 | | - word |
| 27 | + /** |
| 28 | + * Use the characters specified by `boundary_chars` as highlighting boundaries. |
| 29 | + * The `boundary_max_scan` setting controls how far to scan for boundary characters. |
| 30 | + * Only valid for the `fvh` highlighter. |
| 31 | + */ |
| 32 | + chars, |
| 33 | + /** |
| 34 | + * Break highlighted fragments at the next sentence boundary, as determined by Java’s `BreakIterator`. |
| 35 | + * You can specify the locale to use with `boundary_scanner_locale`. |
| 36 | + * When used with the `unified` highlighter, the `sentence` scanner splits sentences bigger than `fragment_size` at the first word boundary next to fragment_size. |
| 37 | + * You can set `fragment_size` to `0` to never split any sentence. |
| 38 | + */ |
| 39 | + sentence, |
| 40 | + /** |
| 41 | + * Break highlighted fragments at the next word boundary, as determined by Java’s `BreakIterator`. |
| 42 | + * You can specify the locale to use with `boundary_scanner_locale`. |
| 43 | + */ |
| 44 | + word |
45 | 45 | } |
46 | 46 |
|
47 | 47 | export class HighlightBase { |
48 | | - type?: HighlighterType |
49 | | - /** |
50 | | - * A string that contains each boundary character. |
51 | | - * @server_default .,!? \t\n |
52 | | - */ |
53 | | - boundary_chars?: string |
54 | | - /** |
55 | | - * How far to scan for boundary characters. |
56 | | - * @server_default 20 |
57 | | - */ |
58 | | - boundary_max_scan?: integer |
59 | | - /** |
60 | | - * Specifies how to break the highlighted fragments: chars, sentence, or word. |
61 | | - * Only valid for the unified and fvh highlighters. |
62 | | - * Defaults to `sentence` for the `unified` highlighter. Defaults to `chars` for the `fvh` highlighter. |
63 | | - */ |
64 | | - boundary_scanner?: BoundaryScanner |
65 | | - /** |
66 | | - * Controls which locale is used to search for sentence and word boundaries. |
67 | | - * This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. |
68 | | - * @server_default Locale.ROOT |
69 | | - */ |
70 | | - boundary_scanner_locale?: string |
71 | | - /** |
72 | | - * @deprecated 8.8.0 |
73 | | - */ |
74 | | - force_source?: boolean |
75 | | - /** |
76 | | - * Specifies how text should be broken up in highlight snippets: `simple` or `span`. |
77 | | - * Only valid for the `plain` highlighter. |
78 | | - * @server_default span |
79 | | - */ |
80 | | - fragmenter?: HighlighterFragmenter |
81 | | - /** |
82 | | - * The size of the highlighted fragment in characters. |
83 | | - * @server_default 100 |
84 | | - */ |
85 | | - fragment_size?: integer |
86 | | - highlight_filter?: boolean |
87 | | - /** |
88 | | - * Highlight matches for a query other than the search query. |
89 | | - * This is especially useful if you use a rescore query because those are not taken into account by highlighting by default. |
90 | | - */ |
91 | | - highlight_query?: QueryContainer |
92 | | - max_fragment_length?: integer |
93 | | - /** |
94 | | - * If set to a non-negative value, highlighting stops at this defined maximum limit. |
95 | | - * The rest of the text is not processed, thus not highlighted and no error is returned |
96 | | - * The `max_analyzed_offset` query setting does not override the `index.highlight.max_analyzed_offset` setting, which prevails when it’s set to lower value than the query setting. |
97 | | - */ |
98 | | - max_analyzed_offset?: integer |
99 | | - /** |
100 | | - * The amount of text you want to return from the beginning of the field if there are no matching fragments to highlight. |
101 | | - * @server_default 0 |
102 | | - */ |
103 | | - no_match_size?: integer |
104 | | - /** |
105 | | - * The maximum number of fragments to return. |
106 | | - * If the number of fragments is set to `0`, no fragments are returned. |
107 | | - * Instead, the entire field contents are highlighted and returned. |
108 | | - * This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. |
109 | | - * If `number_of_fragments` is `0`, `fragment_size` is ignored. |
110 | | - * @server_default 5 |
111 | | - */ |
112 | | - number_of_fragments?: integer |
113 | | - options?: Dictionary<string, UserDefinedValue> |
114 | | - /** |
115 | | - * Sorts highlighted fragments by score when set to `score`. |
116 | | - * By default, fragments will be output in the order they appear in the field (order: `none`). |
117 | | - * Setting this option to `score` will output the most relevant fragments first. |
118 | | - * Each highlighter applies its own logic to compute relevancy scores. |
119 | | - * @server_default none |
120 | | - */ |
121 | | - order?: HighlighterOrder |
122 | | - /** |
123 | | - * Controls the number of matching phrases in a document that are considered. |
124 | | - * Prevents the `fvh` highlighter from analyzing too many phrases and consuming too much memory. |
125 | | - * When using `matched_fields`, `phrase_limit` phrases per matched field are considered. Raising the limit increases query time and consumes more memory. |
126 | | - * Only supported by the `fvh` highlighter. |
127 | | - * @server_default 256 |
128 | | - */ |
129 | | - phrase_limit?: integer |
130 | | - /** |
131 | | - * Use in conjunction with `pre_tags` to define the HTML tags to use for the highlighted text. |
132 | | - * By default, highlighted text is wrapped in `<em>` and `</em>` tags. |
133 | | - */ |
134 | | - post_tags?: string[] |
135 | | - /** |
136 | | - * Use in conjunction with `post_tags` to define the HTML tags to use for the highlighted text. |
137 | | - * By default, highlighted text is wrapped in `<em>` and `</em>` tags. |
138 | | - */ |
139 | | - pre_tags?: string[] |
140 | | - /** |
141 | | - * By default, only fields that contains a query match are highlighted. |
142 | | - * Set to `false` to highlight all fields. |
143 | | - * @server_default true |
144 | | - */ |
145 | | - require_field_match?: boolean |
146 | | - /** |
147 | | - * Set to `styled` to use the built-in tag schema. |
148 | | - */ |
149 | | - tags_schema?: HighlighterTagsSchema |
| 48 | + type?: HighlighterType |
| 49 | + /** |
| 50 | + * A string that contains each boundary character. |
| 51 | + * @server_default .,!? \t\n |
| 52 | + */ |
| 53 | + boundary_chars?: string |
| 54 | + /** |
| 55 | + * How far to scan for boundary characters. |
| 56 | + * @server_default 20 |
| 57 | + */ |
| 58 | + boundary_max_scan?: integer |
| 59 | + /** |
| 60 | + * Specifies how to break the highlighted fragments: chars, sentence, or word. |
| 61 | + * Only valid for the unified and fvh highlighters. |
| 62 | + * Defaults to `sentence` for the `unified` highlighter. Defaults to `chars` for the `fvh` highlighter. |
| 63 | + */ |
| 64 | + boundary_scanner?: BoundaryScanner |
| 65 | + /** |
| 66 | + * Controls which locale is used to search for sentence and word boundaries. |
| 67 | + * This parameter takes a form of a language tag, for example: `"en-US"`, `"fr-FR"`, `"ja-JP"`. |
| 68 | + * @server_default Locale.ROOT |
| 69 | + */ |
| 70 | + boundary_scanner_locale?: string |
| 71 | + /** |
| 72 | + * @deprecated 8.8.0 |
| 73 | + */ |
| 74 | + force_source?: boolean |
| 75 | + /** |
| 76 | + * Specifies how text should be broken up in highlight snippets: `simple` or `span`. |
| 77 | + * Only valid for the `plain` highlighter. |
| 78 | + * @server_default span |
| 79 | + */ |
| 80 | + fragmenter?: HighlighterFragmenter |
| 81 | + /** |
| 82 | + * The size of the highlighted fragment in characters. |
| 83 | + * @server_default 100 |
| 84 | + */ |
| 85 | + fragment_size?: integer |
| 86 | + highlight_filter?: boolean |
| 87 | + /** |
| 88 | + * Highlight matches for a query other than the search query. |
| 89 | + * This is especially useful if you use a rescore query because those are not taken into account by highlighting by default. |
| 90 | + */ |
| 91 | + highlight_query?: QueryContainer |
| 92 | + max_fragment_length?: integer |
| 93 | + /** |
| 94 | + * If set to a non-negative value, highlighting stops at this defined maximum limit. |
| 95 | + * The rest of the text is not processed, thus not highlighted and no error is returned |
| 96 | + * The `max_analyzed_offset` query setting does not override the `index.highlight.max_analyzed_offset` setting, which prevails when it’s set to lower value than the query setting. |
| 97 | + */ |
| 98 | + max_analyzed_offset?: integer |
| 99 | + /** |
| 100 | + * The amount of text you want to return from the beginning of the field if there are no matching fragments to highlight. |
| 101 | + * @server_default 0 |
| 102 | + */ |
| 103 | + no_match_size?: integer |
| 104 | + /** |
| 105 | + * The maximum number of fragments to return. |
| 106 | + * If the number of fragments is set to `0`, no fragments are returned. |
| 107 | + * Instead, the entire field contents are highlighted and returned. |
| 108 | + * This can be handy when you need to highlight short texts such as a title or address, but fragmentation is not required. |
| 109 | + * If `number_of_fragments` is `0`, `fragment_size` is ignored. |
| 110 | + * @server_default 5 |
| 111 | + */ |
| 112 | + number_of_fragments?: integer |
| 113 | + options?: Dictionary<string, UserDefinedValue> |
| 114 | + /** |
| 115 | + * Sorts highlighted fragments by score when set to `score`. |
| 116 | + * By default, fragments will be output in the order they appear in the field (order: `none`). |
| 117 | + * Setting this option to `score` will output the most relevant fragments first. |
| 118 | + * Each highlighter applies its own logic to compute relevancy scores. |
| 119 | + * @server_default none |
| 120 | + */ |
| 121 | + order?: HighlighterOrder |
| 122 | + /** |
| 123 | + * Controls the number of matching phrases in a document that are considered. |
| 124 | + * Prevents the `fvh` highlighter from analyzing too many phrases and consuming too much memory. |
| 125 | + * When using `matched_fields`, `phrase_limit` phrases per matched field are considered. Raising the limit increases query time and consumes more memory. |
| 126 | + * Only supported by the `fvh` highlighter. |
| 127 | + * @server_default 256 |
| 128 | + */ |
| 129 | + phrase_limit?: integer |
| 130 | + /** |
| 131 | + * Use in conjunction with `pre_tags` to define the HTML tags to use for the highlighted text. |
| 132 | + * By default, highlighted text is wrapped in `<em>` and `</em>` tags. |
| 133 | + */ |
| 134 | + post_tags?: string[] |
| 135 | + /** |
| 136 | + * Use in conjunction with `post_tags` to define the HTML tags to use for the highlighted text. |
| 137 | + * By default, highlighted text is wrapped in `<em>` and `</em>` tags. |
| 138 | + */ |
| 139 | + pre_tags?: string[] |
| 140 | + /** |
| 141 | + * By default, only fields that contains a query match are highlighted. |
| 142 | + * Set to `false` to highlight all fields. |
| 143 | + * @server_default true |
| 144 | + */ |
| 145 | + require_field_match?: boolean |
| 146 | + /** |
| 147 | + * Set to `styled` to use the built-in tag schema. |
| 148 | + */ |
| 149 | + tags_schema?: HighlighterTagsSchema |
150 | 150 | } |
151 | 151 |
|
152 | 152 | export class Highlight extends HighlightBase { |
153 | | - encoder?: HighlighterEncoder |
154 | | - fields: |
155 | | - | SingleKeyDictionary<Field, HighlightField> |
156 | | - | SingleKeyDictionary<Field, HighlightField>[] |
| 153 | + encoder?: HighlighterEncoder |
| 154 | + fields: |
| 155 | + | SingleKeyDictionary<Field, HighlightField> |
| 156 | + | SingleKeyDictionary<Field, HighlightField>[] |
157 | 157 | } |
158 | 158 |
|
159 | 159 | export enum HighlighterEncoder { |
160 | | - default, |
161 | | - html |
| 160 | + default, |
| 161 | + html |
162 | 162 | } |
163 | 163 |
|
164 | 164 | export enum HighlighterFragmenter { |
165 | | - simple, |
166 | | - span |
| 165 | + simple, |
| 166 | + span |
167 | 167 | } |
168 | 168 |
|
169 | 169 | export enum HighlighterOrder { |
170 | | - score |
| 170 | + score |
171 | 171 | } |
172 | 172 |
|
173 | 173 | export enum HighlighterTagsSchema { |
174 | | - styled |
| 174 | + styled |
175 | 175 | } |
176 | 176 |
|
177 | 177 | /** @non_exhaustive */ |
178 | 178 | export enum HighlighterType { |
179 | | - /** |
180 | | - * The `plain` highlighter uses the standard Lucene highlighter |
181 | | - */ |
182 | | - plain, |
183 | | - /** |
184 | | - * The fvh highlighter uses the Lucene Fast Vector highlighter. |
185 | | - * @codegen_name fast_vector |
186 | | - */ |
187 | | - fvh, |
188 | | - /** |
189 | | - * The unified highlighter uses the Lucene Unified Highlighter. |
190 | | - */ |
191 | | - unified |
| 179 | + /** |
| 180 | + * The `plain` highlighter uses the standard Lucene highlighter |
| 181 | + */ |
| 182 | + plain, |
| 183 | + /** |
| 184 | + * The fvh highlighter uses the Lucene Fast Vector highlighter. |
| 185 | + * @codegen_name fast_vector |
| 186 | + */ |
| 187 | + fvh, |
| 188 | + /** |
| 189 | + * The unified highlighter uses the Lucene Unified Highlighter. |
| 190 | + */ |
| 191 | + unified |
192 | 192 | } |
193 | 193 |
|
194 | 194 | export class HighlightField extends HighlightBase { |
195 | | - fragment_offset?: integer |
196 | | - matched_fields?: Fields |
| 195 | + fragment_offset?: integer |
| 196 | + matched_fields?: Fields |
197 | 197 | } |
0 commit comments