OLD | NEW |
| (Empty) |
1 /* | |
2 ** 2014 May 31 | |
3 ** | |
4 ** The author disclaims copyright to this source code. In place of | |
5 ** a legal notice, here is a blessing: | |
6 ** | |
7 ** May you do good and not evil. | |
8 ** May you find forgiveness for yourself and forgive others. | |
9 ** May you share freely, never taking more than you give. | |
10 ** | |
11 ****************************************************************************** | |
12 ** | |
13 */ | |
14 #ifndef _FTS5INT_H | |
15 #define _FTS5INT_H | |
16 | |
17 #include "fts5.h" | |
18 #include "sqlite3ext.h" | |
19 SQLITE_EXTENSION_INIT1 | |
20 | |
21 #include <string.h> | |
22 #include <assert.h> | |
23 | |
24 #ifndef SQLITE_AMALGAMATION | |
25 | |
26 typedef unsigned char u8; | |
27 typedef unsigned int u32; | |
28 typedef unsigned short u16; | |
29 typedef sqlite3_int64 i64; | |
30 typedef sqlite3_uint64 u64; | |
31 | |
32 #define ArraySize(x) (sizeof(x) / sizeof(x[0])) | |
33 | |
34 #define testcase(x) | |
35 #define ALWAYS(x) 1 | |
36 #define NEVER(x) 0 | |
37 | |
38 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) | |
39 #define MAX(x,y) (((x) > (y)) ? (x) : (y)) | |
40 | |
41 /* | |
42 ** Constants for the largest and smallest possible 64-bit signed integers. | |
43 */ | |
44 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32)) | |
45 # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64) | |
46 | |
47 #endif | |
48 | |
49 | |
50 /* | |
51 ** Maximum number of prefix indexes on single FTS5 table. This must be | |
52 ** less than 32. If it is set to anything large than that, an #error | |
53 ** directive in fts5_index.c will cause the build to fail. | |
54 */ | |
55 #define FTS5_MAX_PREFIX_INDEXES 31 | |
56 | |
57 #define FTS5_DEFAULT_NEARDIST 10 | |
58 #define FTS5_DEFAULT_RANK "bm25" | |
59 | |
60 /* Name of rank and rowid columns */ | |
61 #define FTS5_RANK_NAME "rank" | |
62 #define FTS5_ROWID_NAME "rowid" | |
63 | |
64 #ifdef SQLITE_DEBUG | |
65 # define FTS5_CORRUPT sqlite3Fts5Corrupt() | |
66 int sqlite3Fts5Corrupt(void); | |
67 #else | |
68 # define FTS5_CORRUPT SQLITE_CORRUPT_VTAB | |
69 #endif | |
70 | |
71 /* | |
72 ** The assert_nc() macro is similar to the assert() macro, except that it | |
73 ** is used for assert() conditions that are true only if it can be | |
74 ** guranteed that the database is not corrupt. | |
75 */ | |
76 #ifdef SQLITE_DEBUG | |
77 extern int sqlite3_fts5_may_be_corrupt; | |
78 # define assert_nc(x) assert(sqlite3_fts5_may_be_corrupt || (x)) | |
79 #else | |
80 # define assert_nc(x) assert(x) | |
81 #endif | |
82 | |
83 typedef struct Fts5Global Fts5Global; | |
84 typedef struct Fts5Colset Fts5Colset; | |
85 | |
86 /* If a NEAR() clump or phrase may only match a specific set of columns, | |
87 ** then an object of the following type is used to record the set of columns. | |
88 ** Each entry in the aiCol[] array is a column that may be matched. | |
89 ** | |
90 ** This object is used by fts5_expr.c and fts5_index.c. | |
91 */ | |
92 struct Fts5Colset { | |
93 int nCol; | |
94 int aiCol[1]; | |
95 }; | |
96 | |
97 | |
98 | |
99 /************************************************************************** | |
100 ** Interface to code in fts5_config.c. fts5_config.c contains contains code | |
101 ** to parse the arguments passed to the CREATE VIRTUAL TABLE statement. | |
102 */ | |
103 | |
104 typedef struct Fts5Config Fts5Config; | |
105 | |
106 /* | |
107 ** An instance of the following structure encodes all information that can | |
108 ** be gleaned from the CREATE VIRTUAL TABLE statement. | |
109 ** | |
110 ** And all information loaded from the %_config table. | |
111 ** | |
112 ** nAutomerge: | |
113 ** The minimum number of segments that an auto-merge operation should | |
114 ** attempt to merge together. A value of 1 sets the object to use the | |
115 ** compile time default. Zero disables auto-merge altogether. | |
116 ** | |
117 ** zContent: | |
118 ** | |
119 ** zContentRowid: | |
120 ** The value of the content_rowid= option, if one was specified. Or | |
121 ** the string "rowid" otherwise. This text is not quoted - if it is | |
122 ** used as part of an SQL statement it needs to be quoted appropriately. | |
123 ** | |
124 ** zContentExprlist: | |
125 ** | |
126 ** pzErrmsg: | |
127 ** This exists in order to allow the fts5_index.c module to return a | |
128 ** decent error message if it encounters a file-format version it does | |
129 ** not understand. | |
130 ** | |
131 ** bColumnsize: | |
132 ** True if the %_docsize table is created. | |
133 ** | |
134 ** bPrefixIndex: | |
135 ** This is only used for debugging. If set to false, any prefix indexes | |
136 ** are ignored. This value is configured using: | |
137 ** | |
138 ** INSERT INTO tbl(tbl, rank) VALUES('prefix-index', $bPrefixIndex); | |
139 ** | |
140 */ | |
141 struct Fts5Config { | |
142 sqlite3 *db; /* Database handle */ | |
143 char *zDb; /* Database holding FTS index (e.g. "main") */ | |
144 char *zName; /* Name of FTS index */ | |
145 int nCol; /* Number of columns */ | |
146 char **azCol; /* Column names */ | |
147 u8 *abUnindexed; /* True for unindexed columns */ | |
148 int nPrefix; /* Number of prefix indexes */ | |
149 int *aPrefix; /* Sizes in bytes of nPrefix prefix indexes */ | |
150 int eContent; /* An FTS5_CONTENT value */ | |
151 char *zContent; /* content table */ | |
152 char *zContentRowid; /* "content_rowid=" option value */ | |
153 int bColumnsize; /* "columnsize=" option value (dflt==1) */ | |
154 char *zContentExprlist; | |
155 Fts5Tokenizer *pTok; | |
156 fts5_tokenizer *pTokApi; | |
157 | |
158 /* Values loaded from the %_config table */ | |
159 int iCookie; /* Incremented when %_config is modified */ | |
160 int pgsz; /* Approximate page size used in %_data */ | |
161 int nAutomerge; /* 'automerge' setting */ | |
162 int nCrisisMerge; /* Maximum allowed segments per level */ | |
163 int nHashSize; /* Bytes of memory for in-memory hash */ | |
164 char *zRank; /* Name of rank function */ | |
165 char *zRankArgs; /* Arguments to rank function */ | |
166 | |
167 /* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */ | |
168 char **pzErrmsg; | |
169 | |
170 #ifdef SQLITE_DEBUG | |
171 int bPrefixIndex; /* True to use prefix-indexes */ | |
172 #endif | |
173 }; | |
174 | |
175 /* Current expected value of %_config table 'version' field */ | |
176 #define FTS5_CURRENT_VERSION 4 | |
177 | |
178 #define FTS5_CONTENT_NORMAL 0 | |
179 #define FTS5_CONTENT_NONE 1 | |
180 #define FTS5_CONTENT_EXTERNAL 2 | |
181 | |
182 | |
183 | |
184 | |
185 int sqlite3Fts5ConfigParse( | |
186 Fts5Global*, sqlite3*, int, const char **, Fts5Config**, char** | |
187 ); | |
188 void sqlite3Fts5ConfigFree(Fts5Config*); | |
189 | |
190 int sqlite3Fts5ConfigDeclareVtab(Fts5Config *pConfig); | |
191 | |
192 int sqlite3Fts5Tokenize( | |
193 Fts5Config *pConfig, /* FTS5 Configuration object */ | |
194 int flags, /* FTS5_TOKENIZE_* flags */ | |
195 const char *pText, int nText, /* Text to tokenize */ | |
196 void *pCtx, /* Context passed to xToken() */ | |
197 int (*xToken)(void*, int, const char*, int, int, int) /* Callback */ | |
198 ); | |
199 | |
200 void sqlite3Fts5Dequote(char *z); | |
201 | |
202 /* Load the contents of the %_config table */ | |
203 int sqlite3Fts5ConfigLoad(Fts5Config*, int); | |
204 | |
205 /* Set the value of a single config attribute */ | |
206 int sqlite3Fts5ConfigSetValue(Fts5Config*, const char*, sqlite3_value*, int*); | |
207 | |
208 int sqlite3Fts5ConfigParseRank(const char*, char**, char**); | |
209 | |
210 /* | |
211 ** End of interface to code in fts5_config.c. | |
212 **************************************************************************/ | |
213 | |
214 /************************************************************************** | |
215 ** Interface to code in fts5_buffer.c. | |
216 */ | |
217 | |
218 /* | |
219 ** Buffer object for the incremental building of string data. | |
220 */ | |
221 typedef struct Fts5Buffer Fts5Buffer; | |
222 struct Fts5Buffer { | |
223 u8 *p; | |
224 int n; | |
225 int nSpace; | |
226 }; | |
227 | |
228 int sqlite3Fts5BufferSize(int*, Fts5Buffer*, int); | |
229 void sqlite3Fts5BufferAppendVarint(int*, Fts5Buffer*, i64); | |
230 void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, int, const u8*); | |
231 void sqlite3Fts5BufferAppendString(int *, Fts5Buffer*, const char*); | |
232 void sqlite3Fts5BufferFree(Fts5Buffer*); | |
233 void sqlite3Fts5BufferZero(Fts5Buffer*); | |
234 void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*); | |
235 void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...); | |
236 | |
237 char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...); | |
238 | |
239 #define fts5BufferZero(x) sqlite3Fts5BufferZero(x) | |
240 #define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,c) | |
241 #define fts5BufferFree(a) sqlite3Fts5BufferFree(a) | |
242 #define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d) | |
243 #define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d) | |
244 | |
245 #define fts5BufferGrow(pRc,pBuf,nn) ( \ | |
246 (pBuf)->n + (nn) <= (pBuf)->nSpace ? 0 : \ | |
247 sqlite3Fts5BufferSize((pRc),(pBuf),(nn)+(pBuf)->n) \ | |
248 ) | |
249 | |
250 /* Write and decode big-endian 32-bit integer values */ | |
251 void sqlite3Fts5Put32(u8*, int); | |
252 int sqlite3Fts5Get32(const u8*); | |
253 | |
254 #define FTS5_POS2COLUMN(iPos) (int)(iPos >> 32) | |
255 #define FTS5_POS2OFFSET(iPos) (int)(iPos & 0xFFFFFFFF) | |
256 | |
257 typedef struct Fts5PoslistReader Fts5PoslistReader; | |
258 struct Fts5PoslistReader { | |
259 /* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */ | |
260 const u8 *a; /* Position list to iterate through */ | |
261 int n; /* Size of buffer at a[] in bytes */ | |
262 int i; /* Current offset in a[] */ | |
263 | |
264 u8 bFlag; /* For client use (any custom purpose) */ | |
265 | |
266 /* Output variables */ | |
267 u8 bEof; /* Set to true at EOF */ | |
268 i64 iPos; /* (iCol<<32) + iPos */ | |
269 }; | |
270 int sqlite3Fts5PoslistReaderInit( | |
271 const u8 *a, int n, /* Poslist buffer to iterate through */ | |
272 Fts5PoslistReader *pIter /* Iterator object to initialize */ | |
273 ); | |
274 int sqlite3Fts5PoslistReaderNext(Fts5PoslistReader*); | |
275 | |
276 typedef struct Fts5PoslistWriter Fts5PoslistWriter; | |
277 struct Fts5PoslistWriter { | |
278 i64 iPrev; | |
279 }; | |
280 int sqlite3Fts5PoslistWriterAppend(Fts5Buffer*, Fts5PoslistWriter*, i64); | |
281 | |
282 int sqlite3Fts5PoslistNext64( | |
283 const u8 *a, int n, /* Buffer containing poslist */ | |
284 int *pi, /* IN/OUT: Offset within a[] */ | |
285 i64 *piOff /* IN/OUT: Current offset */ | |
286 ); | |
287 | |
288 /* Malloc utility */ | |
289 void *sqlite3Fts5MallocZero(int *pRc, int nByte); | |
290 char *sqlite3Fts5Strndup(int *pRc, const char *pIn, int nIn); | |
291 | |
292 /* Character set tests (like isspace(), isalpha() etc.) */ | |
293 int sqlite3Fts5IsBareword(char t); | |
294 | |
295 /* | |
296 ** End of interface to code in fts5_buffer.c. | |
297 **************************************************************************/ | |
298 | |
299 /************************************************************************** | |
300 ** Interface to code in fts5_index.c. fts5_index.c contains contains code | |
301 ** to access the data stored in the %_data table. | |
302 */ | |
303 | |
304 typedef struct Fts5Index Fts5Index; | |
305 typedef struct Fts5IndexIter Fts5IndexIter; | |
306 | |
307 /* | |
308 ** Values used as part of the flags argument passed to IndexQuery(). | |
309 */ | |
310 #define FTS5INDEX_QUERY_PREFIX 0x0001 /* Prefix query */ | |
311 #define FTS5INDEX_QUERY_DESC 0x0002 /* Docs in descending rowid order */ | |
312 #define FTS5INDEX_QUERY_TEST_NOIDX 0x0004 /* Do not use prefix index */ | |
313 #define FTS5INDEX_QUERY_SCAN 0x0008 /* Scan query (fts5vocab) */ | |
314 | |
315 /* | |
316 ** Create/destroy an Fts5Index object. | |
317 */ | |
318 int sqlite3Fts5IndexOpen(Fts5Config *pConfig, int bCreate, Fts5Index**, char**); | |
319 int sqlite3Fts5IndexClose(Fts5Index *p); | |
320 | |
321 /* | |
322 ** for( | |
323 ** sqlite3Fts5IndexQuery(p, "token", 5, 0, 0, &pIter); | |
324 ** 0==sqlite3Fts5IterEof(pIter); | |
325 ** sqlite3Fts5IterNext(pIter) | |
326 ** ){ | |
327 ** i64 iRowid = sqlite3Fts5IterRowid(pIter); | |
328 ** } | |
329 */ | |
330 | |
331 /* | |
332 ** Open a new iterator to iterate though all rowids that match the | |
333 ** specified token or token prefix. | |
334 */ | |
335 int sqlite3Fts5IndexQuery( | |
336 Fts5Index *p, /* FTS index to query */ | |
337 const char *pToken, int nToken, /* Token (or prefix) to query for */ | |
338 int flags, /* Mask of FTS5INDEX_QUERY_X flags */ | |
339 Fts5Colset *pColset, /* Match these columns only */ | |
340 Fts5IndexIter **ppIter /* OUT: New iterator object */ | |
341 ); | |
342 | |
343 /* | |
344 ** The various operations on open token or token prefix iterators opened | |
345 ** using sqlite3Fts5IndexQuery(). | |
346 */ | |
347 int sqlite3Fts5IterEof(Fts5IndexIter*); | |
348 int sqlite3Fts5IterNext(Fts5IndexIter*); | |
349 int sqlite3Fts5IterNextFrom(Fts5IndexIter*, i64 iMatch); | |
350 i64 sqlite3Fts5IterRowid(Fts5IndexIter*); | |
351 int sqlite3Fts5IterPoslist(Fts5IndexIter*,Fts5Colset*, const u8**, int*, i64*); | |
352 int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf); | |
353 | |
354 /* | |
355 ** Close an iterator opened by sqlite3Fts5IndexQuery(). | |
356 */ | |
357 void sqlite3Fts5IterClose(Fts5IndexIter*); | |
358 | |
359 /* | |
360 ** This interface is used by the fts5vocab module. | |
361 */ | |
362 const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*); | |
363 int sqlite3Fts5IterNextScan(Fts5IndexIter*); | |
364 | |
365 | |
366 /* | |
367 ** Insert or remove data to or from the index. Each time a document is | |
368 ** added to or removed from the index, this function is called one or more | |
369 ** times. | |
370 ** | |
371 ** For an insert, it must be called once for each token in the new document. | |
372 ** If the operation is a delete, it must be called (at least) once for each | |
373 ** unique token in the document with an iCol value less than zero. The iPos | |
374 ** argument is ignored for a delete. | |
375 */ | |
376 int sqlite3Fts5IndexWrite( | |
377 Fts5Index *p, /* Index to write to */ | |
378 int iCol, /* Column token appears in (-ve -> delete) */ | |
379 int iPos, /* Position of token within column */ | |
380 const char *pToken, int nToken /* Token to add or remove to or from index */ | |
381 ); | |
382 | |
383 /* | |
384 ** Indicate that subsequent calls to sqlite3Fts5IndexWrite() pertain to | |
385 ** document iDocid. | |
386 */ | |
387 int sqlite3Fts5IndexBeginWrite( | |
388 Fts5Index *p, /* Index to write to */ | |
389 int bDelete, /* True if current operation is a delete */ | |
390 i64 iDocid /* Docid to add or remove data from */ | |
391 ); | |
392 | |
393 /* | |
394 ** Flush any data stored in the in-memory hash tables to the database. | |
395 ** If the bCommit flag is true, also close any open blob handles. | |
396 */ | |
397 int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit); | |
398 | |
399 /* | |
400 ** Discard any data stored in the in-memory hash tables. Do not write it | |
401 ** to the database. Additionally, assume that the contents of the %_data | |
402 ** table may have changed on disk. So any in-memory caches of %_data | |
403 ** records must be invalidated. | |
404 */ | |
405 int sqlite3Fts5IndexRollback(Fts5Index *p); | |
406 | |
407 /* | |
408 ** Get or set the "averages" values. | |
409 */ | |
410 int sqlite3Fts5IndexGetAverages(Fts5Index *p, i64 *pnRow, i64 *anSize); | |
411 int sqlite3Fts5IndexSetAverages(Fts5Index *p, const u8*, int); | |
412 | |
413 /* | |
414 ** Functions called by the storage module as part of integrity-check. | |
415 */ | |
416 u64 sqlite3Fts5IndexCksum(Fts5Config*,i64,int,int,const char*,int); | |
417 int sqlite3Fts5IndexIntegrityCheck(Fts5Index*, u64 cksum); | |
418 | |
419 /* | |
420 ** Called during virtual module initialization to register UDF | |
421 ** fts5_decode() with SQLite | |
422 */ | |
423 int sqlite3Fts5IndexInit(sqlite3*); | |
424 | |
425 int sqlite3Fts5IndexSetCookie(Fts5Index*, int); | |
426 | |
427 /* | |
428 ** Return the total number of entries read from the %_data table by | |
429 ** this connection since it was created. | |
430 */ | |
431 int sqlite3Fts5IndexReads(Fts5Index *p); | |
432 | |
433 int sqlite3Fts5IndexReinit(Fts5Index *p); | |
434 int sqlite3Fts5IndexOptimize(Fts5Index *p); | |
435 int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge); | |
436 | |
437 int sqlite3Fts5IndexLoadConfig(Fts5Index *p); | |
438 | |
439 /* | |
440 ** End of interface to code in fts5_index.c. | |
441 **************************************************************************/ | |
442 | |
443 /************************************************************************** | |
444 ** Interface to code in fts5_varint.c. | |
445 */ | |
446 int sqlite3Fts5GetVarint32(const unsigned char *p, u32 *v); | |
447 int sqlite3Fts5GetVarintLen(u32 iVal); | |
448 u8 sqlite3Fts5GetVarint(const unsigned char*, u64*); | |
449 int sqlite3Fts5PutVarint(unsigned char *p, u64 v); | |
450 | |
451 #define fts5GetVarint32(a,b) sqlite3Fts5GetVarint32(a,(u32*)&b) | |
452 #define fts5GetVarint sqlite3Fts5GetVarint | |
453 | |
454 #define fts5FastGetVarint32(a, iOff, nVal) { \ | |
455 nVal = (a)[iOff++]; \ | |
456 if( nVal & 0x80 ){ \ | |
457 iOff--; \ | |
458 iOff += fts5GetVarint32(&(a)[iOff], nVal); \ | |
459 } \ | |
460 } | |
461 | |
462 | |
463 /* | |
464 ** End of interface to code in fts5_varint.c. | |
465 **************************************************************************/ | |
466 | |
467 | |
468 /************************************************************************** | |
469 ** Interface to code in fts5.c. | |
470 */ | |
471 | |
472 int sqlite3Fts5GetTokenizer( | |
473 Fts5Global*, | |
474 const char **azArg, | |
475 int nArg, | |
476 Fts5Tokenizer**, | |
477 fts5_tokenizer**, | |
478 char **pzErr | |
479 ); | |
480 | |
481 Fts5Index *sqlite3Fts5IndexFromCsrid(Fts5Global*, i64, Fts5Config **); | |
482 | |
483 /* | |
484 ** End of interface to code in fts5.c. | |
485 **************************************************************************/ | |
486 | |
487 /************************************************************************** | |
488 ** Interface to code in fts5_hash.c. | |
489 */ | |
490 typedef struct Fts5Hash Fts5Hash; | |
491 | |
492 /* | |
493 ** Create a hash table, free a hash table. | |
494 */ | |
495 int sqlite3Fts5HashNew(Fts5Hash**, int *pnSize); | |
496 void sqlite3Fts5HashFree(Fts5Hash*); | |
497 | |
498 int sqlite3Fts5HashWrite( | |
499 Fts5Hash*, | |
500 i64 iRowid, /* Rowid for this entry */ | |
501 int iCol, /* Column token appears in (-ve -> delete) */ | |
502 int iPos, /* Position of token within column */ | |
503 char bByte, | |
504 const char *pToken, int nToken /* Token to add or remove to or from index */ | |
505 ); | |
506 | |
507 /* | |
508 ** Empty (but do not delete) a hash table. | |
509 */ | |
510 void sqlite3Fts5HashClear(Fts5Hash*); | |
511 | |
512 int sqlite3Fts5HashQuery( | |
513 Fts5Hash*, /* Hash table to query */ | |
514 const char *pTerm, int nTerm, /* Query term */ | |
515 const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */ | |
516 int *pnDoclist /* OUT: Size of doclist in bytes */ | |
517 ); | |
518 | |
519 int sqlite3Fts5HashScanInit( | |
520 Fts5Hash*, /* Hash table to query */ | |
521 const char *pTerm, int nTerm /* Query prefix */ | |
522 ); | |
523 void sqlite3Fts5HashScanNext(Fts5Hash*); | |
524 int sqlite3Fts5HashScanEof(Fts5Hash*); | |
525 void sqlite3Fts5HashScanEntry(Fts5Hash *, | |
526 const char **pzTerm, /* OUT: term (nul-terminated) */ | |
527 const u8 **ppDoclist, /* OUT: pointer to doclist */ | |
528 int *pnDoclist /* OUT: size of doclist in bytes */ | |
529 ); | |
530 | |
531 | |
532 /* | |
533 ** End of interface to code in fts5_hash.c. | |
534 **************************************************************************/ | |
535 | |
536 /************************************************************************** | |
537 ** Interface to code in fts5_storage.c. fts5_storage.c contains contains | |
538 ** code to access the data stored in the %_content and %_docsize tables. | |
539 */ | |
540 | |
541 #define FTS5_STMT_SCAN_ASC 0 /* SELECT rowid, * FROM ... ORDER BY 1 ASC */ | |
542 #define FTS5_STMT_SCAN_DESC 1 /* SELECT rowid, * FROM ... ORDER BY 1 DESC */ | |
543 #define FTS5_STMT_LOOKUP 2 /* SELECT rowid, * FROM ... WHERE rowid=? */ | |
544 | |
545 typedef struct Fts5Storage Fts5Storage; | |
546 | |
547 int sqlite3Fts5StorageOpen(Fts5Config*, Fts5Index*, int, Fts5Storage**, char**); | |
548 int sqlite3Fts5StorageClose(Fts5Storage *p); | |
549 int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName); | |
550 | |
551 int sqlite3Fts5DropAll(Fts5Config*); | |
552 int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **); | |
553 | |
554 int sqlite3Fts5StorageDelete(Fts5Storage *p, i64); | |
555 int sqlite3Fts5StorageContentInsert(Fts5Storage *p, sqlite3_value**, i64*); | |
556 int sqlite3Fts5StorageIndexInsert(Fts5Storage *p, sqlite3_value**, i64); | |
557 | |
558 int sqlite3Fts5StorageIntegrity(Fts5Storage *p); | |
559 | |
560 int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt**, char**); | |
561 void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*); | |
562 | |
563 int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol); | |
564 int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg); | |
565 int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow); | |
566 | |
567 int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit); | |
568 int sqlite3Fts5StorageRollback(Fts5Storage *p); | |
569 | |
570 int sqlite3Fts5StorageConfigValue( | |
571 Fts5Storage *p, const char*, sqlite3_value*, int | |
572 ); | |
573 | |
574 int sqlite3Fts5StorageSpecialDelete(Fts5Storage *p, i64 iDel, sqlite3_value**); | |
575 | |
576 int sqlite3Fts5StorageDeleteAll(Fts5Storage *p); | |
577 int sqlite3Fts5StorageRebuild(Fts5Storage *p); | |
578 int sqlite3Fts5StorageOptimize(Fts5Storage *p); | |
579 int sqlite3Fts5StorageMerge(Fts5Storage *p, int nMerge); | |
580 | |
581 /* | |
582 ** End of interface to code in fts5_storage.c. | |
583 **************************************************************************/ | |
584 | |
585 | |
586 /************************************************************************** | |
587 ** Interface to code in fts5_expr.c. | |
588 */ | |
589 typedef struct Fts5Expr Fts5Expr; | |
590 typedef struct Fts5ExprNode Fts5ExprNode; | |
591 typedef struct Fts5Parse Fts5Parse; | |
592 typedef struct Fts5Token Fts5Token; | |
593 typedef struct Fts5ExprPhrase Fts5ExprPhrase; | |
594 typedef struct Fts5ExprNearset Fts5ExprNearset; | |
595 | |
596 struct Fts5Token { | |
597 const char *p; /* Token text (not NULL terminated) */ | |
598 int n; /* Size of buffer p in bytes */ | |
599 }; | |
600 | |
601 /* Parse a MATCH expression. */ | |
602 int sqlite3Fts5ExprNew( | |
603 Fts5Config *pConfig, | |
604 const char *zExpr, | |
605 Fts5Expr **ppNew, | |
606 char **pzErr | |
607 ); | |
608 | |
609 /* | |
610 ** for(rc = sqlite3Fts5ExprFirst(pExpr, pIdx, bDesc); | |
611 ** rc==SQLITE_OK && 0==sqlite3Fts5ExprEof(pExpr); | |
612 ** rc = sqlite3Fts5ExprNext(pExpr) | |
613 ** ){ | |
614 ** // The document with rowid iRowid matches the expression! | |
615 ** i64 iRowid = sqlite3Fts5ExprRowid(pExpr); | |
616 ** } | |
617 */ | |
618 int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc); | |
619 int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax); | |
620 int sqlite3Fts5ExprEof(Fts5Expr*); | |
621 i64 sqlite3Fts5ExprRowid(Fts5Expr*); | |
622 | |
623 void sqlite3Fts5ExprFree(Fts5Expr*); | |
624 | |
625 /* Called during startup to register a UDF with SQLite */ | |
626 int sqlite3Fts5ExprInit(Fts5Global*, sqlite3*); | |
627 | |
628 int sqlite3Fts5ExprPhraseCount(Fts5Expr*); | |
629 int sqlite3Fts5ExprPhraseSize(Fts5Expr*, int iPhrase); | |
630 int sqlite3Fts5ExprPoslist(Fts5Expr*, int, const u8 **); | |
631 | |
632 int sqlite3Fts5ExprClonePhrase(Fts5Config*, Fts5Expr*, int, Fts5Expr**); | |
633 | |
634 /******************************************* | |
635 ** The fts5_expr.c API above this point is used by the other hand-written | |
636 ** C code in this module. The interfaces below this point are called by | |
637 ** the parser code in fts5parse.y. */ | |
638 | |
639 void sqlite3Fts5ParseError(Fts5Parse *pParse, const char *zFmt, ...); | |
640 | |
641 Fts5ExprNode *sqlite3Fts5ParseNode( | |
642 Fts5Parse *pParse, | |
643 int eType, | |
644 Fts5ExprNode *pLeft, | |
645 Fts5ExprNode *pRight, | |
646 Fts5ExprNearset *pNear | |
647 ); | |
648 | |
649 Fts5ExprPhrase *sqlite3Fts5ParseTerm( | |
650 Fts5Parse *pParse, | |
651 Fts5ExprPhrase *pPhrase, | |
652 Fts5Token *pToken, | |
653 int bPrefix | |
654 ); | |
655 | |
656 Fts5ExprNearset *sqlite3Fts5ParseNearset( | |
657 Fts5Parse*, | |
658 Fts5ExprNearset*, | |
659 Fts5ExprPhrase* | |
660 ); | |
661 | |
662 Fts5Colset *sqlite3Fts5ParseColset( | |
663 Fts5Parse*, | |
664 Fts5Colset*, | |
665 Fts5Token * | |
666 ); | |
667 | |
668 void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*); | |
669 void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*); | |
670 void sqlite3Fts5ParseNodeFree(Fts5ExprNode*); | |
671 | |
672 void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*); | |
673 void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*); | |
674 void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p); | |
675 void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*); | |
676 | |
677 /* | |
678 ** End of interface to code in fts5_expr.c. | |
679 **************************************************************************/ | |
680 | |
681 | |
682 | |
683 /************************************************************************** | |
684 ** Interface to code in fts5_aux.c. | |
685 */ | |
686 | |
687 int sqlite3Fts5AuxInit(fts5_api*); | |
688 /* | |
689 ** End of interface to code in fts5_aux.c. | |
690 **************************************************************************/ | |
691 | |
692 /************************************************************************** | |
693 ** Interface to code in fts5_tokenizer.c. | |
694 */ | |
695 | |
696 int sqlite3Fts5TokenizerInit(fts5_api*); | |
697 /* | |
698 ** End of interface to code in fts5_tokenizer.c. | |
699 **************************************************************************/ | |
700 | |
701 /************************************************************************** | |
702 ** Interface to code in fts5_vocab.c. | |
703 */ | |
704 | |
705 int sqlite3Fts5VocabInit(Fts5Global*, sqlite3*); | |
706 | |
707 /* | |
708 ** End of interface to code in fts5_vocab.c. | |
709 **************************************************************************/ | |
710 | |
711 | |
712 /************************************************************************** | |
713 ** Interface to automatically generated code in fts5_unicode2.c. | |
714 */ | |
715 int sqlite3Fts5UnicodeIsalnum(int c); | |
716 int sqlite3Fts5UnicodeIsdiacritic(int c); | |
717 int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic); | |
718 /* | |
719 ** End of interface to code in fts5_unicode2.c. | |
720 **************************************************************************/ | |
721 | |
722 #endif | |
OLD | NEW |