fts3Int.h 23 KB

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