0000: 2f 2a 0a 2a 2a 20 32 30 31 34 20 4d 61 79 20 33 /*.** 2014 May 3
0010: 31 0a 2a 2a 0a 2a 2a 20 54 68 65 20 61 75 74 68 1.**.** The auth
0020: 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 or disclaims cop
0030: 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 yright to this s
0040: 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 ource code. In
0050: 70 6c 61 63 65 20 6f 66 0a 2a 2a 20 61 20 6c 65 place of.** a le
0060: 67 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 gal notice, here
0070: 20 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a is a blessing:.
0080: 2a 2a 0a 2a 2a 20 20 20 20 4d 61 79 20 79 6f 75 **.** May you
0090: 20 64 6f 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 do good and not
00a0: 20 65 76 69 6c 2e 0a 2a 2a 20 20 20 20 4d 61 79 evil..** May
00b0: 20 79 6f 75 20 66 69 6e 64 20 66 6f 72 67 69 76 you find forgiv
00c0: 65 6e 65 73 73 20 66 6f 72 20 79 6f 75 72 73 65 eness for yourse
00d0: 6c 66 20 61 6e 64 20 66 6f 72 67 69 76 65 20 6f lf and forgive o
00e0: 74 68 65 72 73 2e 0a 2a 2a 20 20 20 20 4d 61 79 thers..** May
00f0: 20 79 6f 75 20 73 68 61 72 65 20 66 72 65 65 6c you share freel
0100: 79 2c 20 6e 65 76 65 72 20 74 61 6b 69 6e 67 20 y, never taking
0110: 6d 6f 72 65 20 74 68 61 6e 20 79 6f 75 20 67 69 more than you gi
0120: 76 65 2e 0a 2a 2a 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a ve..**.*********
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0170: 2a 2a 2a 2a 2a 0a 2a 2a 0a 2a 2a 20 49 6e 74 65 *****.**.** Inte
0180: 72 66 61 63 65 73 20 74 6f 20 65 78 74 65 6e 64 rfaces to extend
0190: 20 46 54 53 35 2e 20 55 73 69 6e 67 20 74 68 65 FTS5. Using the
01a0: 20 69 6e 74 65 72 66 61 63 65 73 20 64 65 66 69 interfaces defi
01b0: 6e 65 64 20 69 6e 20 74 68 69 73 20 66 69 6c 65 ned in this file
01c0: 2c 20 0a 2a 2a 20 46 54 53 35 20 6d 61 79 20 62 , .** FTS5 may b
01d0: 65 20 65 78 74 65 6e 64 65 64 20 77 69 74 68 3a e extended with:
01e0: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 2a 20 63 75 73 .**.** * cus
01f0: 74 6f 6d 20 74 6f 6b 65 6e 69 7a 65 72 73 2c 20 tom tokenizers,
0200: 61 6e 64 0a 2a 2a 20 20 20 20 20 2a 20 63 75 73 and.** * cus
0210: 74 6f 6d 20 61 75 78 69 6c 69 61 72 79 20 66 75 tom auxiliary fu
0220: 6e 63 74 69 6f 6e 73 2e 0a 2a 2f 0a 0a 0a 23 69 nctions..*/...#i
0230: 66 6e 64 65 66 20 5f 46 54 53 35 5f 48 0a 23 64 fndef _FTS5_H.#d
0240: 65 66 69 6e 65 20 5f 46 54 53 35 5f 48 0a 0a 23 efine _FTS5_H..#
0250: 69 6e 63 6c 75 64 65 20 22 73 71 6c 69 74 65 33 include "sqlite3
0260: 2e 68 22 0a 0a 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .h"../**********
0270: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0280: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0290: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
02a0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a ***************.
02b0: 2a 2a 20 43 55 53 54 4f 4d 20 41 55 58 49 4c 49 ** CUSTOM AUXILI
02c0: 41 52 59 20 46 55 4e 43 54 49 4f 4e 53 0a 2a 2a ARY FUNCTIONS.**
02d0: 0a 2a 2a 20 56 69 72 74 75 61 6c 20 74 61 62 6c .** Virtual tabl
02e0: 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e e implementation
02f0: 73 20 6d 61 79 20 6f 76 65 72 6c 6f 61 64 20 53 s may overload S
0300: 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 62 79 20 QL functions by
0310: 69 6d 70 6c 65 6d 65 6e 74 69 6e 67 0a 2a 2a 20 implementing.**
0320: 74 68 65 20 73 71 6c 69 74 65 33 5f 6d 6f 64 75 the sqlite3_modu
0330: 6c 65 2e 78 46 69 6e 64 46 75 6e 63 74 69 6f 6e le.xFindFunction
0340: 28 29 20 6d 65 74 68 6f 64 2e 0a 2a 2f 0a 0a 74 () method..*/..t
0350: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 74 ypedef struct Ft
0360: 73 35 45 78 74 65 6e 73 69 6f 6e 41 70 69 20 46 s5ExtensionApi F
0370: 74 73 35 45 78 74 65 6e 73 69 6f 6e 41 70 69 3b ts5ExtensionApi;
0380: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
0390: 46 74 73 35 43 6f 6e 74 65 78 74 20 46 74 73 35 Fts5Context Fts5
03a0: 43 6f 6e 74 65 78 74 3b 0a 0a 74 79 70 65 64 65 Context;..typede
03b0: 66 20 76 6f 69 64 20 28 2a 66 74 73 35 5f 65 78 f void (*fts5_ex
03c0: 74 65 6e 73 69 6f 6e 5f 66 75 6e 63 74 69 6f 6e tension_function
03d0: 29 28 0a 20 20 63 6f 6e 73 74 20 46 74 73 35 45 )(. const Fts5E
03e0: 78 74 65 6e 73 69 6f 6e 41 70 69 20 2a 70 41 70 xtensionApi *pAp
03f0: 69 2c 20 20 20 2f 2a 20 41 50 49 20 6f 66 66 65 i, /* API offe
0400: 72 65 64 20 62 79 20 63 75 72 72 65 6e 74 20 46 red by current F
0410: 54 53 20 76 65 72 73 69 6f 6e 20 2a 2f 0a 20 20 TS version */.
0420: 46 74 73 35 43 6f 6e 74 65 78 74 20 2a 70 46 74 Fts5Context *pFt
0430: 73 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 s,
0440: 2f 2a 20 46 69 72 73 74 20 61 72 67 20 74 6f 20 /* First arg to
0450: 70 61 73 73 20 74 6f 20 70 41 70 69 20 66 75 6e pass to pApi fun
0460: 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 73 71 6c 69 ctions */. sqli
0470: 74 65 33 5f 63 6f 6e 74 65 78 74 20 2a 70 43 74 te3_context *pCt
0480: 78 2c 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 x, /* C
0490: 6f 6e 74 65 78 74 20 66 6f 72 20 72 65 74 75 72 ontext for retur
04a0: 6e 69 6e 67 20 72 65 73 75 6c 74 2f 65 72 72 6f ning result/erro
04b0: 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 61 6c 2c r */. int nVal,
04c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
04d0: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
04e0: 20 6f 66 20 76 61 6c 75 65 73 20 69 6e 20 61 70 of values in ap
04f0: 56 61 6c 5b 5d 20 61 72 72 61 79 20 2a 2f 0a 20 Val[] array */.
0500: 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a sqlite3_value *
0510: 2a 61 70 56 61 6c 20 20 20 20 20 20 20 20 20 20 *apVal
0520: 20 2f 2a 20 41 72 72 61 79 20 6f 66 20 74 72 61 /* Array of tra
0530: 69 6c 69 6e 67 20 61 72 67 75 6d 65 6e 74 73 20 iling arguments
0540: 2a 2f 0a 29 3b 0a 0a 2f 2a 0a 2a 2a 20 45 58 54 */.);../*.** EXT
0550: 45 4e 53 49 4f 4e 20 41 50 49 20 46 55 4e 43 54 ENSION API FUNCT
0560: 49 4f 4e 53 0a 2a 2a 0a 2a 2a 20 78 55 73 65 72 IONS.**.** xUser
0570: 44 61 74 61 28 70 46 74 73 29 3a 0a 2a 2a 20 20 Data(pFts):.**
0580: 20 52 65 74 75 72 6e 20 61 20 63 6f 70 79 20 6f Return a copy o
0590: 66 20 74 68 65 20 63 6f 6e 74 65 78 74 20 70 6f f the context po
05a0: 69 6e 74 65 72 20 74 68 65 20 65 78 74 65 6e 73 inter the extens
05b0: 69 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 77 61 73 ion function was
05c0: 20 0a 2a 2a 20 20 20 72 65 67 69 73 74 65 72 65 .** registere
05d0: 64 20 77 69 74 68 2e 0a 2a 2a 0a 2a 2a 20 78 43 d with..**.** xC
05e0: 6f 6c 75 6d 6e 54 6f 74 61 6c 53 69 7a 65 28 70 olumnTotalSize(p
05f0: 46 74 73 2c 20 69 43 6f 6c 2c 20 70 6e 54 6f 6b Fts, iCol, pnTok
0600: 65 6e 29 3a 0a 2a 2a 20 20 20 49 66 20 70 61 72 en):.** If par
0610: 61 6d 65 74 65 72 20 69 43 6f 6c 20 69 73 20 6c ameter iCol is l
0620: 65 73 73 20 74 68 61 6e 20 7a 65 72 6f 2c 20 73 ess than zero, s
0630: 65 74 20 6f 75 74 70 75 74 20 76 61 72 69 61 62 et output variab
0640: 6c 65 20 2a 70 6e 54 6f 6b 65 6e 0a 2a 2a 20 20 le *pnToken.**
0650: 20 74 6f 20 74 68 65 20 74 6f 74 61 6c 20 6e 75 to the total nu
0660: 6d 62 65 72 20 6f 66 20 74 6f 6b 65 6e 73 20 69 mber of tokens i
0670: 6e 20 74 68 65 20 46 54 53 35 20 74 61 62 6c 65 n the FTS5 table
0680: 2e 20 4f 72 2c 20 69 66 20 69 43 6f 6c 20 69 73 . Or, if iCol is
0690: 0a 2a 2a 20 20 20 6e 6f 6e 2d 6e 65 67 61 74 69 .** non-negati
06a0: 76 65 20 62 75 74 20 6c 65 73 73 20 74 68 61 6e ve but less than
06b0: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 the number of c
06c0: 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 74 61 olumns in the ta
06d0: 62 6c 65 2c 20 72 65 74 75 72 6e 0a 2a 2a 20 20 ble, return.**
06e0: 20 74 68 65 20 74 6f 74 61 6c 20 6e 75 6d 62 65 the total numbe
06f0: 72 20 6f 66 20 74 6f 6b 65 6e 73 20 69 6e 20 63 r of tokens in c
0700: 6f 6c 75 6d 6e 20 69 43 6f 6c 2c 20 63 6f 6e 73 olumn iCol, cons
0710: 69 64 65 72 69 6e 67 20 61 6c 6c 20 72 6f 77 73 idering all rows
0720: 20 69 6e 20 0a 2a 2a 20 20 20 74 68 65 20 46 54 in .** the FT
0730: 53 35 20 74 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 S5 table..**.**
0740: 20 20 49 66 20 70 61 72 61 6d 65 74 65 72 20 69 If parameter i
0750: 43 6f 6c 20 69 73 20 67 72 65 61 74 65 72 20 74 Col is greater t
0760: 68 61 6e 20 6f 72 20 65 71 75 61 6c 20 74 6f 20 han or equal to
0770: 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 6f the number of co
0780: 6c 75 6d 6e 73 0a 2a 2a 20 20 20 69 6e 20 74 68 lumns.** in th
0790: 65 20 74 61 62 6c 65 2c 20 53 51 4c 49 54 45 5f e table, SQLITE_
07a0: 52 41 4e 47 45 20 69 73 20 72 65 74 75 72 6e 65 RANGE is returne
07b0: 64 2e 20 4f 72 2c 20 69 66 20 61 6e 20 65 72 72 d. Or, if an err
07c0: 6f 72 20 6f 63 63 75 72 73 20 28 65 2e 67 2e 0a or occurs (e.g..
07d0: 2a 2a 20 20 20 61 6e 20 4f 4f 4d 20 63 6f 6e 64 ** an OOM cond
07e0: 69 74 69 6f 6e 20 6f 72 20 49 4f 20 65 72 72 6f ition or IO erro
07f0: 72 29 2c 20 61 6e 20 61 70 70 72 6f 70 72 69 61 r), an appropria
0800: 74 65 20 53 51 4c 69 74 65 20 65 72 72 6f 72 20 te SQLite error
0810: 63 6f 64 65 20 69 73 20 0a 2a 2a 20 20 20 72 65 code is .** re
0820: 74 75 72 6e 65 64 2e 0a 2a 2a 0a 2a 2a 20 78 43 turned..**.** xC
0830: 6f 6c 75 6d 6e 43 6f 75 6e 74 3a 0a 2a 2a 20 20 olumnCount:.**
0840: 20 52 65 74 75 72 6e 73 20 74 68 65 20 6e 75 6d Returns the num
0850: 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 ber of columns i
0860: 6e 20 74 68 65 20 46 54 53 35 20 74 61 62 6c 65 n the FTS5 table
0870: 2e 0a 2a 2a 0a 2a 2a 20 78 43 6f 6c 75 6d 6e 53 ..**.** xColumnS
0880: 69 7a 65 3a 0a 2a 2a 20 20 20 52 65 70 6f 72 74 ize:.** Report
0890: 73 20 74 68 65 20 73 69 7a 65 20 69 6e 20 74 6f s the size in to
08a0: 6b 65 6e 73 20 6f 66 20 61 20 63 6f 6c 75 6d 6e kens of a column
08b0: 20 76 61 6c 75 65 20 66 72 6f 6d 20 74 68 65 20 value from the
08c0: 63 75 72 72 65 6e 74 20 72 6f 77 2e 0a 2a 2a 0a current row..**.
08d0: 2a 2a 20 78 43 6f 6c 75 6d 6e 54 65 78 74 3a 0a ** xColumnText:.
08e0: 2a 2a 20 20 20 52 65 70 6f 72 74 73 20 74 68 65 ** Reports the
08f0: 20 73 69 7a 65 20 69 6e 20 74 6f 6b 65 6e 73 20 size in tokens
0900: 6f 66 20 61 20 63 6f 6c 75 6d 6e 20 76 61 6c 75 of a column valu
0910: 65 20 66 72 6f 6d 20 74 68 65 20 63 75 72 72 65 e from the curre
0920: 6e 74 20 72 6f 77 2e 0a 2a 2a 0a 2a 2a 20 78 50 nt row..**.** xP
0930: 68 72 61 73 65 43 6f 75 6e 74 3a 0a 2a 2a 20 20 hraseCount:.**
0940: 20 52 65 74 75 72 6e 73 20 74 68 65 20 6e 75 6d Returns the num
0950: 62 65 72 20 6f 66 20 70 68 72 61 73 65 73 20 69 ber of phrases i
0960: 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 71 75 n the current qu
0970: 65 72 79 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a ery expression..
0980: 2a 2a 0a 2a 2a 20 78 50 68 72 61 73 65 53 69 7a **.** xPhraseSiz
0990: 65 3a 0a 2a 2a 20 20 20 52 65 74 75 72 6e 73 20 e:.** Returns
09a0: 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 74 6f the number of to
09b0: 6b 65 6e 73 20 69 6e 20 70 68 72 61 73 65 20 69 kens in phrase i
09c0: 50 68 72 61 73 65 20 6f 66 20 74 68 65 20 71 75 Phrase of the qu
09d0: 65 72 79 2e 20 50 68 72 61 73 65 73 0a 2a 2a 20 ery. Phrases.**
09e0: 20 20 61 72 65 20 6e 75 6d 62 65 72 65 64 20 73 are numbered s
09f0: 74 61 72 74 69 6e 67 20 66 72 6f 6d 20 7a 65 72 tarting from zer
0a00: 6f 2e 0a 2a 2a 0a 2a 2a 20 78 49 6e 73 74 43 6f o..**.** xInstCo
0a10: 75 6e 74 3a 0a 2a 2a 20 20 20 53 65 74 20 2a 70 unt:.** Set *p
0a20: 6e 49 6e 73 74 20 74 6f 20 74 68 65 20 74 6f 74 nInst to the tot
0a30: 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 6f 63 63 al number of occ
0a40: 75 72 72 65 6e 63 65 73 20 6f 66 20 61 6c 6c 20 urrences of all
0a50: 70 68 72 61 73 65 73 20 77 69 74 68 69 6e 0a 2a phrases within.*
0a60: 2a 20 20 20 74 68 65 20 71 75 65 72 79 20 77 69 * the query wi
0a70: 74 68 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 thin the current
0a80: 20 72 6f 77 2e 20 52 65 74 75 72 6e 20 53 51 4c row. Return SQL
0a90: 49 54 45 5f 4f 4b 20 69 66 20 73 75 63 63 65 73 ITE_OK if succes
0aa0: 73 66 75 6c 2c 20 6f 72 0a 2a 2a 20 20 20 61 6e sful, or.** an
0ab0: 20 65 72 72 6f 72 20 63 6f 64 65 20 28 69 2e 65 error code (i.e
0ac0: 2e 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 29 20 . SQLITE_NOMEM)
0ad0: 69 66 20 61 6e 20 65 72 72 6f 72 20 6f 63 63 75 if an error occu
0ae0: 72 73 2e 0a 2a 2a 0a 2a 2a 20 78 49 6e 73 74 3a rs..**.** xInst:
0af0: 0a 2a 2a 20 20 20 51 75 65 72 79 20 66 6f 72 20 .** Query for
0b00: 74 68 65 20 64 65 74 61 69 6c 73 20 6f 66 20 70 the details of p
0b10: 68 72 61 73 65 20 6d 61 74 63 68 20 69 49 64 78 hrase match iIdx
0b20: 20 77 69 74 68 69 6e 20 74 68 65 20 63 75 72 72 within the curr
0b30: 65 6e 74 20 72 6f 77 2e 0a 2a 2a 20 20 20 50 68 ent row..** Ph
0b40: 72 61 73 65 20 6d 61 74 63 68 65 73 20 61 72 65 rase matches are
0b50: 20 6e 75 6d 62 65 72 65 64 20 73 74 61 72 74 69 numbered starti
0b60: 6e 67 20 66 72 6f 6d 20 7a 65 72 6f 2c 20 73 6f ng from zero, so
0b70: 20 74 68 65 20 69 49 64 78 20 61 72 67 75 6d 65 the iIdx argume
0b80: 6e 74 0a 2a 2a 20 20 20 73 68 6f 75 6c 64 20 62 nt.** should b
0b90: 65 20 67 72 65 61 74 65 72 20 74 68 61 6e 20 6f e greater than o
0ba0: 72 20 65 71 75 61 6c 20 74 6f 20 7a 65 72 6f 20 r equal to zero
0bb0: 61 6e 64 20 73 6d 61 6c 6c 65 72 20 74 68 61 6e and smaller than
0bc0: 20 74 68 65 20 76 61 6c 75 65 0a 2a 2a 20 20 20 the value.**
0bd0: 6f 75 74 70 75 74 20 62 79 20 78 49 6e 73 74 43 output by xInstC
0be0: 6f 75 6e 74 28 29 2e 0a 2a 2a 0a 2a 2a 20 20 20 ount()..**.**
0bf0: 52 65 74 75 72 6e 73 20 53 51 4c 49 54 45 5f 4f Returns SQLITE_O
0c00: 4b 20 69 66 20 73 75 63 63 65 73 73 66 75 6c 2c K if successful,
0c10: 20 6f 72 20 61 6e 20 65 72 72 6f 72 20 63 6f 64 or an error cod
0c20: 65 20 28 69 2e 65 2e 20 53 51 4c 49 54 45 5f 4e e (i.e. SQLITE_N
0c30: 4f 4d 45 4d 29 20 0a 2a 2a 20 20 20 69 66 20 61 OMEM) .** if a
0c40: 6e 20 65 72 72 6f 72 20 6f 63 63 75 72 73 2e 0a n error occurs..
0c50: 2a 2a 0a 2a 2a 20 78 52 6f 77 69 64 3a 0a 2a 2a **.** xRowid:.**
0c60: 20 20 20 52 65 74 75 72 6e 73 20 74 68 65 20 72 Returns the r
0c70: 6f 77 69 64 20 6f 66 20 74 68 65 20 63 75 72 72 owid of the curr
0c80: 65 6e 74 20 72 6f 77 2e 0a 2a 2a 0a 2a 2a 20 78 ent row..**.** x
0c90: 54 6f 6b 65 6e 69 7a 65 3a 0a 2a 2a 20 20 20 54 Tokenize:.** T
0ca0: 6f 6b 65 6e 69 7a 65 20 74 65 78 74 20 75 73 69 okenize text usi
0cb0: 6e 67 20 74 68 65 20 74 6f 6b 65 6e 69 7a 65 72 ng the tokenizer
0cc0: 20 62 65 6c 6f 6e 67 69 6e 67 20 74 6f 20 74 68 belonging to th
0cd0: 65 20 46 54 53 35 20 74 61 62 6c 65 2e 0a 2a 2a e FTS5 table..**
0ce0: 0a 2a 2a 20 78 51 75 65 72 79 50 68 72 61 73 65 .** xQueryPhrase
0cf0: 28 70 46 74 73 35 2c 20 69 50 68 72 61 73 65 2c (pFts5, iPhrase,
0d00: 20 70 55 73 65 72 44 61 74 61 2c 20 78 43 61 6c pUserData, xCal
0d10: 6c 62 61 63 6b 29 3a 0a 2a 2a 20 20 20 54 68 69 lback):.** Thi
0d20: 73 20 41 50 49 20 66 75 6e 63 74 69 6f 6e 20 69 s API function i
0d30: 73 20 75 73 65 64 20 74 6f 20 71 75 65 72 79 20 s used to query
0d40: 74 68 65 20 46 54 53 20 74 61 62 6c 65 20 66 6f the FTS table fo
0d50: 72 20 70 68 72 61 73 65 20 69 50 68 72 61 73 65 r phrase iPhrase
0d60: 0a 2a 2a 20 20 20 6f 66 20 74 68 65 20 63 75 72 .** of the cur
0d70: 72 65 6e 74 20 71 75 65 72 79 2e 20 53 70 65 63 rent query. Spec
0d80: 69 66 69 63 61 6c 6c 79 2c 20 61 20 71 75 65 72 ifically, a quer
0d90: 79 20 65 71 75 69 76 61 6c 65 6e 74 20 74 6f 3a y equivalent to:
0da0: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 2e 2e 2e .**.** ...
0db0: 20 46 52 4f 4d 20 66 74 73 74 61 62 6c 65 20 57 FROM ftstable W
0dc0: 48 45 52 45 20 66 74 73 74 61 62 6c 65 20 4d 41 HERE ftstable MA
0dd0: 54 43 48 20 24 70 20 4f 52 44 45 52 20 42 59 20 TCH $p ORDER BY
0de0: 72 6f 77 69 64 0a 2a 2a 0a 2a 2a 20 20 20 77 69 rowid.**.** wi
0df0: 74 68 20 24 70 20 73 65 74 20 74 6f 20 61 20 70 th $p set to a p
0e00: 68 72 61 73 65 20 65 71 75 69 76 61 6c 65 6e 74 hrase equivalent
0e10: 20 74 6f 20 74 68 65 20 70 68 72 61 73 65 20 69 to the phrase i
0e20: 50 68 72 61 73 65 20 6f 66 20 74 68 65 0a 2a 2a Phrase of the.**
0e30: 20 20 20 63 75 72 72 65 6e 74 20 71 75 65 72 79 current query
0e40: 20 69 73 20 65 78 65 63 75 74 65 64 2e 20 46 6f is executed. Fo
0e50: 72 20 65 61 63 68 20 72 6f 77 20 76 69 73 69 74 r each row visit
0e60: 65 64 2c 20 74 68 65 20 63 61 6c 6c 62 61 63 6b ed, the callback
0e70: 20 66 75 6e 63 74 69 6f 6e 0a 2a 2a 20 20 20 70 function.** p
0e80: 61 73 73 65 64 20 61 73 20 74 68 65 20 66 6f 75 assed as the fou
0e90: 72 74 68 20 61 72 67 75 6d 65 6e 74 20 69 73 20 rth argument is
0ea0: 69 6e 76 6f 6b 65 64 2e 20 54 68 65 20 63 6f 6e invoked. The con
0eb0: 74 65 78 74 20 61 6e 64 20 41 50 49 20 6f 62 6a text and API obj
0ec0: 65 63 74 73 20 0a 2a 2a 20 20 20 70 61 73 73 65 ects .** passe
0ed0: 64 20 74 6f 20 74 68 65 20 63 61 6c 6c 62 61 63 d to the callbac
0ee0: 6b 20 66 75 6e 63 74 69 6f 6e 20 6d 61 79 20 62 k function may b
0ef0: 65 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 e used to access
0f00: 20 74 68 65 20 70 72 6f 70 65 72 74 69 65 73 20 the properties
0f10: 6f 66 0a 2a 2a 20 20 20 65 61 63 68 20 6d 61 74 of.** each mat
0f20: 63 68 65 64 20 72 6f 77 2e 20 49 6e 76 6f 6b 69 ched row. Invoki
0f30: 6e 67 20 41 70 69 2e 78 55 73 65 72 44 61 74 61 ng Api.xUserData
0f40: 28 29 20 72 65 74 75 72 6e 73 20 61 20 63 6f 70 () returns a cop
0f50: 79 20 6f 66 20 74 68 65 20 70 6f 69 6e 74 65 72 y of the pointer
0f60: 0a 2a 2a 20 20 20 70 61 73 73 65 64 20 61 73 20 .** passed as
0f70: 74 68 65 20 74 68 69 72 64 20 61 72 67 75 6d 65 the third argume
0f80: 6e 74 20 74 6f 20 70 55 73 65 72 44 61 74 61 2e nt to pUserData.
0f90: 0a 2a 2a 0a 2a 2a 20 20 20 49 66 20 74 68 65 20 .**.** If the
0fa0: 63 61 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f callback functio
0fb0: 6e 20 72 65 74 75 72 6e 73 20 61 6e 79 20 76 61 n returns any va
0fc0: 6c 75 65 20 6f 74 68 65 72 20 74 68 61 6e 20 53 lue other than S
0fd0: 51 4c 49 54 45 5f 4f 4b 2c 20 74 68 65 0a 2a 2a QLITE_OK, the.**
0fe0: 20 20 20 71 75 65 72 79 20 69 73 20 61 62 61 6e query is aban
0ff0: 64 6f 6e 65 64 20 61 6e 64 20 74 68 65 20 78 51 doned and the xQ
1000: 75 65 72 79 50 68 72 61 73 65 20 66 75 6e 63 74 ueryPhrase funct
1010: 69 6f 6e 20 72 65 74 75 72 6e 73 20 69 6d 6d 65 ion returns imme
1020: 64 69 61 74 65 6c 79 2e 0a 2a 2a 20 20 20 49 66 diately..** If
1030: 20 74 68 65 20 72 65 74 75 72 6e 65 64 20 76 61 the returned va
1040: 6c 75 65 20 69 73 20 53 51 4c 49 54 45 5f 44 4f lue is SQLITE_DO
1050: 4e 45 2c 20 78 51 75 65 72 79 50 68 72 61 73 65 NE, xQueryPhrase
1060: 20 72 65 74 75 72 6e 73 20 53 51 4c 49 54 45 5f returns SQLITE_
1070: 4f 4b 2e 0a 2a 2a 20 20 20 4f 74 68 65 72 77 69 OK..** Otherwi
1080: 73 65 2c 20 74 68 65 20 65 72 72 6f 72 20 63 6f se, the error co
1090: 64 65 20 69 73 20 70 72 6f 70 61 67 61 74 65 64 de is propagated
10a0: 20 75 70 77 61 72 64 73 2e 0a 2a 2a 0a 2a 2a 20 upwards..**.**
10b0: 20 20 49 66 20 74 68 65 20 71 75 65 72 79 20 72 If the query r
10c0: 75 6e 73 20 74 6f 20 63 6f 6d 70 6c 65 74 69 6f uns to completio
10d0: 6e 20 77 69 74 68 6f 75 74 20 69 6e 63 69 64 65 n without incide
10e0: 6e 74 2c 20 53 51 4c 49 54 45 5f 4f 4b 20 69 73 nt, SQLITE_OK is
10f0: 20 72 65 74 75 72 6e 65 64 2e 0a 2a 2a 20 20 20 returned..**
1100: 4f 72 2c 20 69 66 20 73 6f 6d 65 20 65 72 72 6f Or, if some erro
1110: 72 20 6f 63 63 75 72 73 20 62 65 66 6f 72 65 20 r occurs before
1120: 74 68 65 20 71 75 65 72 79 20 63 6f 6d 70 6c 65 the query comple
1130: 74 65 73 20 6f 72 20 69 73 20 61 62 6f 72 74 65 tes or is aborte
1140: 64 20 62 79 0a 2a 2a 20 20 20 74 68 65 20 63 61 d by.** the ca
1150: 6c 6c 62 61 63 6b 2c 20 61 6e 20 53 51 4c 69 74 llback, an SQLit
1160: 65 20 65 72 72 6f 72 20 63 6f 64 65 20 69 73 20 e error code is
1170: 72 65 74 75 72 6e 65 64 2e 0a 2a 2a 0a 2a 2a 0a returned..**.**.
1180: 2a 2a 20 78 53 65 74 41 75 78 64 61 74 61 28 70 ** xSetAuxdata(p
1190: 46 74 73 35 2c 20 70 41 75 78 2c 20 78 44 65 6c Fts5, pAux, xDel
11a0: 65 74 65 29 0a 2a 2a 0a 2a 2a 20 20 20 53 61 76 ete).**.** Sav
11b0: 65 20 74 68 65 20 70 6f 69 6e 74 65 72 20 70 61 e the pointer pa
11c0: 73 73 65 64 20 61 73 20 74 68 65 20 73 65 63 6f ssed as the seco
11d0: 6e 64 20 61 72 67 75 6d 65 6e 74 20 61 73 20 74 nd argument as t
11e0: 68 65 20 65 78 74 65 6e 73 69 6f 6e 20 66 75 6e he extension fun
11f0: 63 74 69 6f 6e 73 20 0a 2a 2a 20 20 20 22 61 75 ctions .** "au
1200: 78 69 6c 69 61 72 79 20 64 61 74 61 22 2e 20 54 xiliary data". T
1210: 68 65 20 70 6f 69 6e 74 65 72 20 6d 61 79 20 74 he pointer may t
1220: 68 65 6e 20 62 65 20 72 65 74 72 69 65 76 65 64 hen be retrieved
1230: 20 62 79 20 74 68 65 20 63 75 72 72 65 6e 74 20 by the current
1240: 6f 72 20 61 6e 79 0a 2a 2a 20 20 20 66 75 74 75 or any.** futu
1250: 72 65 20 69 6e 76 6f 63 61 74 69 6f 6e 20 6f 66 re invocation of
1260: 20 74 68 65 20 73 61 6d 65 20 66 74 73 35 20 65 the same fts5 e
1270: 78 74 65 6e 73 69 6f 6e 20 66 75 6e 63 74 69 6f xtension functio
1280: 6e 20 6d 61 64 65 20 61 73 20 70 61 72 74 20 6f n made as part o
1290: 66 0a 2a 2a 20 20 20 6f 66 20 74 68 65 20 73 61 f.** of the sa
12a0: 6d 65 20 4d 41 54 43 48 20 71 75 65 72 79 20 75 me MATCH query u
12b0: 73 69 6e 67 20 74 68 65 20 78 47 65 74 41 75 78 sing the xGetAux
12c0: 64 61 74 61 28 29 20 41 50 49 2e 0a 2a 2a 0a 2a data() API..**.*
12d0: 2a 20 20 20 45 61 63 68 20 65 78 74 65 6e 73 69 * Each extensi
12e0: 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 61 on function is a
12f0: 6c 6c 6f 63 61 74 65 64 20 61 20 73 69 6e 67 6c llocated a singl
1300: 65 20 61 75 78 69 6c 69 61 72 79 20 64 61 74 61 e auxiliary data
1310: 20 73 6c 6f 74 20 66 6f 72 0a 2a 2a 20 20 20 65 slot for.** e
1320: 61 63 68 20 46 54 53 20 71 75 65 72 79 20 28 4d ach FTS query (M
1330: 41 54 43 48 20 65 78 70 72 65 73 73 69 6f 6e 29 ATCH expression)
1340: 2e 20 49 66 20 74 68 65 20 65 78 74 65 6e 73 69 . If the extensi
1350: 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 69 on function is i
1360: 6e 76 6f 6b 65 64 20 0a 2a 2a 20 20 20 6d 6f 72 nvoked .** mor
1370: 65 20 74 68 61 6e 20 6f 6e 63 65 20 66 6f 72 20 e than once for
1380: 61 20 73 69 6e 67 6c 65 20 46 54 53 20 71 75 65 a single FTS que
1390: 72 79 2c 20 74 68 65 6e 20 61 6c 6c 20 69 6e 76 ry, then all inv
13a0: 6f 63 61 74 69 6f 6e 73 20 73 68 61 72 65 20 61 ocations share a
13b0: 20 0a 2a 2a 20 20 20 73 69 6e 67 6c 65 20 61 75 .** single au
13c0: 78 69 6c 69 61 72 79 20 64 61 74 61 20 63 6f 6e xiliary data con
13d0: 74 65 78 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 49 66 text..**.** If
13e0: 20 74 68 65 72 65 20 69 73 20 61 6c 72 65 61 64 there is alread
13f0: 79 20 61 6e 20 61 75 78 69 6c 69 61 72 79 20 64 y an auxiliary d
1400: 61 74 61 20 70 6f 69 6e 74 65 72 20 77 68 65 6e ata pointer when
1410: 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 this function i
1420: 73 0a 2a 2a 20 20 20 69 6e 76 6f 6b 65 64 2c 20 s.** invoked,
1430: 74 68 65 6e 20 69 74 20 69 73 20 72 65 70 6c 61 then it is repla
1440: 63 65 64 20 62 79 20 74 68 65 20 6e 65 77 20 70 ced by the new p
1450: 6f 69 6e 74 65 72 2e 20 49 66 20 61 6e 20 78 44 ointer. If an xD
1460: 65 6c 65 74 65 20 63 61 6c 6c 62 61 63 6b 0a 2a elete callback.*
1470: 2a 20 20 20 77 61 73 20 73 70 65 63 69 66 69 65 * was specifie
1480: 64 20 61 6c 6f 6e 67 20 77 69 74 68 20 74 68 65 d along with the
1490: 20 6f 72 69 67 69 6e 61 6c 20 70 6f 69 6e 74 65 original pointe
14a0: 72 2c 20 69 74 20 69 73 20 69 6e 76 6f 6b 65 64 r, it is invoked
14b0: 20 61 74 20 74 68 69 73 0a 2a 2a 20 20 20 70 6f at this.** po
14c0: 69 6e 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 54 68 65 int..**.** The
14d0: 20 78 44 65 6c 65 74 65 20 63 61 6c 6c 62 61 63 xDelete callbac
14e0: 6b 2c 20 69 66 20 6f 6e 65 20 69 73 20 73 70 65 k, if one is spe
14f0: 63 69 66 69 65 64 2c 20 69 73 20 61 6c 73 6f 20 cified, is also
1500: 69 6e 76 6f 6b 65 64 20 6f 6e 20 74 68 65 0a 2a invoked on the.*
1510: 2a 20 20 20 61 75 78 69 6c 69 61 72 79 20 64 61 * auxiliary da
1520: 74 61 20 70 6f 69 6e 74 65 72 20 61 66 74 65 72 ta pointer after
1530: 20 74 68 65 20 46 54 53 35 20 71 75 65 72 79 20 the FTS5 query
1540: 68 61 73 20 66 69 6e 69 73 68 65 64 2e 0a 2a 2a has finished..**
1550: 0a 2a 2a 20 20 20 49 66 20 61 6e 20 65 72 72 6f .** If an erro
1560: 72 20 28 65 2e 67 2e 20 61 6e 20 4f 4f 4d 20 63 r (e.g. an OOM c
1570: 6f 6e 64 69 74 69 6f 6e 29 20 6f 63 63 75 72 73 ondition) occurs
1580: 20 77 69 74 68 69 6e 20 74 68 69 73 20 66 75 6e within this fun
1590: 63 74 69 6f 6e 2c 20 61 6e 0a 2a 2a 20 20 20 74 ction, an.** t
15a0: 68 65 20 61 75 78 69 6c 69 61 72 79 20 64 61 74 he auxiliary dat
15b0: 61 20 69 73 20 73 65 74 20 74 6f 20 4e 55 4c 4c a is set to NULL
15c0: 20 61 6e 64 20 61 6e 20 65 72 72 6f 72 20 63 6f and an error co
15d0: 64 65 20 72 65 74 75 72 6e 65 64 2e 20 49 66 20 de returned. If
15e0: 74 68 65 0a 2a 2a 20 20 20 78 44 65 6c 65 74 65 the.** xDelete
15f0: 20 70 61 72 61 6d 65 74 65 72 20 77 61 73 20 6e parameter was n
1600: 6f 74 20 4e 55 4c 4c 2c 20 69 74 20 69 73 20 69 ot NULL, it is i
1610: 6e 76 6f 6b 65 64 20 6f 6e 20 74 68 65 20 61 75 nvoked on the au
1620: 78 69 6c 69 61 72 79 20 64 61 74 61 0a 2a 2a 20 xiliary data.**
1630: 20 20 70 6f 69 6e 74 65 72 20 62 65 66 6f 72 65 pointer before
1640: 20 72 65 74 75 72 6e 69 6e 67 2e 0a 2a 2a 0a 2a returning..**.*
1650: 2a 0a 2a 2a 20 78 47 65 74 41 75 78 64 61 74 61 *.** xGetAuxdata
1660: 28 70 46 74 73 35 2c 20 62 43 6c 65 61 72 29 0a (pFts5, bClear).
1670: 2a 2a 0a 2a 2a 20 20 20 52 65 74 75 72 6e 73 20 **.** Returns
1680: 74 68 65 20 63 75 72 72 65 6e 74 20 61 75 78 69 the current auxi
1690: 6c 69 61 72 79 20 64 61 74 61 20 70 6f 69 6e 74 liary data point
16a0: 65 72 20 66 6f 72 20 74 68 65 20 66 74 73 35 20 er for the fts5
16b0: 65 78 74 65 6e 73 69 6f 6e 20 0a 2a 2a 20 20 20 extension .**
16c0: 66 75 6e 63 74 69 6f 6e 2e 20 53 65 65 20 74 68 function. See th
16d0: 65 20 78 53 65 74 41 75 78 64 61 74 61 28 29 20 e xSetAuxdata()
16e0: 6d 65 74 68 6f 64 20 66 6f 72 20 64 65 74 61 69 method for detai
16f0: 6c 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 49 66 20 74 ls..**.** If t
1700: 68 65 20 62 43 6c 65 61 72 20 61 72 67 75 6d 65 he bClear argume
1710: 6e 74 20 69 73 20 6e 6f 6e 2d 7a 65 72 6f 2c 20 nt is non-zero,
1720: 74 68 65 6e 20 74 68 65 20 61 75 78 69 6c 69 61 then the auxilia
1730: 72 79 20 64 61 74 61 20 69 73 20 63 6c 65 61 72 ry data is clear
1740: 65 64 0a 2a 2a 20 20 20 28 73 65 74 20 74 6f 20 ed.** (set to
1750: 4e 55 4c 4c 29 20 62 65 66 6f 72 65 20 74 68 69 NULL) before thi
1760: 73 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72 s function retur
1770: 6e 73 2e 20 49 6e 20 74 68 69 73 20 63 61 73 65 ns. In this case
1780: 20 74 68 65 20 78 44 65 6c 65 74 65 2c 0a 2a 2a the xDelete,.**
1790: 20 20 20 69 66 20 61 6e 79 2c 20 69 73 20 6e 6f if any, is no
17a0: 74 20 69 6e 76 6f 6b 65 64 2e 0a 2a 2a 0a 2a 2a t invoked..**.**
17b0: 0a 2a 2a 20 78 52 6f 77 43 6f 75 6e 74 28 70 46 .** xRowCount(pF
17c0: 74 73 35 2c 20 70 6e 52 6f 77 29 0a 2a 2a 0a 2a ts5, pnRow).**.*
17d0: 2a 20 20 20 54 68 69 73 20 66 75 6e 63 74 69 6f * This functio
17e0: 6e 20 69 73 20 75 73 65 64 20 74 6f 20 72 65 74 n is used to ret
17f0: 72 69 65 76 65 20 74 68 65 20 74 6f 74 61 6c 20 rieve the total
1800: 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 69 number of rows i
1810: 6e 20 74 68 65 20 74 61 62 6c 65 2e 0a 2a 2a 20 n the table..**
1820: 20 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 In other words
1830: 2c 20 74 68 65 20 73 61 6d 65 20 76 61 6c 75 65 , the same value
1840: 20 74 68 61 74 20 77 6f 75 6c 64 20 62 65 20 72 that would be r
1850: 65 74 75 72 6e 65 64 20 62 79 3a 0a 2a 2a 0a 2a eturned by:.**.*
1860: 2a 20 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 * SELECT
1870: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 66 74 count(*) FROM ft
1880: 73 74 61 62 6c 65 3b 0a 2a 2f 0a 73 74 72 75 63 stable;.*/.struc
1890: 74 20 46 74 73 35 45 78 74 65 6e 73 69 6f 6e 41 t Fts5ExtensionA
18a0: 70 69 20 7b 0a 20 20 69 6e 74 20 69 56 65 72 73 pi {. int iVers
18b0: 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 ion;
18c0: 20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e /* Curren
18d0: 74 6c 79 20 61 6c 77 61 79 73 20 73 65 74 20 74 tly always set t
18e0: 6f 20 31 20 2a 2f 0a 0a 20 20 76 6f 69 64 20 2a o 1 */.. void *
18f0: 28 2a 78 55 73 65 72 44 61 74 61 29 28 46 74 73 (*xUserData)(Fts
1900: 35 43 6f 6e 74 65 78 74 2a 29 3b 0a 0a 20 20 69 5Context*);.. i
1910: 6e 74 20 28 2a 78 43 6f 6c 75 6d 6e 43 6f 75 6e nt (*xColumnCoun
1920: 74 29 28 46 74 73 35 43 6f 6e 74 65 78 74 2a 29 t)(Fts5Context*)
1930: 3b 0a 20 20 69 6e 74 20 28 2a 78 52 6f 77 43 6f ;. int (*xRowCo
1940: 75 6e 74 29 28 46 74 73 35 43 6f 6e 74 65 78 74 unt)(Fts5Context
1950: 2a 2c 20 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 *, sqlite3_int64
1960: 20 2a 70 6e 52 6f 77 29 3b 0a 20 20 69 6e 74 20 *pnRow);. int
1970: 28 2a 78 43 6f 6c 75 6d 6e 54 6f 74 61 6c 53 69 (*xColumnTotalSi
1980: 7a 65 29 28 46 74 73 35 43 6f 6e 74 65 78 74 2a ze)(Fts5Context*
1990: 2c 20 69 6e 74 20 69 43 6f 6c 2c 20 73 71 6c 69 , int iCol, sqli
19a0: 74 65 33 5f 69 6e 74 36 34 20 2a 70 6e 54 6f 6b te3_int64 *pnTok
19b0: 65 6e 29 3b 0a 0a 20 20 69 6e 74 20 28 2a 78 54 en);.. int (*xT
19c0: 6f 6b 65 6e 69 7a 65 29 28 46 74 73 35 43 6f 6e okenize)(Fts5Con
19d0: 74 65 78 74 2a 2c 20 0a 20 20 20 20 63 6f 6e 73 text*, . cons
19e0: 74 20 63 68 61 72 20 2a 70 54 65 78 74 2c 20 69 t char *pText, i
19f0: 6e 74 20 6e 54 65 78 74 2c 20 2f 2a 20 54 65 78 nt nText, /* Tex
1a00: 74 20 74 6f 20 74 6f 6b 65 6e 69 7a 65 20 2a 2f t to tokenize */
1a10: 0a 20 20 20 20 76 6f 69 64 20 2a 70 43 74 78 2c . void *pCtx,
1a20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a30: 20 20 20 2f 2a 20 43 6f 6e 74 65 78 74 20 70 61 /* Context pa
1a40: 73 73 65 64 20 74 6f 20 78 54 6f 6b 65 6e 28 29 ssed to xToken()
1a50: 20 2a 2f 0a 20 20 20 20 69 6e 74 20 28 2a 78 54 */. int (*xT
1a60: 6f 6b 65 6e 29 28 76 6f 69 64 2a 2c 20 63 6f 6e oken)(void*, con
1a70: 73 74 20 63 68 61 72 2a 2c 20 69 6e 74 2c 20 69 st char*, int, i
1a80: 6e 74 2c 20 69 6e 74 29 20 20 20 20 20 20 20 2f nt, int) /
1a90: 2a 20 43 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 * Callback */.
1aa0: 29 3b 0a 0a 20 20 69 6e 74 20 28 2a 78 50 68 72 );.. int (*xPhr
1ab0: 61 73 65 43 6f 75 6e 74 29 28 46 74 73 35 43 6f aseCount)(Fts5Co
1ac0: 6e 74 65 78 74 2a 29 3b 0a 20 20 69 6e 74 20 28 ntext*);. int (
1ad0: 2a 78 50 68 72 61 73 65 53 69 7a 65 29 28 46 74 *xPhraseSize)(Ft
1ae0: 73 35 43 6f 6e 74 65 78 74 2a 2c 20 69 6e 74 20 s5Context*, int
1af0: 69 50 68 72 61 73 65 29 3b 0a 0a 20 20 69 6e 74 iPhrase);.. int
1b00: 20 28 2a 78 49 6e 73 74 43 6f 75 6e 74 29 28 46 (*xInstCount)(F
1b10: 74 73 35 43 6f 6e 74 65 78 74 2a 2c 20 69 6e 74 ts5Context*, int
1b20: 20 2a 70 6e 49 6e 73 74 29 3b 0a 20 20 69 6e 74 *pnInst);. int
1b30: 20 28 2a 78 49 6e 73 74 29 28 46 74 73 35 43 6f (*xInst)(Fts5Co
1b40: 6e 74 65 78 74 2a 2c 20 69 6e 74 20 69 49 64 78 ntext*, int iIdx
1b50: 2c 20 69 6e 74 20 2a 70 69 50 68 72 61 73 65 2c , int *piPhrase,
1b60: 20 69 6e 74 20 2a 70 69 43 6f 6c 2c 20 69 6e 74 int *piCol, int
1b70: 20 2a 70 69 4f 66 66 29 3b 0a 0a 20 20 73 71 6c *piOff);.. sql
1b80: 69 74 65 33 5f 69 6e 74 36 34 20 28 2a 78 52 6f ite3_int64 (*xRo
1b90: 77 69 64 29 28 46 74 73 35 43 6f 6e 74 65 78 74 wid)(Fts5Context
1ba0: 2a 29 3b 0a 20 20 69 6e 74 20 28 2a 78 43 6f 6c *);. int (*xCol
1bb0: 75 6d 6e 54 65 78 74 29 28 46 74 73 35 43 6f 6e umnText)(Fts5Con
1bc0: 74 65 78 74 2a 2c 20 69 6e 74 20 69 43 6f 6c 2c text*, int iCol,
1bd0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2a 70 7a const char **pz
1be0: 2c 20 69 6e 74 20 2a 70 6e 29 3b 0a 20 20 69 6e , int *pn);. in
1bf0: 74 20 28 2a 78 43 6f 6c 75 6d 6e 53 69 7a 65 29 t (*xColumnSize)
1c00: 28 46 74 73 35 43 6f 6e 74 65 78 74 2a 2c 20 69 (Fts5Context*, i
1c10: 6e 74 20 69 43 6f 6c 2c 20 69 6e 74 20 2a 70 6e nt iCol, int *pn
1c20: 54 6f 6b 65 6e 29 3b 0a 0a 20 20 69 6e 74 20 28 Token);.. int (
1c30: 2a 78 51 75 65 72 79 50 68 72 61 73 65 29 28 46 *xQueryPhrase)(F
1c40: 74 73 35 43 6f 6e 74 65 78 74 2a 2c 20 69 6e 74 ts5Context*, int
1c50: 20 69 50 68 72 61 73 65 2c 20 76 6f 69 64 20 2a iPhrase, void *
1c60: 70 55 73 65 72 44 61 74 61 2c 0a 20 20 20 20 69 pUserData,. i
1c70: 6e 74 28 2a 29 28 63 6f 6e 73 74 20 46 74 73 35 nt(*)(const Fts5
1c80: 45 78 74 65 6e 73 69 6f 6e 41 70 69 2a 2c 46 74 ExtensionApi*,Ft
1c90: 73 35 43 6f 6e 74 65 78 74 2a 2c 76 6f 69 64 2a s5Context*,void*
1ca0: 29 0a 20 20 29 3b 0a 20 20 69 6e 74 20 28 2a 78 ). );. int (*x
1cb0: 53 65 74 41 75 78 64 61 74 61 29 28 46 74 73 35 SetAuxdata)(Fts5
1cc0: 43 6f 6e 74 65 78 74 2a 2c 20 76 6f 69 64 20 2a Context*, void *
1cd0: 70 41 75 78 2c 20 76 6f 69 64 28 2a 78 44 65 6c pAux, void(*xDel
1ce0: 65 74 65 29 28 76 6f 69 64 2a 29 29 3b 0a 20 20 ete)(void*));.
1cf0: 76 6f 69 64 20 2a 28 2a 78 47 65 74 41 75 78 64 void *(*xGetAuxd
1d00: 61 74 61 29 28 46 74 73 35 43 6f 6e 74 65 78 74 ata)(Fts5Context
1d10: 2a 2c 20 69 6e 74 20 62 43 6c 65 61 72 29 3b 0a *, int bClear);.
1d20: 7d 3b 0a 0a 2f 2a 20 0a 2a 2a 20 43 55 53 54 4f };../* .** CUSTO
1d30: 4d 20 41 55 58 49 4c 49 41 52 59 20 46 55 4e 43 M AUXILIARY FUNC
1d40: 54 49 4f 4e 53 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a TIONS.**********
1d50: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1d60: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1d70: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1d80: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f ***************/
1d90: 0a 0a 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ../*************
1da0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1db0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1dc0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1dd0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 2a 2a 20 ************.**
1de0: 43 55 53 54 4f 4d 20 54 4f 4b 45 4e 49 5a 45 52 CUSTOM TOKENIZER
1df0: 53 0a 2a 2a 0a 2a 2a 20 41 70 70 6c 69 63 61 74 S.**.** Applicat
1e00: 69 6f 6e 73 20 6d 61 79 20 61 6c 73 6f 20 72 65 ions may also re
1e10: 67 69 73 74 65 72 20 63 75 73 74 6f 6d 20 74 6f gister custom to
1e20: 6b 65 6e 69 7a 65 72 20 74 79 70 65 73 2e 20 41 kenizer types. A
1e30: 20 74 6f 6b 65 6e 69 7a 65 72 20 0a 2a 2a 20 69 tokenizer .** i
1e40: 73 20 72 65 67 69 73 74 65 72 65 64 20 62 79 20 s registered by
1e50: 70 72 6f 76 69 64 69 6e 67 20 66 74 73 35 20 77 providing fts5 w
1e60: 69 74 68 20 61 20 70 6f 70 75 6c 61 74 65 64 20 ith a populated
1e70: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
1e80: 0a 2a 2a 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 .** following st
1e90: 72 75 63 74 75 72 65 2e 20 41 6c 6c 20 73 74 72 ructure. All str
1ea0: 75 63 74 75 72 65 20 6d 65 74 68 6f 64 73 20 6d ucture methods m
1eb0: 75 73 74 20 62 65 20 64 65 66 69 6e 65 64 2c 20 ust be defined,
1ec0: 73 65 74 74 69 6e 67 0a 2a 2a 20 61 6e 79 20 6d setting.** any m
1ed0: 65 6d 62 65 72 20 6f 66 20 74 68 65 20 66 74 73 ember of the fts
1ee0: 35 5f 74 6f 6b 65 6e 69 7a 65 72 20 73 74 72 75 5_tokenizer stru
1ef0: 63 74 20 74 6f 20 4e 55 4c 4c 20 6c 65 61 64 73 ct to NULL leads
1f00: 20 74 6f 20 75 6e 64 65 66 69 6e 65 64 0a 2a 2a to undefined.**
1f10: 20 62 65 68 61 76 69 6f 75 72 2e 20 54 68 65 20 behaviour. The
1f20: 73 74 72 75 63 74 75 72 65 20 6d 65 74 68 6f 64 structure method
1f30: 73 20 61 72 65 20 65 78 70 65 63 74 65 64 20 74 s are expected t
1f40: 6f 20 66 75 6e 63 74 69 6f 6e 20 61 73 20 66 6f o function as fo
1f50: 6c 6c 6f 77 73 3a 0a 2a 2a 0a 2a 2a 20 78 43 72 llows:.**.** xCr
1f60: 65 61 74 65 3a 0a 2a 2a 20 20 20 54 68 69 73 20 eate:.** This
1f70: 66 75 6e 63 74 69 6f 6e 20 69 73 20 75 73 65 64 function is used
1f80: 20 74 6f 20 61 6c 6c 6f 63 61 74 65 20 61 6e 64 to allocate and
1f90: 20 69 6e 69 74 69 74 61 6c 69 7a 65 20 61 20 74 inititalize a t
1fa0: 6f 6b 65 6e 69 7a 65 72 20 69 6e 73 74 61 6e 63 okenizer instanc
1fb0: 65 2e 0a 2a 2a 20 20 20 41 20 74 6f 6b 65 6e 69 e..** A tokeni
1fc0: 7a 65 72 20 69 6e 73 74 61 6e 63 65 20 69 73 20 zer instance is
1fd0: 72 65 71 75 69 72 65 64 20 74 6f 20 61 63 74 75 required to actu
1fe0: 61 6c 6c 79 20 74 6f 6b 65 6e 69 7a 65 20 74 65 ally tokenize te
1ff0: 78 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 54 68 65 20 xt..**.** The
2000: 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 70 first argument p
2010: 61 73 73 65 64 20 74 6f 20 74 68 69 73 20 66 75 assed to this fu
2020: 6e 63 74 69 6f 6e 20 69 73 20 61 20 63 6f 70 79 nction is a copy
2030: 20 6f 66 20 74 68 65 20 28 76 6f 69 64 2a 29 0a of the (void*).
2040: 2a 2a 20 20 20 70 6f 69 6e 74 65 72 20 70 72 6f ** pointer pro
2050: 76 69 64 65 64 20 62 79 20 74 68 65 20 61 70 70 vided by the app
2060: 6c 69 63 61 74 69 6f 6e 20 77 68 65 6e 20 74 68 lication when th
2070: 65 20 66 74 73 35 5f 74 6f 6b 65 6e 69 7a 65 72 e fts5_tokenizer
2080: 20 6f 62 6a 65 63 74 0a 2a 2a 20 20 20 77 61 73 object.** was
2090: 20 72 65 67 69 73 74 65 72 65 64 20 77 69 74 68 registered with
20a0: 20 46 54 53 35 20 28 74 68 65 20 74 68 69 72 64 FTS5 (the third
20b0: 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 78 43 72 argument to xCr
20c0: 65 61 74 65 54 6f 6b 65 6e 69 7a 65 72 28 29 29 eateTokenizer())
20d0: 2e 20 0a 2a 2a 20 20 20 54 68 65 20 73 65 63 6f . .** The seco
20e0: 6e 64 20 61 6e 64 20 74 68 69 72 64 20 61 72 67 nd and third arg
20f0: 75 6d 65 6e 74 73 20 61 72 65 20 61 6e 20 61 72 uments are an ar
2100: 72 61 79 20 6f 66 20 6e 75 6c 2d 74 65 72 6d 69 ray of nul-termi
2110: 6e 61 74 65 64 20 73 74 72 69 6e 67 73 0a 2a 2a nated strings.**
2120: 20 20 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 containing th
2130: 65 20 74 6f 6b 65 6e 69 7a 65 72 20 61 72 67 75 e tokenizer argu
2140: 6d 65 6e 74 73 2c 20 69 66 20 61 6e 79 2c 20 73 ments, if any, s
2150: 70 65 63 69 66 69 65 64 20 66 6f 6c 6c 6f 77 69 pecified followi
2160: 6e 67 20 74 68 65 0a 2a 2a 20 20 20 74 6f 6b 65 ng the.** toke
2170: 6e 69 7a 65 72 20 6e 61 6d 65 20 61 73 20 70 61 nizer name as pa
2180: 72 74 20 6f 66 20 74 68 65 20 43 52 45 41 54 45 rt of the CREATE
2190: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 73 VIRTUAL TABLE s
21a0: 74 61 74 65 6d 65 6e 74 20 75 73 65 64 0a 2a 2a tatement used.**
21b0: 20 20 20 74 6f 20 63 72 65 61 74 65 20 74 68 65 to create the
21c0: 20 46 54 53 35 20 74 61 62 6c 65 2e 0a 2a 2a 0a FTS5 table..**.
21d0: 2a 2a 20 20 20 54 68 65 20 66 69 6e 61 6c 20 61 ** The final a
21e0: 72 67 75 6d 65 6e 74 20 69 73 20 61 6e 20 6f 75 rgument is an ou
21f0: 74 70 75 74 20 76 61 72 69 61 62 6c 65 2e 20 49 tput variable. I
2200: 66 20 73 75 63 63 65 73 73 66 75 6c 2c 20 28 2a f successful, (*
2210: 70 70 4f 75 74 29 20 0a 2a 2a 20 20 20 73 68 6f ppOut) .** sho
2220: 75 6c 64 20 62 65 20 73 65 74 20 74 6f 20 70 6f uld be set to po
2230: 69 6e 74 20 74 6f 20 74 68 65 20 6e 65 77 20 74 int to the new t
2240: 6f 6b 65 6e 69 7a 65 72 20 68 61 6e 64 6c 65 20 okenizer handle
2250: 61 6e 64 20 53 51 4c 49 54 45 5f 4f 4b 0a 2a 2a and SQLITE_OK.**
2260: 20 20 20 72 65 74 75 72 6e 65 64 2e 20 49 66 20 returned. If
2270: 61 6e 20 65 72 72 6f 72 20 6f 63 63 75 72 73 2c an error occurs,
2280: 20 73 6f 6d 65 20 76 61 6c 75 65 20 6f 74 68 65 some value othe
2290: 72 20 74 68 61 6e 20 53 51 4c 49 54 45 5f 4f 4b r than SQLITE_OK
22a0: 20 73 68 6f 75 6c 64 0a 2a 2a 20 20 20 62 65 20 should.** be
22b0: 72 65 74 75 72 6e 65 64 2e 20 49 6e 20 74 68 69 returned. In thi
22c0: 73 20 63 61 73 65 2c 20 66 74 73 35 20 61 73 73 s case, fts5 ass
22d0: 75 6d 65 73 20 74 68 61 74 20 74 68 65 20 66 69 umes that the fi
22e0: 6e 61 6c 20 76 61 6c 75 65 20 6f 66 20 2a 70 70 nal value of *pp
22f0: 4f 75 74 20 0a 2a 2a 20 20 20 69 73 20 75 6e 64 Out .** is und
2300: 65 66 69 6e 65 64 2e 0a 2a 2a 0a 2a 2a 20 78 44 efined..**.** xD
2310: 65 6c 65 74 65 3a 0a 2a 2a 20 20 20 54 68 69 73 elete:.** This
2320: 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 69 6e 76 function is inv
2330: 6f 6b 65 64 20 74 6f 20 64 65 6c 65 74 65 20 61 oked to delete a
2340: 20 74 6f 6b 65 6e 69 7a 65 72 20 68 61 6e 64 6c tokenizer handl
2350: 65 20 70 72 65 76 69 6f 75 73 6c 79 0a 2a 2a 20 e previously.**
2360: 20 20 61 6c 6c 6f 63 61 74 65 64 20 75 73 69 6e allocated usin
2370: 67 20 78 43 72 65 61 74 65 28 29 2e 20 46 74 73 g xCreate(). Fts
2380: 35 20 67 75 61 72 61 6e 74 65 65 73 20 74 68 61 5 guarantees tha
2390: 74 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 t this function
23a0: 77 69 6c 6c 0a 2a 2a 20 20 20 62 65 20 69 6e 76 will.** be inv
23b0: 6f 6b 65 64 20 65 78 61 63 74 6c 79 20 6f 6e 63 oked exactly onc
23c0: 65 20 66 6f 72 20 65 61 63 68 20 73 75 63 63 65 e for each succe
23d0: 73 73 66 75 6c 20 63 61 6c 6c 20 74 6f 20 78 43 ssful call to xC
23e0: 72 65 61 74 65 28 29 2e 0a 2a 2a 0a 2a 2a 20 78 reate()..**.** x
23f0: 54 6f 6b 65 6e 69 7a 65 3a 0a 2a 2a 20 20 20 54 Tokenize:.** T
2400: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 his function is
2410: 65 78 70 65 63 74 65 64 20 74 6f 20 74 6f 6b 65 expected to toke
2420: 6e 69 7a 65 20 74 68 65 20 6e 54 65 78 74 20 62 nize the nText b
2430: 79 74 65 20 73 74 72 69 6e 67 20 69 6e 64 69 63 yte string indic
2440: 61 74 65 64 20 0a 2a 2a 20 20 20 62 79 20 61 72 ated .** by ar
2450: 67 75 6d 65 6e 74 20 70 54 65 78 74 2e 20 70 54 gument pText. pT
2460: 65 78 74 20 6d 61 79 20 6e 6f 74 20 62 65 20 6e ext may not be n
2470: 75 6c 2d 74 65 72 6d 69 6e 61 74 65 64 2e 20 54 ul-terminated. T
2480: 68 65 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e he first argumen
2490: 74 0a 2a 2a 20 20 20 70 61 73 73 65 64 20 74 6f t.** passed to
24a0: 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 this function i
24b0: 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 s a pointer to a
24c0: 6e 20 46 74 73 35 54 6f 6b 65 6e 69 7a 65 72 20 n Fts5Tokenizer
24d0: 6f 62 6a 65 63 74 20 72 65 74 75 72 6e 65 64 20 object returned
24e0: 0a 2a 2a 20 20 20 62 79 20 61 6e 20 65 61 72 6c .** by an earl
24f0: 69 65 72 20 63 61 6c 6c 20 74 6f 20 78 43 72 65 ier call to xCre
2500: 61 74 65 28 29 2e 0a 2a 2a 0a 2a 2a 20 20 20 46 ate()..**.** F
2510: 6f 72 20 65 61 63 68 20 74 6f 6b 65 6e 20 69 6e or each token in
2520: 20 74 68 65 20 69 6e 70 75 74 20 73 74 72 69 6e the input strin
2530: 67 2c 20 74 68 65 20 73 75 70 70 6c 69 65 64 20 g, the supplied
2540: 63 61 6c 6c 62 61 63 6b 20 78 54 6f 6b 65 6e 28 callback xToken(
2550: 29 20 6d 75 73 74 0a 2a 2a 20 20 20 62 65 20 69 ) must.** be i
2560: 6e 76 6f 6b 65 64 2e 20 54 68 65 20 66 69 72 73 nvoked. The firs
2570: 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 69 74 t argument to it
2580: 20 73 68 6f 75 6c 64 20 62 65 20 61 20 63 6f 70 should be a cop
2590: 79 20 6f 66 20 74 68 65 20 70 6f 69 6e 74 65 72 y of the pointer
25a0: 0a 2a 2a 20 20 20 70 61 73 73 65 64 20 61 73 20 .** passed as
25b0: 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67 75 6d the second argum
25c0: 65 6e 74 20 74 6f 20 78 54 6f 6b 65 6e 69 7a 65 ent to xTokenize
25d0: 28 29 2e 20 54 68 65 20 6e 65 78 74 20 74 77 6f (). The next two
25e0: 20 61 72 67 75 6d 65 6e 74 73 0a 2a 2a 20 20 20 arguments.**
25f0: 61 72 65 20 61 20 70 6f 69 6e 74 65 72 20 74 6f are a pointer to
2600: 20 61 20 62 75 66 66 65 72 20 63 6f 6e 74 61 69 a buffer contai
2610: 6e 69 6e 67 20 74 68 65 20 74 6f 6b 65 6e 20 74 ning the token t
2620: 65 78 74 2c 20 61 6e 64 20 74 68 65 20 73 69 7a ext, and the siz
2630: 65 20 6f 66 0a 2a 2a 20 20 20 74 68 65 20 74 6f e of.** the to
2640: 6b 65 6e 20 69 6e 20 62 79 74 65 73 2e 20 54 68 ken in bytes. Th
2650: 65 20 34 74 68 20 61 6e 64 20 35 74 68 20 61 72 e 4th and 5th ar
2660: 67 75 6d 65 6e 74 73 20 61 72 65 20 74 68 65 20 guments are the
2670: 62 79 74 65 20 6f 66 66 73 65 74 73 20 6f 66 0a byte offsets of.
2680: 2a 2a 20 20 20 74 68 65 20 66 69 72 73 74 20 62 ** the first b
2690: 79 74 65 20 6f 66 20 61 6e 64 20 66 69 72 73 74 yte of and first
26a0: 20 62 79 74 65 20 69 6d 6d 65 64 69 61 74 65 6c byte immediatel
26b0: 79 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 y following the
26c0: 74 65 78 74 20 66 72 6f 6d 20 0a 2a 2a 20 20 20 text from .**
26d0: 77 68 69 63 68 20 74 68 65 20 74 6f 6b 65 6e 20 which the token
26e0: 69 73 20 64 65 72 69 76 65 64 20 77 69 74 68 69 is derived withi
26f0: 6e 20 74 68 65 20 69 6e 70 75 74 2e 0a 2a 2a 0a n the input..**.
2700: 2a 2a 20 20 20 46 54 53 35 20 61 73 73 75 6d 65 ** FTS5 assume
2710: 73 20 74 68 65 20 78 54 6f 6b 65 6e 28 29 20 63 s the xToken() c
2720: 61 6c 6c 62 61 63 6b 20 69 73 20 69 6e 76 6f 6b allback is invok
2730: 65 64 20 66 6f 72 20 65 61 63 68 20 74 6f 6b 65 ed for each toke
2740: 6e 20 69 6e 20 74 68 65 20 0a 2a 2a 20 20 20 6f n in the .** o
2750: 72 64 65 72 20 74 68 61 74 20 74 68 65 79 20 6f rder that they o
2760: 63 63 75 72 20 77 69 74 68 69 6e 20 74 68 65 20 ccur within the
2770: 69 6e 70 75 74 20 74 65 78 74 2e 0a 2a 2a 0a 2a input text..**.*
2780: 2a 20 20 20 49 66 20 61 6e 20 78 54 6f 6b 65 6e * If an xToken
2790: 28 29 20 63 61 6c 6c 62 61 63 6b 20 72 65 74 75 () callback retu
27a0: 72 6e 73 20 61 6e 79 20 76 61 6c 75 65 20 6f 74 rns any value ot
27b0: 68 65 72 20 74 68 61 6e 20 53 51 4c 49 54 45 5f her than SQLITE_
27c0: 4f 4b 2c 20 74 68 65 6e 0a 2a 2a 20 20 20 74 68 OK, then.** th
27d0: 65 20 74 6f 6b 65 6e 69 7a 61 74 69 6f 6e 20 73 e tokenization s
27e0: 68 6f 75 6c 64 20 62 65 20 61 62 61 6e 64 6f 6e hould be abandon
27f0: 65 64 20 61 6e 64 20 74 68 65 20 78 54 6f 6b 65 ed and the xToke
2800: 6e 69 7a 65 28 29 20 6d 65 74 68 6f 64 20 73 68 nize() method sh
2810: 6f 75 6c 64 0a 2a 2a 20 20 20 69 6d 6d 65 64 69 ould.** immedi
2820: 61 74 65 6c 79 20 72 65 74 75 72 6e 20 61 20 63 ately return a c
2830: 6f 70 79 20 6f 66 20 74 68 65 20 78 54 6f 6b 65 opy of the xToke
2840: 6e 28 29 20 72 65 74 75 72 6e 20 76 61 6c 75 65 n() return value
2850: 2e 20 4f 72 2c 20 69 66 20 74 68 65 0a 2a 2a 20 . Or, if the.**
2860: 20 20 69 6e 70 75 74 20 62 75 66 66 65 72 20 69 input buffer i
2870: 73 20 65 78 68 61 75 73 74 65 64 2c 20 78 54 6f s exhausted, xTo
2880: 6b 65 6e 69 7a 65 28 29 20 73 68 6f 75 6c 64 20 kenize() should
2890: 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f 4f 4b return SQLITE_OK
28a0: 2e 20 46 69 6e 61 6c 6c 79 2c 0a 2a 2a 20 20 20 . Finally,.**
28b0: 69 66 20 61 6e 20 65 72 72 6f 72 20 6f 63 63 75 if an error occu
28c0: 72 73 20 77 69 74 68 20 74 68 65 20 78 54 6f 6b rs with the xTok
28d0: 65 6e 69 7a 65 28 29 20 69 6d 70 6c 65 6d 65 6e enize() implemen
28e0: 74 61 74 69 6f 6e 20 69 74 73 65 6c 66 2c 20 69 tation itself, i
28f0: 74 0a 2a 2a 20 20 20 6d 61 79 20 61 62 61 6e 64 t.** may aband
2900: 6f 6e 20 74 68 65 20 74 6f 6b 65 6e 69 7a 61 74 on the tokenizat
2910: 69 6f 6e 20 61 6e 64 20 72 65 74 75 72 6e 20 61 ion and return a
2920: 6e 79 20 65 72 72 6f 72 20 63 6f 64 65 20 6f 74 ny error code ot
2930: 68 65 72 20 74 68 61 6e 0a 2a 2a 20 20 20 53 51 her than.** SQ
2940: 4c 49 54 45 5f 4f 4b 20 6f 72 20 53 51 4c 49 54 LITE_OK or SQLIT
2950: 45 5f 44 4f 4e 45 2e 0a 2a 2a 0a 2a 2f 0a 74 79 E_DONE..**.*/.ty
2960: 70 65 64 65 66 20 73 74 72 75 63 74 20 46 74 73 pedef struct Fts
2970: 35 54 6f 6b 65 6e 69 7a 65 72 20 46 74 73 35 54 5Tokenizer Fts5T
2980: 6f 6b 65 6e 69 7a 65 72 3b 0a 74 79 70 65 64 65 okenizer;.typede
2990: 66 20 73 74 72 75 63 74 20 66 74 73 35 5f 74 6f f struct fts5_to
29a0: 6b 65 6e 69 7a 65 72 20 66 74 73 35 5f 74 6f 6b kenizer fts5_tok
29b0: 65 6e 69 7a 65 72 3b 0a 73 74 72 75 63 74 20 66 enizer;.struct f
29c0: 74 73 35 5f 74 6f 6b 65 6e 69 7a 65 72 20 7b 0a ts5_tokenizer {.
29d0: 20 20 69 6e 74 20 28 2a 78 43 72 65 61 74 65 29 int (*xCreate)
29e0: 28 76 6f 69 64 2a 2c 20 63 6f 6e 73 74 20 63 68 (void*, const ch
29f0: 61 72 20 2a 2a 61 7a 41 72 67 2c 20 69 6e 74 20 ar **azArg, int
2a00: 6e 41 72 67 2c 20 46 74 73 35 54 6f 6b 65 6e 69 nArg, Fts5Tokeni
2a10: 7a 65 72 20 2a 2a 70 70 4f 75 74 29 3b 0a 20 20 zer **ppOut);.
2a20: 76 6f 69 64 20 28 2a 78 44 65 6c 65 74 65 29 28 void (*xDelete)(
2a30: 46 74 73 35 54 6f 6b 65 6e 69 7a 65 72 2a 29 3b Fts5Tokenizer*);
2a40: 0a 20 20 69 6e 74 20 28 2a 78 54 6f 6b 65 6e 69 . int (*xTokeni
2a50: 7a 65 29 28 46 74 73 35 54 6f 6b 65 6e 69 7a 65 ze)(Fts5Tokenize
2a60: 72 2a 2c 20 0a 20 20 20 20 20 20 76 6f 69 64 20 r*, . void
2a70: 2a 70 43 74 78 2c 0a 20 20 20 20 20 20 63 6f 6e *pCtx,. con
2a80: 73 74 20 63 68 61 72 20 2a 70 54 65 78 74 2c 20 st char *pText,
2a90: 69 6e 74 20 6e 54 65 78 74 2c 20 0a 20 20 20 20 int nText, .
2aa0: 20 20 69 6e 74 20 28 2a 78 54 6f 6b 65 6e 29 28 int (*xToken)(
2ab0: 0a 20 20 20 20 20 20 20 20 76 6f 69 64 20 2a 70 . void *p
2ac0: 43 74 78 2c 20 20 20 20 20 20 20 20 20 2f 2a 20 Ctx, /*
2ad0: 43 6f 70 79 20 6f 66 20 32 6e 64 20 61 72 67 75 Copy of 2nd argu
2ae0: 6d 65 6e 74 20 74 6f 20 78 54 6f 6b 65 6e 69 7a ment to xTokeniz
2af0: 65 28 29 20 2a 2f 0a 20 20 20 20 20 20 20 20 63 e() */. c
2b00: 6f 6e 73 74 20 63 68 61 72 20 2a 70 54 6f 6b 65 onst char *pToke
2b10: 6e 2c 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f n, /* Pointer to
2b20: 20 62 75 66 66 65 72 20 63 6f 6e 74 61 69 6e 69 buffer containi
2b30: 6e 67 20 74 6f 6b 65 6e 20 2a 2f 0a 20 20 20 20 ng token */.
2b40: 20 20 20 20 69 6e 74 20 6e 54 6f 6b 65 6e 2c 20 int nToken,
2b50: 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 /* Size
2b60: 6f 66 20 74 6f 6b 65 6e 20 69 6e 20 62 79 74 65 of token in byte
2b70: 73 20 2a 2f 0a 20 20 20 20 20 20 20 20 69 6e 74 s */. int
2b80: 20 69 53 74 61 72 74 2c 20 20 20 20 20 20 20 20 iStart,
2b90: 20 2f 2a 20 42 79 74 65 20 6f 66 66 73 65 74 20 /* Byte offset
2ba0: 6f 66 20 74 6f 6b 65 6e 20 77 69 74 68 69 6e 20 of token within
2bb0: 69 6e 70 75 74 20 74 65 78 74 20 2a 2f 0a 20 20 input text */.
2bc0: 20 20 20 20 20 20 69 6e 74 20 69 45 6e 64 20 20 int iEnd
2bd0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 42 79 74 /* Byt
2be0: 65 20 6f 66 66 73 65 74 20 6f 66 20 65 6e 64 20 e offset of end
2bf0: 6f 66 20 74 6f 6b 65 6e 20 77 69 74 68 69 6e 20 of token within
2c00: 69 6e 70 75 74 20 74 65 78 74 20 2a 2f 0a 20 20 input text */.
2c10: 20 20 20 20 29 0a 20 20 29 3b 0a 7d 3b 0a 0a 2f ). );.};../
2c20: 2a 0a 2a 2a 20 45 4e 44 20 4f 46 20 43 55 53 54 *.** END OF CUST
2c30: 4f 4d 20 54 4f 4b 45 4e 49 5a 45 52 53 0a 2a 2a OM TOKENIZERS.**
2c40: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2c50: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2c60: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2c70: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2c80: 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 2f 2a 2a 2a 2a 2a *******/../*****
2c90: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2ca0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2cb0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2cc0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2cd0: 2a 2a 2a 2a 0a 2a 2a 20 46 54 53 35 20 45 58 54 ****.** FTS5 EXT
2ce0: 45 4e 53 49 4f 4e 20 52 45 47 49 53 54 52 41 54 ENSION REGISTRAT
2cf0: 49 4f 4e 20 41 50 49 0a 2a 2f 0a 74 79 70 65 64 ION API.*/.typed
2d00: 65 66 20 73 74 72 75 63 74 20 66 74 73 35 5f 61 ef struct fts5_a
2d10: 70 69 20 66 74 73 35 5f 61 70 69 3b 0a 73 74 72 pi fts5_api;.str
2d20: 75 63 74 20 66 74 73 35 5f 61 70 69 20 7b 0a 20 uct fts5_api {.
2d30: 20 69 6e 74 20 69 56 65 72 73 69 6f 6e 3b 20 20 int iVersion;
2d40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d50: 20 2f 2a 20 43 75 72 72 65 6e 74 6c 79 20 61 6c /* Currently al
2d60: 77 61 79 73 20 73 65 74 20 74 6f 20 31 20 2a 2f ways set to 1 */
2d70: 0a 0a 20 20 2f 2a 20 43 72 65 61 74 65 20 61 20 .. /* Create a
2d80: 6e 65 77 20 74 6f 6b 65 6e 69 7a 65 72 20 2a 2f new tokenizer */
2d90: 0a 20 20 69 6e 74 20 28 2a 78 43 72 65 61 74 65 . int (*xCreate
2da0: 54 6f 6b 65 6e 69 7a 65 72 29 28 0a 20 20 20 20 Tokenizer)(.
2db0: 66 74 73 35 5f 61 70 69 20 2a 70 41 70 69 2c 0a fts5_api *pApi,.
2dc0: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
2dd0: 7a 4e 61 6d 65 2c 0a 20 20 20 20 76 6f 69 64 20 zName,. void
2de0: 2a 70 43 6f 6e 74 65 78 74 2c 0a 20 20 20 20 66 *pContext,. f
2df0: 74 73 35 5f 74 6f 6b 65 6e 69 7a 65 72 20 2a 70 ts5_tokenizer *p
2e00: 54 6f 6b 65 6e 69 7a 65 72 2c 0a 20 20 20 20 76 Tokenizer,. v
2e10: 6f 69 64 20 28 2a 78 44 65 73 74 72 6f 79 29 28 oid (*xDestroy)(
2e20: 76 6f 69 64 2a 29 0a 20 20 29 3b 0a 0a 20 20 2f void*). );.. /
2e30: 2a 20 46 69 6e 64 20 61 6e 20 65 78 69 73 74 69 * Find an existi
2e40: 6e 67 20 74 6f 6b 65 6e 69 7a 65 72 20 2a 2f 0a ng tokenizer */.
2e50: 20 20 69 6e 74 20 28 2a 78 46 69 6e 64 54 6f 6b int (*xFindTok
2e60: 65 6e 69 7a 65 72 29 28 0a 20 20 20 20 66 74 73 enizer)(. fts
2e70: 35 5f 61 70 69 20 2a 70 41 70 69 2c 0a 20 20 20 5_api *pApi,.
2e80: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 const char *zNa
2e90: 6d 65 2c 0a 20 20 20 20 76 6f 69 64 20 2a 2a 70 me,. void **p
2ea0: 70 43 6f 6e 74 65 78 74 2c 0a 20 20 20 20 66 74 pContext,. ft
2eb0: 73 35 5f 74 6f 6b 65 6e 69 7a 65 72 20 2a 70 54 s5_tokenizer *pT
2ec0: 6f 6b 65 6e 69 7a 65 72 0a 20 20 29 3b 0a 0a 20 okenizer. );..
2ed0: 20 2f 2a 20 43 72 65 61 74 65 20 61 20 6e 65 77 /* Create a new
2ee0: 20 61 75 78 69 6c 69 61 72 79 20 66 75 6e 63 74 auxiliary funct
2ef0: 69 6f 6e 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 ion */. int (*x
2f00: 43 72 65 61 74 65 46 75 6e 63 74 69 6f 6e 29 28 CreateFunction)(
2f10: 0a 20 20 20 20 66 74 73 35 5f 61 70 69 20 2a 70 . fts5_api *p
2f20: 41 70 69 2c 0a 20 20 20 20 63 6f 6e 73 74 20 63 Api,. const c
2f30: 68 61 72 20 2a 7a 4e 61 6d 65 2c 0a 20 20 20 20 har *zName,.
2f40: 76 6f 69 64 20 2a 70 43 6f 6e 74 65 78 74 2c 0a void *pContext,.
2f50: 20 20 20 20 66 74 73 35 5f 65 78 74 65 6e 73 69 fts5_extensi
2f60: 6f 6e 5f 66 75 6e 63 74 69 6f 6e 20 78 46 75 6e on_function xFun
2f70: 63 74 69 6f 6e 2c 0a 20 20 20 20 76 6f 69 64 20 ction,. void
2f80: 28 2a 78 44 65 73 74 72 6f 79 29 28 76 6f 69 64 (*xDestroy)(void
2f90: 2a 29 0a 20 20 29 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a *). );.};../*.*
2fa0: 2a 20 45 4e 44 20 4f 46 20 52 45 47 49 53 54 52 * END OF REGISTR
2fb0: 41 54 49 4f 4e 20 41 50 49 0a 2a 2a 2a 2a 2a 2a ATION API.******
2fc0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2fd0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2fe0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2ff0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
3000: 2a 2a 2a 2f 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 ***/..#endif /*
3010: 5f 46 54 53 35 5f 48 20 2a 2f 0a 0a _FTS5_H */..