/
xapian_d_header.d
542 lines (460 loc) · 17.3 KB
/
xapian_d_header.d
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
/**
обвязка к xapin
Copyright: © 2014 Semantic Machines
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Authors: Valeriy Bushenev
*/
module veda.bind.xapian_d_header;
/// Enum of stem strategy
enum stem_strategy { STEM_NONE, STEM_SOME, STEM_ALL, STEM_ALL_Z };
/// Enum of possible query operations
enum xapian_op
{
/// Return iff both subqueries are satisfied
OP_AND,
/// Return if either subquery is satisfied
OP_OR,
/// Return if left but not right satisfied
OP_AND_NOT,
/// Return if one query satisfied, but not both
OP_XOR,
/// Return iff left satisfied, but use weights from both
OP_AND_MAYBE,
/// As AND, but use only weights from left subquery
OP_FILTER,
/** 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.
*/
OP_NEAR,
/** 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.
*/
OP_PHRASE,
/** Filter by a range test on a document value. */
OP_VALUE_RANGE,
/** 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.
*/
OP_SCALE_WEIGHT,
/** 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.
*/
OP_ELITE_SET,
/** Filter by a greater-than-or-equal test on a document value. */
OP_VALUE_GE,
/** Filter by a less-than-or-equal test on a document value. */
OP_VALUE_LE,
/** 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.
*/
OP_SYNONYM
};
/// Enum of feature flag
enum feature_flag
{
/// 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 right truncation (e.g. Xap*).
*
* 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).
*
* NB: You need to tell the QueryParser object which database to
* expand wildcards from by calling set_database.
*/
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.
*
* NB: You need to tell the QueryParser object which database to
* expand wildcards from by calling set_database.
*/
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 | FLAG_AUTO_SYNONYMS,
/** 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.
*
* Added in Xapian 1.0.11.
*/
FLAG_DEFAULT = FLAG_PHRASE | FLAG_BOOLEAN | FLAG_LOVEHATE
};
//alias int size_t;
alias int int32_t;
alias byte int8_t;
alias ubyte uint8_t;
alias dchar TCHAR;
/** Open for read/write; create if no db exists. */
const int DB_CREATE_OR_OPEN = 1;
/** Create a new database; fail if db exists. */
const int DB_CREATE = 2;
/** Overwrite existing db; create if none exists. */
const int DB_CREATE_OR_OVERWRITE = 3;
/** Open for read/write; fail if no db exists. */
const int DB_OPEN = 4;
const int BRASS = 1;
const int CHERT = 2;
const int IN_MEMORY = 3;
extern (C++)
{
/// Base class for value range processors
interface XapianNumberValueRangeProcessor
{
}
interface XapianTermIterator
{
@nogc void reset(byte *err);
@nogc void next(byte *err);
@nogc bool is_next(byte *err);
@nogc void get_term(char **out_val, uint **out_val_length, byte *err);
}
/// Parses a piece of text and generate terms.
interface XapianTermGenerator
{
/// Set the XapianStem object to be used for generating stemmed terms.
@nogc void set_stemmer(XapianStem stemmer, byte *err);
/// -
@nogc void set_document(XapianDocument doc, byte *err);
/// -
@nogc void index_text(const char *data_str, ulong data_len, byte *err);
/// -
@nogc void index_text(const char *data_str, ulong data_len, const char *prefix_str, ulong prefix_len, byte *err);
/// -
@nogc void index_text_without_positions(const char *data_str, ulong data_len, byte *err);
/// -
@nogc void index_text_without_positions(const char *data_str, ulong data_len, const char *prefix_str, ulong prefix_len, byte *err);
/// -
@nogc void index_data(int data, const char *prefix_str, ulong prefix_len, byte *err);
/// -
@nogc void index_data(long data, const char *prefix_str, ulong prefix_len, byte *err);
/// -
@nogc void index_data(float data, const char *prefix_str, ulong prefix_len, byte *err);
/// -
@nogc void index_data(double data, const char *prefix_str, ulong prefix_len, byte *err);
}
/// This class is used to access a database, or a group of databases.
interface XapianDatabase
{
@nogc XapianEnquire new_Enquire(byte *err);
@nogc void close(byte *err);
@nogc void reopen(byte *err);
@nogc XapianTermIterator allterms(const char *prefix_str, ulong prefix_len, byte *err);
@nogc void add_database(XapianDatabase add_db, byte *err);
}
/// This class provides read/write access to a database
interface XapianWritableDatabase
{
@nogc XapianEnquire new_Enquire(byte *err);
@nogc uint add_document(XapianDocument doc, byte *err);
@nogc uint replace_document(const char *_unique_term, ulong _unique_term_len, XapianDocument document, byte *err);
@nogc void delete_document(const char *_unique_term, ulong _unique_term_len, byte *err);
@nogc void commit(byte *err);
@nogc void close(byte *err);
@nogc void reopen(byte *err);
}
/// Class representing a query
interface XapianQuery
{
@nogc void get_description(char **out_val, uint **out_val_length, byte *err);
@nogc void serialise(char **out_val, uint **out_val_length, byte *err);
@nogc XapianQuery add_right_query(int op_, XapianQuery _right, byte *err);
@nogc int get_length (byte *err);
}
/// A handle representing a document in a Xapian database
interface XapianDocument
{
@nogc char *get_data(char **out_val, uint **out_val_length, byte *err);
@nogc void set_data(const char *data_str, ulong data_len, byte *err);
@nogc void add_boolean_term(const char *_data, ulong _data_len, byte *err);
@nogc void add_value(int slot, const char *_data, ulong _data_len, byte *err);
@nogc void add_value(int slot, int _data, byte *err);
@nogc void add_value(int slot, long _data, byte *err);
@nogc void add_value(int slot, float _data, byte *err);
@nogc void add_value(int slot, double _data, byte *err);
}
/// An iterator pointing to items in an MSet
interface XapianMSetIterator
{
@nogc uint get_documentid(byte *err);
@nogc XapianDocument get_document(byte *err);
@nogc void get_document_data(char **out_val, uint **out_val_length, byte *err);
@nogc void next(byte *err);
@nogc bool is_next(byte *err);
}
/// A match set (MSet)
interface XapianMSet
{
@nogc int get_matches_estimated(byte *err);
@nogc int size(byte *err);
@nogc XapianMSetIterator iterator(byte *err);
}
/// This class provides an interface to the information retrieval system for the purpose of searching
interface XapianEnquire
{
@nogc void set_query(XapianQuery query, byte *err);
@nogc XapianMSet get_mset(int from, int size, byte *err);
@nogc void set_sort_by_key(XapianMultiValueKeyMaker sorter, bool p, byte *err);
@nogc void clear_matchspies();
}
/// Class representing a stemming algorithm
interface XapianStem
{
}
/// Build a XapianQuery object from a user query string
interface XapianQueryParser
{
@nogc void set_stemmer(XapianStem stemmer, byte *err);
@nogc void set_database(XapianDatabase db, byte *err);
@nogc void set_database(XapianWritableDatabase db, byte *err);
@nogc void set_stemming_strategy(stem_strategy strategy, byte *err);
@nogc XapianQuery parse_query(char *query_string, ulong query_string_len, byte *err);
@nogc XapianQuery parse_query(char *query_string, ulong query_string_len, uint flags, byte *err);
@nogc XapianQuery parse_query(char *query_string, ulong query_string_len, uint flags, char *prefix_string, ulong prefix_string_len,
byte *err);
@nogc void add_prefix(char *field_string, ulong field_string_len, char *prefix_string, ulong prefix_string_len, byte *err);
@nogc void add_valuerangeprocessor(XapianNumberValueRangeProcessor pp, byte *err);
@nogc void set_max_wildcard_expansion (int limit, byte *err);
}
/// KeyMaker subclass which combines several values
interface XapianMultiValueKeyMaker
{
@nogc void add_value(int pos, byte *err);
@nogc void add_value(int pos, bool asc_desc, byte *err);
}
/// -
@nogc XapianDatabase new_Database(byte *err);
/// -
@nogc XapianDatabase new_Database(const char *path, uint path_len, int db_type, byte *err);
/// -
@nogc XapianWritableDatabase new_WritableDatabase(const char *path, uint path_len, int action, int db_type, byte *err);
/// -
@nogc XapianDocument new_Document(byte *err);
/// -
@nogc XapianMultiValueKeyMaker new_MultiValueKeyMaker(byte *err);
/// -
@nogc XapianQueryParser new_QueryParser(byte *err);
/// -
@nogc XapianStem new_Stem(char *language, uint language_len, byte *err);
/// -
@nogc XapianTermGenerator new_TermGenerator(byte *err);
/// -
@nogc XapianNumberValueRangeProcessor new_NumberValueRangeProcessor(int slot, const char *_str, ulong _str_len, bool prefix, byte *err);
/// -
@nogc XapianQuery new_Query(byte *err);
/// -
@nogc XapianQuery new_Query(const char *_str, uint _str_len, byte *err);
// XapianQuery new_Query_add (XapianQuery _left, XapianQuery _right);//, int op_);
/// -
@nogc XapianQuery new_Query_range(int op_, int slot, double _begin, double _end, byte *err);
/// -
@nogc XapianQuery new_Query_double(int op_, int slot, double _value, byte *err);
/// -
@nogc XapianQuery new_Query_equal(int op_, int slot, const char *_str, ulong _str_len, byte *err);
/// -
@nogc void sortable_serialise(double value, char **out_val, uint **out_val_length, byte *err);
////////
/// -
@nogc void destroy_Document(XapianDocument doc);
/// -
@nogc void destroy_MSet(XapianMSet mset);
/// -
@nogc void destroy_MSetIterator(XapianMSetIterator msetit);
/// -
@nogc void destroy_Query(XapianQuery query);
/// -
@nogc void destroy_Enquire(XapianEnquire enquire);
/// -
@nogc void destroy_MultiValueKeyMaker(XapianMultiValueKeyMaker sorter);
/// -
@nogc void destroy_Database(XapianDatabase db);
}
class XapianError : Exception
{
byte code = 0;
this(byte _code, string msg, string file = __FILE__, size_t line = __LINE__, Throwable next = null)
{
super(msg, file, line, next);
code = _code;
}
string get_xapian_msg()
{
if (xapian_msg_code.length == 0)
init_err_code();
return xapian_msg_code.get(code, "Unknown");
}
}
string get_xapian_err_msg(byte code)
{
if (xapian_msg_code.length == 0)
init_err_code();
return xapian_msg_code.get(code, "Unknown");
}
private string[ byte ] xapian_msg_code;
private void init_err_code()
{
xapian_msg_code =
[
-1:"DatabaseModifiedError",
-2:"DatabaseLockError"
,
-3:"LogicError"
,
-4:"AssertionError"
,
-5:"InvalidArgumentError"
,
-6:"InvalidOperationError"
,
-7:"UnimplementedError"
,
-8:"RuntimeError"
,
-9:"DatabaseError"
,
-10:"DatabaseCorruptError"
,
-11:"DatabaseCreateError"
,
-12:"DatabaseOpeningError"
,
-13:"DatabaseVersionError"
,
-14:"DocNotFoundError"
,
-15:"FeatureUnavailableError"
,
-16:"InternalError"
,
-17:"NetworkError"
,
-18:"NetworkTimeoutError"
,
-19:"QueryParserError"
,
-20:"RangeError"
,
-21:"SerialisationError"
];
}