OLD | NEW |
| (Empty) |
1 /* | |
2 ** 2008 Nov 28 | |
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 | |
15 #include "fts3_tokenizer.h" | |
16 #include "sqlite3.h" | |
17 | |
18 /* | |
19 ** The following describes the syntax supported by the fts3 MATCH | |
20 ** operator in a similar format to that used by the lemon parser | |
21 ** generator. This module does not use actually lemon, it uses a | |
22 ** custom parser. | |
23 ** | |
24 ** query ::= andexpr (OR andexpr)*. | |
25 ** | |
26 ** andexpr ::= notexpr (AND? notexpr)*. | |
27 ** | |
28 ** notexpr ::= nearexpr (NOT nearexpr|-TOKEN)*. | |
29 ** notexpr ::= LP query RP. | |
30 ** | |
31 ** nearexpr ::= phrase (NEAR distance_opt nearexpr)*. | |
32 ** | |
33 ** distance_opt ::= . | |
34 ** distance_opt ::= / INTEGER. | |
35 ** | |
36 ** phrase ::= TOKEN. | |
37 ** phrase ::= COLUMN:TOKEN. | |
38 ** phrase ::= "TOKEN TOKEN TOKEN...". | |
39 */ | |
40 | |
41 typedef struct Fts3Expr Fts3Expr; | |
42 typedef struct Fts3Phrase Fts3Phrase; | |
43 | |
44 /* | |
45 ** A "phrase" is a sequence of one or more tokens that must match in | |
46 ** sequence. A single token is the base case and the most common case. | |
47 ** For a sequence of tokens contained in "...", nToken will be the number | |
48 ** of tokens in the string. | |
49 */ | |
50 struct Fts3Phrase { | |
51 int nToken; /* Number of tokens in the phrase */ | |
52 int iColumn; /* Index of column this phrase must match */ | |
53 int isNot; /* Phrase prefixed by unary not (-) operator */ | |
54 struct PhraseToken { | |
55 char *z; /* Text of the token */ | |
56 int n; /* Number of bytes in buffer pointed to by z */ | |
57 int isPrefix; /* True if token ends in with a "*" character */ | |
58 } aToken[1]; /* One entry for each token in the phrase */ | |
59 }; | |
60 | |
61 /* | |
62 ** A tree of these objects forms the RHS of a MATCH operator. | |
63 */ | |
64 struct Fts3Expr { | |
65 int eType; /* One of the FTSQUERY_XXX values defined below */ | |
66 int nNear; /* Valid if eType==FTSQUERY_NEAR */ | |
67 Fts3Expr *pParent; /* pParent->pLeft==this or pParent->pRight==this */ | |
68 Fts3Expr *pLeft; /* Left operand */ | |
69 Fts3Expr *pRight; /* Right operand */ | |
70 Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */ | |
71 }; | |
72 | |
73 int sqlite3Fts3ExprParse(sqlite3_tokenizer *, char **, int, int, | |
74 const char *, int, Fts3Expr **); | |
75 void sqlite3Fts3ExprFree(Fts3Expr *); | |
76 | |
77 /* | |
78 ** Candidate values for Fts3Query.eType. Note that the order of the first | |
79 ** four values is in order of precedence when parsing expressions. For | |
80 ** example, the following: | |
81 ** | |
82 ** "a OR b AND c NOT d NEAR e" | |
83 ** | |
84 ** is equivalent to: | |
85 ** | |
86 ** "a OR (b AND (c NOT (d NEAR e)))" | |
87 */ | |
88 #define FTSQUERY_NEAR 1 | |
89 #define FTSQUERY_NOT 2 | |
90 #define FTSQUERY_AND 3 | |
91 #define FTSQUERY_OR 4 | |
92 #define FTSQUERY_PHRASE 5 | |
93 | |
94 #ifdef SQLITE_TEST | |
95 void sqlite3Fts3ExprInitTestInterface(sqlite3 *db); | |
96 #endif | |
OLD | NEW |