OLD | NEW |
| (Empty) |
1 /* | |
2 ** 2009 Nov 12 | |
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 _FTSINT_H | |
15 #define _FTSINT_H | |
16 | |
17 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) | |
18 # define NDEBUG 1 | |
19 #endif | |
20 | |
21 /* | |
22 ** FTS4 is really an extension for FTS3. It is enabled using the | |
23 ** SQLITE_ENABLE_FTS3 macro. But to avoid confusion we also all | |
24 ** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3. | |
25 */ | |
26 #if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3) | |
27 # define SQLITE_ENABLE_FTS3 | |
28 #endif | |
29 | |
30 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) | |
31 | |
32 /* If not building as part of the core, include sqlite3ext.h. */ | |
33 #ifndef SQLITE_CORE | |
34 # include "sqlite3ext.h" | |
35 SQLITE_EXTENSION_INIT3 | |
36 #endif | |
37 | |
38 #include "sqlite3.h" | |
39 #include "fts3_tokenizer.h" | |
40 #include "fts3_hash.h" | |
41 | |
42 /* | |
43 ** This constant determines the maximum depth of an FTS expression tree | |
44 ** that the library will create and use. FTS uses recursion to perform | |
45 ** various operations on the query tree, so the disadvantage of a large | |
46 ** limit is that it may allow very large queries to use large amounts | |
47 ** of stack space (perhaps causing a stack overflow). | |
48 */ | |
49 #ifndef SQLITE_FTS3_MAX_EXPR_DEPTH | |
50 # define SQLITE_FTS3_MAX_EXPR_DEPTH 12 | |
51 #endif | |
52 | |
53 | |
54 /* | |
55 ** This constant controls how often segments are merged. Once there are | |
56 ** FTS3_MERGE_COUNT segments of level N, they are merged into a single | |
57 ** segment of level N+1. | |
58 */ | |
59 #define FTS3_MERGE_COUNT 16 | |
60 | |
61 /* | |
62 ** This is the maximum amount of data (in bytes) to store in the | |
63 ** Fts3Table.pendingTerms hash table. Normally, the hash table is | |
64 ** populated as documents are inserted/updated/deleted in a transaction | |
65 ** and used to create a new segment when the transaction is committed. | |
66 ** However if this limit is reached midway through a transaction, a new | |
67 ** segment is created and the hash table cleared immediately. | |
68 */ | |
69 #define FTS3_MAX_PENDING_DATA (1*1024*1024) | |
70 | |
71 /* | |
72 ** Macro to return the number of elements in an array. SQLite has a | |
73 ** similar macro called ArraySize(). Use a different name to avoid | |
74 ** a collision when building an amalgamation with built-in FTS3. | |
75 */ | |
76 #define SizeofArray(X) ((int)(sizeof(X)/sizeof(X[0]))) | |
77 | |
78 | |
79 #ifndef MIN | |
80 # define MIN(x,y) ((x)<(y)?(x):(y)) | |
81 #endif | |
82 #ifndef MAX | |
83 # define MAX(x,y) ((x)>(y)?(x):(y)) | |
84 #endif | |
85 | |
86 /* | |
87 ** Maximum length of a varint encoded integer. The varint format is different | |
88 ** from that used by SQLite, so the maximum length is 10, not 9. | |
89 */ | |
90 #define FTS3_VARINT_MAX 10 | |
91 | |
92 /* | |
93 ** FTS4 virtual tables may maintain multiple indexes - one index of all terms | |
94 ** in the document set and zero or more prefix indexes. All indexes are stored | |
95 ** as one or more b+-trees in the %_segments and %_segdir tables. | |
96 ** | |
97 ** It is possible to determine which index a b+-tree belongs to based on the | |
98 ** value stored in the "%_segdir.level" column. Given this value L, the index | |
99 ** that the b+-tree belongs to is (L<<10). In other words, all b+-trees with | |
100 ** level values between 0 and 1023 (inclusive) belong to index 0, all levels | |
101 ** between 1024 and 2047 to index 1, and so on. | |
102 ** | |
103 ** It is considered impossible for an index to use more than 1024 levels. In | |
104 ** theory though this may happen, but only after at least | |
105 ** (FTS3_MERGE_COUNT^1024) separate flushes of the pending-terms tables. | |
106 */ | |
107 #define FTS3_SEGDIR_MAXLEVEL 1024 | |
108 #define FTS3_SEGDIR_MAXLEVEL_STR "1024" | |
109 | |
110 /* | |
111 ** The testcase() macro is only used by the amalgamation. If undefined, | |
112 ** make it a no-op. | |
113 */ | |
114 #ifndef testcase | |
115 # define testcase(X) | |
116 #endif | |
117 | |
118 /* | |
119 ** Terminator values for position-lists and column-lists. | |
120 */ | |
121 #define POS_COLUMN (1) /* Column-list terminator */ | |
122 #define POS_END (0) /* Position-list terminator */ | |
123 | |
124 /* | |
125 ** This section provides definitions to allow the | |
126 ** FTS3 extension to be compiled outside of the | |
127 ** amalgamation. | |
128 */ | |
129 #ifndef SQLITE_AMALGAMATION | |
130 /* | |
131 ** Macros indicating that conditional expressions are always true or | |
132 ** false. | |
133 */ | |
134 #ifdef SQLITE_COVERAGE_TEST | |
135 # define ALWAYS(x) (1) | |
136 # define NEVER(X) (0) | |
137 #elif defined(SQLITE_DEBUG) | |
138 # define ALWAYS(x) sqlite3Fts3Always((x)!=0) | |
139 # define NEVER(x) sqlite3Fts3Never((x)!=0) | |
140 int sqlite3Fts3Always(int b); | |
141 int sqlite3Fts3Never(int b); | |
142 #else | |
143 # define ALWAYS(x) (x) | |
144 # define NEVER(x) (x) | |
145 #endif | |
146 | |
147 /* | |
148 ** Internal types used by SQLite. | |
149 */ | |
150 typedef unsigned char u8; /* 1-byte (or larger) unsigned integer */ | |
151 typedef short int i16; /* 2-byte (or larger) signed integer */ | |
152 typedef unsigned int u32; /* 4-byte unsigned integer */ | |
153 typedef sqlite3_uint64 u64; /* 8-byte unsigned integer */ | |
154 typedef sqlite3_int64 i64; /* 8-byte signed integer */ | |
155 | |
156 /* | |
157 ** Macro used to suppress compiler warnings for unused parameters. | |
158 */ | |
159 #define UNUSED_PARAMETER(x) (void)(x) | |
160 | |
161 /* | |
162 ** Activate assert() only if SQLITE_TEST is enabled. | |
163 */ | |
164 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) | |
165 # define NDEBUG 1 | |
166 #endif | |
167 | |
168 /* | |
169 ** The TESTONLY macro is used to enclose variable declarations or | |
170 ** other bits of code that are needed to support the arguments | |
171 ** within testcase() and assert() macros. | |
172 */ | |
173 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) | |
174 # define TESTONLY(X) X | |
175 #else | |
176 # define TESTONLY(X) | |
177 #endif | |
178 | |
179 #endif /* SQLITE_AMALGAMATION */ | |
180 | |
181 #ifdef SQLITE_DEBUG | |
182 int sqlite3Fts3Corrupt(void); | |
183 # define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt() | |
184 #else | |
185 # define FTS_CORRUPT_VTAB SQLITE_CORRUPT_VTAB | |
186 #endif | |
187 | |
188 typedef struct Fts3Table Fts3Table; | |
189 typedef struct Fts3Cursor Fts3Cursor; | |
190 typedef struct Fts3Expr Fts3Expr; | |
191 typedef struct Fts3Phrase Fts3Phrase; | |
192 typedef struct Fts3PhraseToken Fts3PhraseToken; | |
193 | |
194 typedef struct Fts3Doclist Fts3Doclist; | |
195 typedef struct Fts3SegFilter Fts3SegFilter; | |
196 typedef struct Fts3DeferredToken Fts3DeferredToken; | |
197 typedef struct Fts3SegReader Fts3SegReader; | |
198 typedef struct Fts3MultiSegReader Fts3MultiSegReader; | |
199 | |
200 typedef struct MatchinfoBuffer MatchinfoBuffer; | |
201 | |
202 /* | |
203 ** A connection to a fulltext index is an instance of the following | |
204 ** structure. The xCreate and xConnect methods create an instance | |
205 ** of this structure and xDestroy and xDisconnect free that instance. | |
206 ** All other methods receive a pointer to the structure as one of their | |
207 ** arguments. | |
208 */ | |
209 struct Fts3Table { | |
210 sqlite3_vtab base; /* Base class used by SQLite core */ | |
211 sqlite3 *db; /* The database connection */ | |
212 const char *zDb; /* logical database name */ | |
213 const char *zName; /* virtual table name */ | |
214 int nColumn; /* number of named columns in virtual table */ | |
215 char **azColumn; /* column names. malloced */ | |
216 u8 *abNotindexed; /* True for 'notindexed' columns */ | |
217 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */ | |
218 char *zContentTbl; /* content=xxx option, or NULL */ | |
219 char *zLanguageid; /* languageid=xxx option, or NULL */ | |
220 int nAutoincrmerge; /* Value configured by 'automerge' */ | |
221 u32 nLeafAdd; /* Number of leaf blocks added this trans */ | |
222 | |
223 /* Precompiled statements used by the implementation. Each of these | |
224 ** statements is run and reset within a single virtual table API call. | |
225 */ | |
226 sqlite3_stmt *aStmt[40]; | |
227 | |
228 char *zReadExprlist; | |
229 char *zWriteExprlist; | |
230 | |
231 int nNodeSize; /* Soft limit for node size */ | |
232 u8 bFts4; /* True for FTS4, false for FTS3 */ | |
233 u8 bHasStat; /* True if %_stat table exists (2==unknown) */ | |
234 u8 bHasDocsize; /* True if %_docsize table exists */ | |
235 u8 bDescIdx; /* True if doclists are in reverse order */ | |
236 u8 bIgnoreSavepoint; /* True to ignore xSavepoint invocations */ | |
237 int nPgsz; /* Page size for host database */ | |
238 char *zSegmentsTbl; /* Name of %_segments table */ | |
239 sqlite3_blob *pSegments; /* Blob handle open on %_segments table */ | |
240 | |
241 /* | |
242 ** The following array of hash tables is used to buffer pending index | |
243 ** updates during transactions. All pending updates buffered at any one | |
244 ** time must share a common language-id (see the FTS4 langid= feature). | |
245 ** The current language id is stored in variable iPrevLangid. | |
246 ** | |
247 ** A single FTS4 table may have multiple full-text indexes. For each index | |
248 ** there is an entry in the aIndex[] array. Index 0 is an index of all the | |
249 ** terms that appear in the document set. Each subsequent index in aIndex[] | |
250 ** is an index of prefixes of a specific length. | |
251 ** | |
252 ** Variable nPendingData contains an estimate the memory consumed by the | |
253 ** pending data structures, including hash table overhead, but not including | |
254 ** malloc overhead. When nPendingData exceeds nMaxPendingData, all hash | |
255 ** tables are flushed to disk. Variable iPrevDocid is the docid of the most | |
256 ** recently inserted record. | |
257 */ | |
258 int nIndex; /* Size of aIndex[] */ | |
259 struct Fts3Index { | |
260 int nPrefix; /* Prefix length (0 for main terms index) */ | |
261 Fts3Hash hPending; /* Pending terms table for this index */ | |
262 } *aIndex; | |
263 int nMaxPendingData; /* Max pending data before flush to disk */ | |
264 int nPendingData; /* Current bytes of pending data */ | |
265 sqlite_int64 iPrevDocid; /* Docid of most recently inserted document */ | |
266 int iPrevLangid; /* Langid of recently inserted document */ | |
267 int bPrevDelete; /* True if last operation was a delete */ | |
268 | |
269 #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST) | |
270 /* State variables used for validating that the transaction control | |
271 ** methods of the virtual table are called at appropriate times. These | |
272 ** values do not contribute to FTS functionality; they are used for | |
273 ** verifying the operation of the SQLite core. | |
274 */ | |
275 int inTransaction; /* True after xBegin but before xCommit/xRollback */ | |
276 int mxSavepoint; /* Largest valid xSavepoint integer */ | |
277 #endif | |
278 | |
279 #ifdef SQLITE_TEST | |
280 /* True to disable the incremental doclist optimization. This is controled | |
281 ** by special insert command 'test-no-incr-doclist'. */ | |
282 int bNoIncrDoclist; | |
283 #endif | |
284 }; | |
285 | |
286 /* | |
287 ** When the core wants to read from the virtual table, it creates a | |
288 ** virtual table cursor (an instance of the following structure) using | |
289 ** the xOpen method. Cursors are destroyed using the xClose method. | |
290 */ | |
291 struct Fts3Cursor { | |
292 sqlite3_vtab_cursor base; /* Base class used by SQLite core */ | |
293 i16 eSearch; /* Search strategy (see below) */ | |
294 u8 isEof; /* True if at End Of Results */ | |
295 u8 isRequireSeek; /* True if must seek pStmt to %_content row */ | |
296 sqlite3_stmt *pStmt; /* Prepared statement in use by the cursor */ | |
297 Fts3Expr *pExpr; /* Parsed MATCH query string */ | |
298 int iLangid; /* Language being queried for */ | |
299 int nPhrase; /* Number of matchable phrases in query */ | |
300 Fts3DeferredToken *pDeferred; /* Deferred search tokens, if any */ | |
301 sqlite3_int64 iPrevId; /* Previous id read from aDoclist */ | |
302 char *pNextId; /* Pointer into the body of aDoclist */ | |
303 char *aDoclist; /* List of docids for full-text queries */ | |
304 int nDoclist; /* Size of buffer at aDoclist */ | |
305 u8 bDesc; /* True to sort in descending order */ | |
306 int eEvalmode; /* An FTS3_EVAL_XX constant */ | |
307 int nRowAvg; /* Average size of database rows, in pages */ | |
308 sqlite3_int64 nDoc; /* Documents in table */ | |
309 i64 iMinDocid; /* Minimum docid to return */ | |
310 i64 iMaxDocid; /* Maximum docid to return */ | |
311 int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */ | |
312 MatchinfoBuffer *pMIBuffer; /* Buffer for matchinfo data */ | |
313 }; | |
314 | |
315 #define FTS3_EVAL_FILTER 0 | |
316 #define FTS3_EVAL_NEXT 1 | |
317 #define FTS3_EVAL_MATCHINFO 2 | |
318 | |
319 /* | |
320 ** The Fts3Cursor.eSearch member is always set to one of the following. | |
321 ** Actualy, Fts3Cursor.eSearch can be greater than or equal to | |
322 ** FTS3_FULLTEXT_SEARCH. If so, then Fts3Cursor.eSearch - 2 is the index | |
323 ** of the column to be searched. For example, in | |
324 ** | |
325 ** CREATE VIRTUAL TABLE ex1 USING fts3(a,b,c,d); | |
326 ** SELECT docid FROM ex1 WHERE b MATCH 'one two three'; | |
327 ** | |
328 ** Because the LHS of the MATCH operator is 2nd column "b", | |
329 ** Fts3Cursor.eSearch will be set to FTS3_FULLTEXT_SEARCH+1. (+0 for a, | |
330 ** +1 for b, +2 for c, +3 for d.) If the LHS of MATCH were "ex1" | |
331 ** indicating that all columns should be searched, | |
332 ** then eSearch would be set to FTS3_FULLTEXT_SEARCH+4. | |
333 */ | |
334 #define FTS3_FULLSCAN_SEARCH 0 /* Linear scan of %_content table */ | |
335 #define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */ | |
336 #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */ | |
337 | |
338 /* | |
339 ** The lower 16-bits of the sqlite3_index_info.idxNum value set by | |
340 ** the xBestIndex() method contains the Fts3Cursor.eSearch value described | |
341 ** above. The upper 16-bits contain a combination of the following | |
342 ** bits, used to describe extra constraints on full-text searches. | |
343 */ | |
344 #define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */ | |
345 #define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */ | |
346 #define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */ | |
347 | |
348 struct Fts3Doclist { | |
349 char *aAll; /* Array containing doclist (or NULL) */ | |
350 int nAll; /* Size of a[] in bytes */ | |
351 char *pNextDocid; /* Pointer to next docid */ | |
352 | |
353 sqlite3_int64 iDocid; /* Current docid (if pList!=0) */ | |
354 int bFreeList; /* True if pList should be sqlite3_free()d */ | |
355 char *pList; /* Pointer to position list following iDocid */ | |
356 int nList; /* Length of position list */ | |
357 }; | |
358 | |
359 /* | |
360 ** A "phrase" is a sequence of one or more tokens that must match in | |
361 ** sequence. A single token is the base case and the most common case. | |
362 ** For a sequence of tokens contained in double-quotes (i.e. "one two three") | |
363 ** nToken will be the number of tokens in the string. | |
364 */ | |
365 struct Fts3PhraseToken { | |
366 char *z; /* Text of the token */ | |
367 int n; /* Number of bytes in buffer z */ | |
368 int isPrefix; /* True if token ends with a "*" character */ | |
369 int bFirst; /* True if token must appear at position 0 */ | |
370 | |
371 /* Variables above this point are populated when the expression is | |
372 ** parsed (by code in fts3_expr.c). Below this point the variables are | |
373 ** used when evaluating the expression. */ | |
374 Fts3DeferredToken *pDeferred; /* Deferred token object for this token */ | |
375 Fts3MultiSegReader *pSegcsr; /* Segment-reader for this token */ | |
376 }; | |
377 | |
378 struct Fts3Phrase { | |
379 /* Cache of doclist for this phrase. */ | |
380 Fts3Doclist doclist; | |
381 int bIncr; /* True if doclist is loaded incrementally */ | |
382 int iDoclistToken; | |
383 | |
384 /* Used by sqlite3Fts3EvalPhrasePoslist() if this is a descendent of an | |
385 ** OR condition. */ | |
386 char *pOrPoslist; | |
387 i64 iOrDocid; | |
388 | |
389 /* Variables below this point are populated by fts3_expr.c when parsing | |
390 ** a MATCH expression. Everything above is part of the evaluation phase. | |
391 */ | |
392 int nToken; /* Number of tokens in the phrase */ | |
393 int iColumn; /* Index of column this phrase must match */ | |
394 Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */ | |
395 }; | |
396 | |
397 /* | |
398 ** A tree of these objects forms the RHS of a MATCH operator. | |
399 ** | |
400 ** If Fts3Expr.eType is FTSQUERY_PHRASE and isLoaded is true, then aDoclist | |
401 ** points to a malloced buffer, size nDoclist bytes, containing the results | |
402 ** of this phrase query in FTS3 doclist format. As usual, the initial | |
403 ** "Length" field found in doclists stored on disk is omitted from this | |
404 ** buffer. | |
405 ** | |
406 ** Variable aMI is used only for FTSQUERY_NEAR nodes to store the global | |
407 ** matchinfo data. If it is not NULL, it points to an array of size nCol*3, | |
408 ** where nCol is the number of columns in the queried FTS table. The array | |
409 ** is populated as follows: | |
410 ** | |
411 ** aMI[iCol*3 + 0] = Undefined | |
412 ** aMI[iCol*3 + 1] = Number of occurrences | |
413 ** aMI[iCol*3 + 2] = Number of rows containing at least one instance | |
414 ** | |
415 ** The aMI array is allocated using sqlite3_malloc(). It should be freed | |
416 ** when the expression node is. | |
417 */ | |
418 struct Fts3Expr { | |
419 int eType; /* One of the FTSQUERY_XXX values defined below */ | |
420 int nNear; /* Valid if eType==FTSQUERY_NEAR */ | |
421 Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */ | |
422 Fts3Expr *pLeft; /* Left operand */ | |
423 Fts3Expr *pRight; /* Right operand */ | |
424 Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */ | |
425 | |
426 /* The following are used by the fts3_eval.c module. */ | |
427 sqlite3_int64 iDocid; /* Current docid */ | |
428 u8 bEof; /* True this expression is at EOF already */ | |
429 u8 bStart; /* True if iDocid is valid */ | |
430 u8 bDeferred; /* True if this expression is entirely deferred */ | |
431 | |
432 /* The following are used by the fts3_snippet.c module. */ | |
433 int iPhrase; /* Index of this phrase in matchinfo() results */ | |
434 u32 *aMI; /* See above */ | |
435 }; | |
436 | |
437 /* | |
438 ** Candidate values for Fts3Query.eType. Note that the order of the first | |
439 ** four values is in order of precedence when parsing expressions. For | |
440 ** example, the following: | |
441 ** | |
442 ** "a OR b AND c NOT d NEAR e" | |
443 ** | |
444 ** is equivalent to: | |
445 ** | |
446 ** "a OR (b AND (c NOT (d NEAR e)))" | |
447 */ | |
448 #define FTSQUERY_NEAR 1 | |
449 #define FTSQUERY_NOT 2 | |
450 #define FTSQUERY_AND 3 | |
451 #define FTSQUERY_OR 4 | |
452 #define FTSQUERY_PHRASE 5 | |
453 | |
454 | |
455 /* fts3_write.c */ | |
456 int sqlite3Fts3UpdateMethod(sqlite3_vtab*,int,sqlite3_value**,sqlite3_int64*); | |
457 int sqlite3Fts3PendingTermsFlush(Fts3Table *); | |
458 void sqlite3Fts3PendingTermsClear(Fts3Table *); | |
459 int sqlite3Fts3Optimize(Fts3Table *); | |
460 int sqlite3Fts3SegReaderNew(int, int, sqlite3_int64, | |
461 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**); | |
462 int sqlite3Fts3SegReaderPending( | |
463 Fts3Table*,int,const char*,int,int,Fts3SegReader**); | |
464 void sqlite3Fts3SegReaderFree(Fts3SegReader *); | |
465 int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **); | |
466 int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*); | |
467 | |
468 int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **); | |
469 int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **); | |
470 | |
471 #ifndef SQLITE_DISABLE_FTS4_DEFERRED | |
472 void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *); | |
473 int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int); | |
474 int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *); | |
475 void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *); | |
476 int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *); | |
477 #else | |
478 # define sqlite3Fts3FreeDeferredTokens(x) | |
479 # define sqlite3Fts3DeferToken(x,y,z) SQLITE_OK | |
480 # define sqlite3Fts3CacheDeferredDoclists(x) SQLITE_OK | |
481 # define sqlite3Fts3FreeDeferredDoclists(x) | |
482 # define sqlite3Fts3DeferredTokenList(x,y,z) SQLITE_OK | |
483 #endif | |
484 | |
485 void sqlite3Fts3SegmentsClose(Fts3Table *); | |
486 int sqlite3Fts3MaxLevel(Fts3Table *, int *); | |
487 | |
488 /* Special values interpreted by sqlite3SegReaderCursor() */ | |
489 #define FTS3_SEGCURSOR_PENDING -1 | |
490 #define FTS3_SEGCURSOR_ALL -2 | |
491 | |
492 int sqlite3Fts3SegReaderStart(Fts3Table*, Fts3MultiSegReader*, Fts3SegFilter*); | |
493 int sqlite3Fts3SegReaderStep(Fts3Table *, Fts3MultiSegReader *); | |
494 void sqlite3Fts3SegReaderFinish(Fts3MultiSegReader *); | |
495 | |
496 int sqlite3Fts3SegReaderCursor(Fts3Table *, | |
497 int, int, int, const char *, int, int, int, Fts3MultiSegReader *); | |
498 | |
499 /* Flags allowed as part of the 4th argument to SegmentReaderIterate() */ | |
500 #define FTS3_SEGMENT_REQUIRE_POS 0x00000001 | |
501 #define FTS3_SEGMENT_IGNORE_EMPTY 0x00000002 | |
502 #define FTS3_SEGMENT_COLUMN_FILTER 0x00000004 | |
503 #define FTS3_SEGMENT_PREFIX 0x00000008 | |
504 #define FTS3_SEGMENT_SCAN 0x00000010 | |
505 #define FTS3_SEGMENT_FIRST 0x00000020 | |
506 | |
507 /* Type passed as 4th argument to SegmentReaderIterate() */ | |
508 struct Fts3SegFilter { | |
509 const char *zTerm; | |
510 int nTerm; | |
511 int iCol; | |
512 int flags; | |
513 }; | |
514 | |
515 struct Fts3MultiSegReader { | |
516 /* Used internally by sqlite3Fts3SegReaderXXX() calls */ | |
517 Fts3SegReader **apSegment; /* Array of Fts3SegReader objects */ | |
518 int nSegment; /* Size of apSegment array */ | |
519 int nAdvance; /* How many seg-readers to advance */ | |
520 Fts3SegFilter *pFilter; /* Pointer to filter object */ | |
521 char *aBuffer; /* Buffer to merge doclists in */ | |
522 int nBuffer; /* Allocated size of aBuffer[] in bytes */ | |
523 | |
524 int iColFilter; /* If >=0, filter for this column */ | |
525 int bRestart; | |
526 | |
527 /* Used by fts3.c only. */ | |
528 int nCost; /* Cost of running iterator */ | |
529 int bLookup; /* True if a lookup of a single entry. */ | |
530 | |
531 /* Output values. Valid only after Fts3SegReaderStep() returns SQLITE_ROW. */ | |
532 char *zTerm; /* Pointer to term buffer */ | |
533 int nTerm; /* Size of zTerm in bytes */ | |
534 char *aDoclist; /* Pointer to doclist buffer */ | |
535 int nDoclist; /* Size of aDoclist[] in bytes */ | |
536 }; | |
537 | |
538 int sqlite3Fts3Incrmerge(Fts3Table*,int,int); | |
539 | |
540 #define fts3GetVarint32(p, piVal) ( \ | |
541 (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \ | |
542 ) | |
543 | |
544 /* fts3.c */ | |
545 void sqlite3Fts3ErrMsg(char**,const char*,...); | |
546 int sqlite3Fts3PutVarint(char *, sqlite3_int64); | |
547 int sqlite3Fts3GetVarint(const char *, sqlite_int64 *); | |
548 int sqlite3Fts3GetVarint32(const char *, int *); | |
549 int sqlite3Fts3VarintLen(sqlite3_uint64); | |
550 void sqlite3Fts3Dequote(char *); | |
551 void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*); | |
552 int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *); | |
553 int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *); | |
554 void sqlite3Fts3CreateStatTable(int*, Fts3Table*); | |
555 int sqlite3Fts3EvalTestDeferred(Fts3Cursor *pCsr, int *pRc); | |
556 | |
557 /* fts3_tokenizer.c */ | |
558 const char *sqlite3Fts3NextToken(const char *, int *); | |
559 int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *); | |
560 int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *, | |
561 sqlite3_tokenizer **, char ** | |
562 ); | |
563 int sqlite3Fts3IsIdChar(char); | |
564 | |
565 /* fts3_snippet.c */ | |
566 void sqlite3Fts3Offsets(sqlite3_context*, Fts3Cursor*); | |
567 void sqlite3Fts3Snippet(sqlite3_context *, Fts3Cursor *, const char *, | |
568 const char *, const char *, int, int | |
569 ); | |
570 void sqlite3Fts3Matchinfo(sqlite3_context *, Fts3Cursor *, const char *); | |
571 void sqlite3Fts3MIBufferFree(MatchinfoBuffer *p); | |
572 | |
573 /* fts3_expr.c */ | |
574 int sqlite3Fts3ExprParse(sqlite3_tokenizer *, int, | |
575 char **, int, int, int, const char *, int, Fts3Expr **, char ** | |
576 ); | |
577 void sqlite3Fts3ExprFree(Fts3Expr *); | |
578 #ifdef SQLITE_TEST | |
579 int sqlite3Fts3ExprInitTestInterface(sqlite3 *db); | |
580 int sqlite3Fts3InitTerm(sqlite3 *db); | |
581 #endif | |
582 | |
583 int sqlite3Fts3OpenTokenizer(sqlite3_tokenizer *, int, const char *, int, | |
584 sqlite3_tokenizer_cursor ** | |
585 ); | |
586 | |
587 /* fts3_aux.c */ | |
588 int sqlite3Fts3InitAux(sqlite3 *db); | |
589 | |
590 void sqlite3Fts3EvalPhraseCleanup(Fts3Phrase *); | |
591 | |
592 int sqlite3Fts3MsrIncrStart( | |
593 Fts3Table*, Fts3MultiSegReader*, int, const char*, int); | |
594 int sqlite3Fts3MsrIncrNext( | |
595 Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *); | |
596 int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **); | |
597 int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *); | |
598 int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); | |
599 | |
600 /* fts3_tokenize_vtab.c */ | |
601 int sqlite3Fts3InitTok(sqlite3*, Fts3Hash *); | |
602 | |
603 /* fts3_unicode2.c (functions generated by parsing unicode text files) */ | |
604 #ifndef SQLITE_DISABLE_FTS3_UNICODE | |
605 int sqlite3FtsUnicodeFold(int, int); | |
606 int sqlite3FtsUnicodeIsalnum(int); | |
607 int sqlite3FtsUnicodeIsdiacritic(int); | |
608 #endif | |
609 | |
610 #endif /* !SQLITE_CORE || SQLITE_ENABLE_FTS3 */ | |
611 #endif /* _FTSINT_H */ | |
OLD | NEW |