Files
sqlite/ext/fts3/fts3_expr.h
T

88 lines
2.4 KiB
C

/*
** 2008 Nov 28
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
*/
#include "fts3_tokenizer.h"
#include "sqlite3.h"
/*
** The following describes the syntax supported by the fts3 MATCH
** operator in a similar format to that used by the lemon parser
** generator. This module does not use actually lemon, it uses a
** custom parser.
**
** phrase ::= TOKEN.
** phrase ::= TOKEN:COLUMN.
** phrase ::= "TOKEN TOKEN TOKEN...".
** phrase ::= phrase near phrase.
**
** near ::= NEAR.
** near ::= NEAR / INTEGER.
**
** query ::= -TOKEN.
** query ::= phrase.
** query ::= LP query RP.
** query ::= query NOT query.
** query ::= query OR query.
** query ::= query AND query.
*/
typedef struct Fts3Expr Fts3Expr;
typedef struct Fts3Phrase Fts3Phrase;
struct Fts3Phrase {
int nToken; /* Number of entries in aToken[] */
int iColumn; /* Index of column this phrase must match */
int isNot; /* Phrase prefixed by unary not (-) operator */
struct PhraseToken {
char *z;
int n; /* Number of bytes in buffer pointed to by z */
int isPrefix; /* True if token ends in with a "*" character */
} aToken[1];
};
struct Fts3Expr {
int eType; /* One of the FTSQUERY_XXX values defined below */
int nNear; /* Valid if eType==FTSQUERY_NEAR */
Fts3Expr *pParent;
Fts3Expr *pLeft;
Fts3Expr *pRight;
Fts3Phrase *pPhrase; /* Valid if eType==FTSQUERY_PHRASE */
};
int sqlite3Fts3ExprParse(sqlite3_tokenizer *, char **, int, int,
const char *, int, Fts3Expr **);
void sqlite3Fts3ExprFree(Fts3Expr *);
/*
** Candidate values for Fts3Query.eType. Note that the order of the first
** four values is in order of precedence when parsing expressions. For
** example, the following:
**
** "a OR b AND c NOT d NEAR e"
**
** is equivalent to:
**
** "a OR (b AND (c NOT (d NEAR e)))"
*/
#define FTSQUERY_NEAR 1
#define FTSQUERY_NOT 2
#define FTSQUERY_AND 3
#define FTSQUERY_OR 4
#define FTSQUERY_PHRASE 5
#ifdef SQLITE_TEST
void sqlite3Fts3ExprInitTestInterface(sqlite3 *db);
#endif