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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515

/// WritableDatabase flags
pub const DB_BACKEND_GLASS: i32 = 0x100;

/// the chert backend, No longer supported as of Xapian 1.5.0
pub const DB_BACKEND_CHERT: i32 = 0x200;
/// Open a stub database file
pub const DB_BACKEND_STUB: i32 = 0x300;

/** Use the "in memory" backend.
*
*  The filename is currently ignored when this flag is used, but an empty
*  string should be passed to allow for future expansion.
*
*  A new empty database is created, so when creating a Database object this
*  creates an empty read-only database - sometimes useful to avoid special
*  casing this situation, but otherwise of limited use.  It's more useful
*  when creating a WritableDatabase object, though beware that the current
*  inmemory backend implementation was not built for performance and
*  scalability.
*
*  This provides an equivalent to Xapian::InMemory::open() in Xapian 1.2.
 */
pub const DB_BACKEND_INMEMORY: i32 = 0x400;

/** Use the honey backend.
*
*  When opening a WritableDatabase, this means create a honey database if a
*  new database is created.  If there's an existing database (of any type)
*  at the specified path, this flag has no effect.
*
*  When opening a Database, this flag means to only open it if it's a honey
*  database.  There's rarely a good reason to do this - it's mostly provided
*  as equivalent functionality to that provided by the namespaced open()
*  functions in Xapian 1.2.
 */
pub const DB_BACKEND_HONEY: i32 = 0x500;

/** Create database if it doesn't already exist.
*
*  If no opening mode is specified, this is the default.
 */
pub const DB_CREATE_OR_OPEN: i32 = 0x00;

/** Create database if it doesn't already exist, or overwrite if it does. */
pub const DB_CREATE_OR_OVERWRITE: i32 = 0x01;

/** Create a new database.
*
*  If the database already exists, an exception will be thrown.
 */
pub const DB_CREATE: i32 = 0x02;

/** Open an existing database.
*
*  If the database doesn't exist, an exception will be thrown.
 */
pub const DB_OPEN: i32 = 0x03;

/// Enum of possible query operations
/// #[repr(i32)]
pub enum XapianOp {
    /// Return iff both subqueries are satisfied
    OpAnd,

    /// Return if either subquery is satisfied
    OpOr,

    /// Return if left but not right satisfied
    OpAndNot,

    /// Return if one query satisfied, but not both
    OpXor,

    /// Return iff left satisfied, but use weights from both
    OpAndMaybe,

    /// As AND, but use only weights from left subquery
    OpFilter,

    /** Find occurrences of a list of terms with all the terms
        *  occurring within a specified window of positions.
        *
        *  Each occurrence of a term must be at a different position,
        *  but the order they appear in is irrelevant.
        *
        *  The window parameter should be specified for this operation,
        *  but will default to the number of terms in the list.
     */
    OpNear,

    /** Find occurrences of a list of terms with all the terms
        *  occurring within a specified window of positions, and all
        *  the terms appearing in the order specified.
        *
        *  Each occurrence of a term must be at a different position.
        *
        *  The window parameter should be specified for this operation,
        *  but will default to the number of terms in the list.
     */
    OpPhrase,

    /** Filter by a range test on a document value. */
    OpValueRange,

    /** Scale the weight of a subquery by the specified factor.
        *
        *  A factor of 0 means this subquery will contribute no weight to
        *  the query - it will act as a purely boolean subquery.
        *
        *  If the factor is negative, Xapian::InvalidArgumentError will
        *  be thrown.
     */
    OpScaleWeight,

    /** Pick the best N subqueries and combine with OP_OR.
        *
        *  If you want to implement a feature which finds documents
        *  similar to a piece of text, an obvious approach is to build an
        *  "OR" query from all the terms in the text, and run this query
        *  against a database containing the documents.  However such a
        *  query can contain a lots of terms and be quite slow to perform,
        *  yet many of these terms don't contribute usefully to the
        *  results.
        *
        *  The OP_ELITE_SET operator can be used instead of OP_OR in this
        *  situation.  OP_ELITE_SET selects the most important ''N'' terms
        *  and then acts as an OP_OR query with just these, ignoring any
        *  other terms.  This will usually return results just as good as
        *  the full OP_OR query, but much faster.
        *
        *  In general, the OP_ELITE_SET operator can be used when you have
        *  a large OR query, but it doesn't matter if the search
        *  completely ignores some of the less important terms in the
        *  query.
        *
        *  The subqueries don't have to be terms, but if they aren't then
        *  OP_ELITE_SET will look at the estimated frequencies of the
        *  subqueries and so could pick a subset which don't actually
        *  match any documents even if the full OR would match some.
        *
        *  You can specify a parameter to the query constructor which
        *  control the number of terms which OP_ELITE_SET will pick.  If
        *  not specified, this defaults to 10 (or
        *  <code>ceil(sqrt(number_of_subqueries))</code> if there are more
        *  than 100 subqueries, but this rather arbitrary special case
        *  will be dropped in 1.3.0).  For example, this will pick the
        *  best 7 terms:
        *
        *  <pre>
        *  Xapian::Query query(Xapian::Query::OP_ELITE_SET, subqs.begin(), subqs.end(), 7);
        *  </pre>
        *
        * If the number of subqueries is less than this threshold,
        * OP_ELITE_SET behaves identically to OP_OR.
     */
    OpEliteSet,

    /** Filter by a greater-than-or-equal test on a document value. */
    OpValueGe,

    /** Filter by a less-than-or-equal test on a document value. */
    OpValueLe,

    /** Treat a set of queries as synonyms.
        *
        *  This returns all results which match at least one of the
        *  queries, but weighting as if all the sub-queries are instances
        *  of the same term: so multiple matching terms for a document
        *  increase the wdf value used, and the term frequency is based on
        *  the number of documents which would match an OR of all the
        *  subqueries.
        *
        *  The term frequency used will usually be an approximation,
        *  because calculating the precise combined term frequency would
        *  be overly expensive.
        *
        *  Identical to OP_OR, except for the weightings returned.
     */
    OpSynonym,
}

/// Flags to OR together and pass to TermGenerator::set_flags().
#[allow(non_camel_case_types)]
#[repr(i32)]
pub enum TermGeneratorFlag {
    FLAG_DEFAULT = 0,
    /// Index data required for spelling correction.
    FLAG_SPELLING = 128, // Value matches QueryParser flag.

    /** Generate n-grams for scripts without explicit word breaks.
     *
     *  Spans of characters in such scripts are split into unigrams
     *  and bigrams, with the unigrams carrying positional information.
     *  Text in other scripts is split into words as normal.
     *
     *  The QueryParser::FLAG_NGRAMS flag needs to be passed to
     *  QueryParser.
     *
     *  This mode can also be enabled in 1.2.8 and later by setting
     *  environment variable XAPIAN_CJK_NGRAM to a non-empty value (but
     *  doing so was deprecated in 1.4.11).
     *
     *  In 1.4.x this feature was specific to CJK (Chinese, Japanese and
     *  Korean), but in 1.5.0 it's been extended to other languages.  To
     *  reflect this change the new and preferred name is FLAG_NGRAMS,
     *  which was added as an alias for forward compatibility in Xapian
     *  1.4.23.  Use FLAG_CJK_NGRAM instead if you aim to support Xapian
     *  &lt; 1.4.23.
     *
     *  @since Added in Xapian 1.4.23.
     */
    FLAG_NGRAMS = 2048, // Value matches QueryParser flag.

    /** Find word breaks for text in scripts without explicit word breaks.
     *
     *  With this option enabled, spans of text written in such scripts are
     *  split into words using ICU (which uses heuristics and/or
     *  dictionaries to do so).  Text in other scripts is split into words
     *  as normal.
     *
     *  The QueryParser::FLAG_WORD_BREAKS flag needs to be passed to
     *  QueryParser.
     *
     *  @since Added in Xapian 1.5.0.
     */
    FLAG_WORD_BREAKS = 4096 // Value matches QueryParser flag
}

/// QueryParser::feature_flag
#[allow(non_camel_case_types)]
#[repr(i32)]
#[derive(Debug)]
pub enum QueryParserFeatureFlag {
    /// Support AND, OR, etc and bracketed subexpressions.
    FLAG_BOOLEAN = 1,
    /// Support quoted phrases.
    FLAG_PHRASE = 2,
    /// Support + and -.
    FLAG_LOVEHATE = 4,
    /// Support AND, OR, etc even if they aren't in ALLCAPS.
    FLAG_BOOLEAN_ANY_CASE = 8,
    /** Support wildcards.
        *
        *  At present only right truncation (e.g. Xap*) is supported.
        *
        *  Currently you can't use wildcards with boolean filter prefixes,
        *  or in a phrase (either an explicitly quoted one, or one implicitly
        *  generated by hyphens or other punctuation).
        *
        *  In Xapian 1.2.x, you needed to tell the QueryParser object which
        *  database to expand wildcards from by calling set_database().  In
        *  Xapian 1.3.3, OP_WILDCARD was added and wildcards are now
        *  expanded when Enquire::get_mset() is called, with the expansion
        *  using the database being searched.
     */
    FLAG_WILDCARD = 16,
    /** Allow queries such as 'NOT apples'.
        *
        *  These require the use of a list of all documents in the database
        *  which is potentially expensive, so this feature isn't enabled by
        *  default.
     */
    FLAG_PURE_NOT = 32,
    /** Enable partial matching.
        *
        *  Partial matching causes the parser to treat the query as a
        *  "partially entered" search.  This will automatically treat the
        *  final word as a wildcarded match, unless it is followed by
        *  whitespace, to produce more stable results from interactive
        *  searches.
        *
        *  Currently FLAG_PARTIAL doesn't do anything if the final word
        *  in the query has a boolean filter prefix, or if it is in a phrase
        *  (either an explicitly quoted one, or one implicitly generated by
        *  hyphens or other punctuation).  It also doesn't do anything if
        *  if the final word is part of a value range.
        *
        *  In Xapian 1.2.x, you needed to tell the QueryParser object which
        *  database to expand wildcards from by calling set_database().  In
        *  Xapian 1.3.3, OP_WILDCARD was added and wildcards are now
        *  expanded when Enquire::get_mset() is called, with the expansion
        *  using the database being searched.
     */
    FLAG_PARTIAL = 64,

    /** Enable spelling correction.
        *
        *  For each word in the query which doesn't exist as a term in the
        *  database, Database::get_spelling_suggestion() will be called and if
        *  a suggestion is returned, a corrected version of the query string
        *  will be built up which can be read using
        *  QueryParser::get_corrected_query_string().  The query returned is
        *  based on the uncorrected query string however - if you want a
        *  parsed query based on the corrected query string, you must call
        *  QueryParser::parse_query() again.
        *
        *  NB: You must also call set_database() for this to work.
     */
    FLAG_SPELLING_CORRECTION = 128,

    /** Enable synonym operator '~'.
        *
        *  NB: You must also call set_database() for this to work.
     */
    FLAG_SYNONYM = 256,

    /** Enable automatic use of synonyms for single terms.
        *
        *  NB: You must also call set_database() for this to work.
     */
    FLAG_AUTO_SYNONYMS = 512,

    /** Enable automatic use of synonyms for single terms and groups of
        *  terms.
        *
        *  NB: You must also call set_database() for this to work.
     */
    FLAG_AUTO_MULTIWORD_SYNONYMS = 1024,

    /** Generate n-grams for scripts without explicit word breaks.
     *
     *  Spans of characters in such scripts are split into unigrams
     *  and bigrams, with the unigrams carrying positional information.
     *  Text in other scripts is split into words as normal.
     *
     *  The TermGenerator::FLAG_NGRAMS flag needs to have been used at
     *  index time.
     *
     *  This mode can also be enabled in 1.2.8 and later by setting
     *  environment variable XAPIAN_CJK_NGRAM to a non-empty value (but
     *  doing so was deprecated in 1.4.11).
     *
     *  In 1.4.x this feature was specific to CJK (Chinese, Japanese and
     *  Korean), but in 1.5.0 it's been extended to other languages.  To
     *  reflect this change the new and preferred name is FLAG_NGRAMS,
     *  which was added as an alias for forward compatibility in Xapian
     *  1.4.23.  Use FLAG_CJK_NGRAM instead if you aim to support Xapian
     *  &lt; 1.4.23.
     *
     *  @since Added in Xapian 1.4.23.
     */
    FLAG_NGRAMS = 2048,

    /** Find word breaks for text in scripts without explicit word breaks.
     *
     *  With this option enabled, spans of text written in such scripts are
     *  split into words using ICU (which uses heuristics and/or
     *  dictionaries to do so).  Text in other scripts is split into words
     *  as normal.
     *
     *  The TermGenerator::FLAG_WORD_BREAKS flag needs to have been used at
     *  index time.
     *
     *  @since Added in Xapian 1.5.0.
     */
    FLAG_WORD_BREAKS = 4096,

    /** Support extended wildcard '*'.
     *
     *  This flag enables support for wildcard '*' matching zero
     *  or more characters, which may be used anywhere in a word.
     *
     *  Such wildcards can be relatively expensive to expand and to match
     *  so benchmark your system carefully if you have a lot of documents
     *  and/or a high search load.
     *
     *  FLAG_WILDCARD is ignored if this flag is specified.
     *
     *  @since Added in Xapian 1.5.0.
     */
    FLAG_WILDCARD_MULTI = 8192,

    /** Support extended wildcard '?'.
     *
     *  This flag enables support for wildcard '?' matching exactly one
     *  character, which may be use anywhere in a word.
     *
     *  Such wildcards can be relatively expensive to expand and to match
     *  so benchmark your system carefully if you have a lot of documents
     *  and/or a high search load.
     *
     *  FLAG_WILDCARD is ignored if this flag is specified.
     *
     *  @since Added in Xapian 1.5.0.
     */
    FLAG_WILDCARD_SINGLE = 16384,

    /** Enable glob-style wildcarding.
     *
     *  This enables all supported glob-style wildcard pattern flags
     *  - currently that's FLAG_WILDCARD_MULTI and FLAG_WILDCARD_SINGLE.
     *
     *  FLAG_WILDCARD is ignored if this flag is specified.
     *
     *  @since Added in Xapian 1.5.0.
     */
    FLAG_WILDCARD_GLOB = Self::FLAG_WILDCARD_MULTI as i32 | Self::FLAG_WILDCARD_SINGLE as i32,

    /** Support fuzzy matching.
     *
     *  E.g. "unserten~3" would expand to "uncertain" (and likely other
     *  terms).
     *
     *  foo~ uses edit distance of 2
     *  since~0.2 uses edit distance of length("since") * 0.2 = 5 * 0.2 = 1
     *
     *  @since Added in Xapian 1.5.0.
     */
    FLAG_FUZZY = 32768,

    /** Accumulate unstem and stoplist results.
     *
     *  By default, the unstem and stoplist data is reset by a call to
     *  parse_query(), which makes sense if you use the same QueryParser
     *  object to parse a series of independent queries.
     *
     *  If you're using the same QueryParser object to parse several
     *  fields on the same query form, you may want to have the unstem
     *  and stoplist data combined for all of them, in which case you
     *  can use this flag to prevent this data from being reset.
     *
     *  @since Added in Xapian 1.4.18.
     */
    FLAG_ACCUMULATE = 65536,

    /** Produce a query which doesn't use positional information.
     *
     *  With this flag enabled, no positional information will be used
     *  and any query operations which would use it are replaced by
     *  the nearest equivalent which doesn't (so phrase searches, NEAR
     *  and ADJ will result in OP_AND).
     *
     *  @since Added in Xapian 1.4.19.
     */
    FLAG_NO_POSITIONS = 0x20000,

    /** The default flags.
     *
     *  Used if you don't explicitly pass any to @a parse_query().
     *  The default flags are FLAG_PHRASE|FLAG_BOOLEAN|FLAG_LOVEHATE.
     *
     *  @since Added in Xapian 1.0.11.
     */
    FLAG_DEFAULT = Self::FLAG_PHRASE as i32 | Self::FLAG_BOOLEAN as i32 | Self::FLAG_LOVEHATE as i32,
}

/// Enum of possible query operations
#[allow(non_camel_case_types)]
/// #[repr(i32)]
pub enum RangeProcessorFlags {
    RP_PREFIX = 0,
    /// as a suffix
    RP_SUFFIX = 1,
    /// optionally allow str_ on both ends of the range - e.g. $1..$10 or 5m..50m.
    RP_REPEATED = 2,
    RP_DATE_PREFER_MDY = 4,
}

#[allow(non_camel_case_types)]
#[repr(i32)]
#[derive(Debug)]
pub enum SnippetFlags {
    /** Model the relevancy of non-query terms in MSet::snippet().
        *
        *  Non-query terms will be assigned a small weight, and the snippet
        *  will tend to prefer snippets which contain a more interesting
        *  background (where the query term content is equivalent).
     */
    SNIPPET_BACKGROUND_MODEL = 1,
    /** Exhaustively evaluate candidate snippets in MSet::snippet().
        *
        *  Without this flag, snippet generation will stop once it thinks
        *  it has found a "good enough" snippet, which will generally reduce
        *  the time taken to generate a snippet.
     */
    SNIPPET_EXHAUSTIVE = 2,
    /** Return the empty string if no term got matched.
        *
        *  If enabled, snippet() returns an empty string if not a single match
        *  was found in text. If not enabled, snippet() returns a (sub)string
        *  of text without any highlighted terms.
     */
    SNIPPET_EMPTY_WITHOUT_MATCH = 4,

    /** Enable generation of n-grams from CJK text.
        *
        *  This option highlights CJK searches made using the QueryParser
        *  FLAG_CJK_NGRAM flag.  Non-CJK characters are split into words as
        *  normal.
        *
        *  The TermGenerator FLAG_CJK_NGRAM flag needs to have been used at
        *  index time.
        *
        *  This mode can also be enabled by setting environment variable
        *  XAPIAN_CJK_NGRAM to a non-empty value (but doing so was deprecated
        *  in 1.4.11).
        *
        *  @since Added in Xapian 1.4.11.
     */
    SNIPPET_CJK_NGRAM = 2048,
}

// Enquire::docid_order
#[allow(non_camel_case_types)]
#[repr(i32)]
#[derive(Debug)]
pub enum EnquireDocidOrder {
    /** docids sort in ascending order (default) */
    ASCENDING = 1,
    /** docids sort in descending order. */
    DESCENDING = 0,
    /** docids sort in whatever order is most efficient for the backend. */
    DONT_CARE = 2
}