Skip to content

Commit 9d3604e

Browse files
committed
feat: add typings mainly for nicer vscode assistance
1 parent 3b034f9 commit 9d3604e

1 file changed

Lines changed: 356 additions & 0 deletions

File tree

src/index.d.ts

Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
import { AxiosError } from "axios"
2+
import { ClientRequest } from "http"
3+
4+
// TODO: similarity https://lucene.apache.org/solr/guide/7_5/other-schema-elements.html#similarity
5+
// TODO: unique key https://lucene.apache.org/solr/guide/7_5/other-schema-elements.html#unique-key
6+
// TODO: dynamic fields https://lucene.apache.org/solr/guide/7_5/dynamic-fields.html
7+
// TODO: copying fields https://lucene.apache.org/solr/guide/7_5/copying-fields.html
8+
9+
/**
10+
* @file
11+
* @see https://lucene.apache.org/solr/guide/7_5/v2-api.html
12+
*/
13+
14+
/**
15+
* Field types that are available in Solr (except deprecated fields).
16+
* @see https://lucene.apache.org/solr/guide/7_5/field-types-included-with-solr.html#field-types-included-with-solr
17+
*/
18+
export type FieldTypesIncludedInSolr =
19+
| "solr.BinaryField"
20+
| "solr.BoolField"
21+
| "solr.CollationField"
22+
| "solr.CurrencyFieldType"
23+
| "solr.DateRangeField"
24+
| "solr.DatePointField"
25+
| "solr.DoublePointField"
26+
| "solr.ExternalFileField"
27+
| "solr.EnumFieldType"
28+
| "solr.FloatPointField"
29+
| "solr.ICUCollationField"
30+
| "solr.IntPointField"
31+
| "solr.LatLonPointSpatialField"
32+
| "solr.LongPointField"
33+
| "solr.PointType"
34+
| "solr.PreAnalyzedField"
35+
| "solr.RandomSortField"
36+
| "solr.SpatialRecursivePrefixTreeFieldType"
37+
| "solr.StrField"
38+
| "solr.StrField"
39+
| "solr.TextField"
40+
| "solr.UUIDField"
41+
42+
/**
43+
* Field definitions must have a `name` and `class`.
44+
* @see https://lucene.apache.org/solr/guide/7_5/defining-fields.html#field-properties
45+
*/
46+
interface FieldGeneralProperties {
47+
/**
48+
* The name of the field. Field names should consist of alphanumeric or underscore characters
49+
* only and not start with a digit. This is not currently strictly enforced, but other field
50+
* names will not have first class support from all components and back compatibility is not
51+
* guaranteed. Names with both leading and trailing underscores (e.g., _version_) are reserved.
52+
* Every field must have a name.
53+
*/
54+
name: string
55+
56+
/**
57+
* The name of the fieldType for this field. This will be found in the name attribute on
58+
* the fieldType definition. Every field must have a type.
59+
*/
60+
type: string
61+
62+
/**
63+
* A default value that will be added automatically to any document that does not have a value
64+
* in this field when it is indexed. If this property is not specified, there is no default.
65+
*/
66+
default?: string
67+
}
68+
69+
/**
70+
*/
71+
interface FieldTypeGeneralProperties {
72+
/**
73+
* The name of the fieldType. This value gets used in field definitions,
74+
* in the "type" attribute. It is strongly recommended that names consist
75+
* of alphanumeric or underscore characters only and not start with a digit.
76+
* This is not currently strictly enforced.
77+
*/
78+
name: string
79+
80+
/**
81+
* The class name that gets used to store and index the data for this type.
82+
* Note that you may prefix included class names with "solr." and Solr will
83+
* automatically figure out which packages to search for the class - so
84+
* `solr.TextField` will work.
85+
*
86+
* If you are using a third-party class, you will probably need to have a fully
87+
* qualified class name. The fully qualified equivalent for `solr.TextField`
88+
* is `org.apache.solr.schema.TextField`.
89+
*/
90+
class: FieldTypesIncludedInSolr // | string
91+
92+
/**
93+
* For multivalued fields, specifies a distance between multiple values,
94+
* which prevents spurious phrase matches.
95+
*/
96+
positionIncrementGap?: number
97+
98+
/**
99+
* For text fields. If true, Solr automatically generates phrase queries
100+
* for adjacent terms. If false, terms must be enclosed in double-quotes
101+
* to be treated as phrases.
102+
*/
103+
autoGeneratePhraseQueries?: boolean
104+
105+
/**
106+
* Query used to combine scores of overlapping query terms (i.e., synonyms).
107+
* Consider a search for "blue tee" with query-time synonyms `tshirt,tee`.
108+
* - Use `as_same_term` (default) to blend terms, i.e., `SynonymQuery(tshirt,tee)`
109+
* where each term will be treated as equally important. The value `as_same_term`
110+
* is appropriate when terms are true synonyms (television, tv).
111+
* - Use `pick_best` to select the most significant synonym when scoring `Dismax(tee,tshirt)`.
112+
* - Use `as_distinct_terms` to bias scoring towards the most significant synonym (`pants OR slacks`).
113+
* - Use `pick_best` or `as_distinct_terms` when synonyms are expanding to hyponyms
114+
* (`q=jeans w/ jeans=>jeans,pants`) and you want exact to come before parent and
115+
* sibling concepts.
116+
* @see http://opensourceconnections.com/blog/2017/11/21/solr-synonyms-mea-culpa/
117+
*/
118+
synonymQueryStyle?: "as_same_term" | "pick_best" | "as_distinct_terms"
119+
120+
/**
121+
* For text fields,applicable when querying with
122+
* [`sow=false`](https://lucene.apache.org/solr/guide/7_5/the-standard-query-parser.html#standard-query-parser-parameters)
123+
* (which is the default for the sow parameter).
124+
* - Use `true`, the default, for field types with query analyzers including graph-aware filters,
125+
* e.g., [Synonym Graph Filter](https://lucene.apache.org/solr/guide/7_5/filter-descriptions.html#synonym-graph-filter)
126+
* and [Word Delimiter Graph Filter](https://lucene.apache.org/solr/guide/7_5/filter-descriptions.html#word-delimiter-graph-filter).
127+
* - Use `false` for field types with query analyzers including filters that
128+
* can match docs when some tokens are missing,
129+
* e.g., [Shingle Filter](https://lucene.apache.org/solr/guide/7_5/filter-descriptions.html#shingle-filter).
130+
*/
131+
enableGraphQueries?: boolean
132+
133+
/**
134+
* Defines a custom `DocValuesFormat` to use for fields of this type.
135+
* This requires that a schema-aware codec, such as the `SchemaCodecFactory`
136+
* has been configured in `solrconfig.xml`.
137+
*/
138+
docValuesFormat?: string
139+
140+
/**
141+
* Defines a custom `PostingsFormat` to use for fields of this type.
142+
* This requires that a schema-aware codec, such as the `SchemaCodecFactory`
143+
* has been configured in `solrconfig.xml`.
144+
*
145+
* **Note:**
146+
* Lucene index back-compatibility is only supported for the default codec.
147+
* If you choose to customize the `postingsFormat` or `docValuesFormat` in your
148+
* `schema.xml`, upgrading to a future version of Solr may require you to either
149+
* switch back to the default codec and optimize your index to rewrite it into
150+
* the default codec before upgrading, or re-build your entire index from scratch
151+
* after upgrading.
152+
*/
153+
postingsFormat?: string
154+
}
155+
156+
/**
157+
* Fields can have many of the same properties as field types.
158+
* @see https://lucene.apache.org/solr/guide/7_5/field-type-definitions-and-properties.html#field-default-properties
159+
*/
160+
interface FieldTypeDefaultProperties {
161+
/** If true, the value of the field can be used in queries to retrieve matching documents. */
162+
indexed?: boolean
163+
164+
/** If true, the actual value of the field can be retrieved by queries. */
165+
stored?: boolean
166+
167+
/**
168+
* If true, the value of the field will be put in a column-oriented
169+
* [DocValues](https://lucene.apache.org/solr/guide/7_5/docvalues.html#docvalues) structure.
170+
*/
171+
docValues?: boolean
172+
173+
/** Control the placement of documents when a sort field is not present. */
174+
sortMissingFirst?: boolean
175+
176+
/** Control the placement of documents when a sort field is not present. */
177+
sortMissingLast?: boolean
178+
179+
/** If true, indicates that a single document might contain multiple values for this field type. */
180+
multiValued?: boolean
181+
182+
/**
183+
* If true, omits the norms associated with this field (this disables length normalization
184+
* for the field, and saves some memory). **Defaults to true for all primitive (non-analyzed)
185+
* field types, such as int, float, data, bool, and string.** Only full-text fields or fields need norms.
186+
*/
187+
omitNorms?: boolean
188+
189+
/**
190+
* If true, omits term frequency, positions, and payloads from postings for this field.
191+
* This can be a performance boost for fields that don’t require that information.
192+
* It also reduces the storage space required for the index. Queries that rely on position
193+
* that are issued on a field with this option will silently fail to find documents.
194+
* **This property defaults to true for all field types that are not text fields.**
195+
*/
196+
omitTermFreqAndPositions?: boolean
197+
198+
/**
199+
* Similar to `omitTermFreqAndPositions` but preserves term frequency information.
200+
*/
201+
omitPositions?: boolean
202+
203+
/**
204+
* These options instruct Solr to maintain full term vectors for each document,
205+
* optionally including position, offset and payload information for each term
206+
* occurrence in those vectors. These can be used to accelerate highlighting and
207+
* other ancillary functionality, but impose a substantial cost in terms of index size.
208+
* They are not necessary for typical uses of Solr.
209+
*/
210+
termVectors?: boolean
211+
termPositions?: boolean
212+
termOffsets?: boolean
213+
termPayloads?: boolean
214+
215+
/**
216+
* Instructs Solr to reject any attempts to add a document which does not have a value
217+
* for this field. This property defaults to false.
218+
*/
219+
required?: boolean
220+
221+
/**
222+
* If the field has docValues enabled, setting this to true would allow the field
223+
* to be returned as if it were a stored field (even if it has `stored=false`) when
224+
* matching `“*”` in an fl parameter.
225+
*/
226+
useDocValuesAsStored?: boolean
227+
228+
/**
229+
* Large fields are always lazy loaded and will only take up space in the document
230+
* cache if the actual value is < 512KB. This option requires `stored="true"` and
231+
* `multiValued="false"`. It’s intended for fields that might have very large values
232+
* so that they don’t get cached in memory.
233+
*/
234+
large?: boolean
235+
}
236+
237+
/**
238+
* Fields are defined in the fields element of `schema.xml`.
239+
* Once you have the **field types** set up, defining the fields themselves is simple.
240+
*
241+
* @see https://lucene.apache.org/solr/guide/7_5/defining-fields.html
242+
* @see https://lucene.apache.org/solr/guide/7_5/defining-fields.html#optional-field-type-override-properties
243+
*/
244+
export type FieldProperties = FieldGeneralProperties &
245+
FieldTypeDefaultProperties
246+
247+
/**
248+
* A field type defines the analysis that will occur on a field when documents are indexed
249+
* or queries are sent to the index.
250+
* A field type definition can include four types of information:
251+
* - The `name` of the field type (**mandatory**).
252+
* - An implementation `class` name (**mandatory**).
253+
* - If the field type is `TextField`, a description of the field analysis for the field type.
254+
* - Field type properties - depending on the implementation class,
255+
* some properties **may be mandatory**.
256+
*
257+
* The field type `class` determines most of the behavior of a field type, but optional properties
258+
* can also be defined.
259+
*
260+
* The properties that can be specified for a given field type fall into three major categories:
261+
* - Properties specific to the field type’s class.
262+
* - General Properties {@link FieldTypeGeneralProperties} that Solr supports for any field type.
263+
* - Field Default Properties {@link FieldTypeDefaultProperties} that can be specified on the field
264+
* type that will be inherited by fields that use this type instead of the default behavior.
265+
*/
266+
export type FieldTypeProperties = FieldTypeGeneralProperties &
267+
FieldTypeDefaultProperties
268+
269+
type SolrFragmentWithId = {
270+
id: string
271+
[key: string]: string | string[]
272+
}
273+
274+
type SolrDataValue =
275+
| string
276+
| string[]
277+
| SolrFragmentWithId
278+
| SolrFragmentWithId[]
279+
280+
export interface SolrData {
281+
[key: string]: SolrDataValue
282+
}
283+
284+
export interface SolrDocument {
285+
id: string
286+
_childDocuments_?: SolrFragmentWithId | SolrFragmentWithId[]
287+
[key: string]: SolrDataValue | SolrData
288+
}
289+
290+
/**
291+
* This type definition contains just the most important parts.
292+
*/
293+
interface SolrResponseHeader {
294+
params?: object
295+
status: number
296+
QTime: number
297+
}
298+
299+
/**
300+
* This type definition contains just the most important parts.
301+
*/
302+
export interface SolrResponse {
303+
status?: string
304+
response?: {
305+
docs: SolrDocument[]
306+
numFound: number
307+
start: number
308+
}
309+
responseHeader: SolrResponseHeader
310+
}
311+
312+
/**
313+
* This type definition contains just the most important parts.
314+
*/
315+
export interface SolrException {
316+
config
317+
message: string
318+
request: ClientRequest
319+
response: {
320+
config
321+
data: {
322+
error: {
323+
code: number
324+
details: {
325+
errorMessages: string[]
326+
[key: string]: object
327+
}[]
328+
metadata: string[]
329+
}
330+
responseHeader: SolrResponseHeader
331+
}
332+
headers
333+
request: ClientRequest
334+
status: number
335+
statusText: string
336+
}
337+
stack: string
338+
}
339+
340+
export interface SolrSelect {
341+
q: string
342+
fl?: string
343+
fq?: string[]
344+
start?: number
345+
sort?: string
346+
rows?: number
347+
hl?: "on" | "off"
348+
"hl.simple.pre"?: string
349+
"hl.simple.post"?: string
350+
"hl.fl"?: string
351+
debugQuery?: "on" | "off"
352+
indent?: "off" | "on"
353+
wt?: "json" | "xml" | "python" | "ruby" | "php" | "csv"
354+
"json.facet"?: object
355+
facet?:"on" | "off"
356+
}

0 commit comments

Comments
 (0)