2014-06-23 15:33:22 +04:00
|
|
|
/*
|
|
|
|
** 2014 May 31
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
******************************************************************************
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#ifndef _FTS5INT_H
|
|
|
|
#define _FTS5INT_H
|
|
|
|
|
2014-07-16 23:15:57 +04:00
|
|
|
#include "fts5.h"
|
2015-06-25 23:10:24 +03:00
|
|
|
#include "sqlite3ext.h"
|
|
|
|
SQLITE_EXTENSION_INIT1
|
2015-05-30 14:49:58 +03:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#ifndef SQLITE_AMALGAMATION
|
|
|
|
|
|
|
|
typedef unsigned char u8;
|
|
|
|
typedef unsigned int u32;
|
|
|
|
typedef unsigned short u16;
|
2016-02-12 20:56:27 +03:00
|
|
|
typedef short i16;
|
2015-05-30 14:49:58 +03:00
|
|
|
typedef sqlite3_int64 i64;
|
|
|
|
typedef sqlite3_uint64 u64;
|
|
|
|
|
2017-02-13 16:20:02 +03:00
|
|
|
#ifndef ArraySize
|
|
|
|
# define ArraySize(x) ((int)(sizeof(x) / sizeof(x[0])))
|
|
|
|
#endif
|
2015-05-30 14:49:58 +03:00
|
|
|
|
|
|
|
#define testcase(x)
|
2021-10-04 21:21:14 +03:00
|
|
|
|
2021-10-04 21:57:42 +03:00
|
|
|
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
|
|
|
|
# define SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS 1
|
|
|
|
#endif
|
|
|
|
#if defined(SQLITE_OMIT_AUXILIARY_SAFETY_CHECKS)
|
|
|
|
# define ALWAYS(X) (1)
|
|
|
|
# define NEVER(X) (0)
|
|
|
|
#elif !defined(NDEBUG)
|
|
|
|
# define ALWAYS(X) ((X)?1:(assert(0),0))
|
|
|
|
# define NEVER(X) ((X)?(assert(0),1):0)
|
2021-10-04 21:21:14 +03:00
|
|
|
#else
|
2021-10-04 21:57:42 +03:00
|
|
|
# define ALWAYS(X) (X)
|
|
|
|
# define NEVER(X) (X)
|
2021-10-04 21:21:14 +03:00
|
|
|
#endif
|
2015-05-30 14:49:58 +03:00
|
|
|
|
|
|
|
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
|
2015-07-09 22:02:19 +03:00
|
|
|
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
|
2015-05-30 14:49:58 +03:00
|
|
|
|
2015-07-09 23:46:35 +03:00
|
|
|
/*
|
|
|
|
** Constants for the largest and smallest possible 64-bit signed integers.
|
|
|
|
*/
|
|
|
|
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
|
|
|
|
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
|
|
|
|
|
2024-07-17 19:27:36 +03:00
|
|
|
/* The uptr type is an unsigned integer large enough to hold a pointer
|
|
|
|
*/
|
|
|
|
#if defined(HAVE_STDINT_H)
|
|
|
|
typedef uintptr_t uptr;
|
|
|
|
#elif SQLITE_PTRSIZE==4
|
|
|
|
typedef u32 uptr;
|
|
|
|
#else
|
|
|
|
typedef u64 uptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
|
|
|
|
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
|
|
|
|
#else
|
|
|
|
# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
|
|
|
|
#endif
|
|
|
|
|
2015-05-30 14:49:58 +03:00
|
|
|
#endif
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2016-03-23 18:04:00 +03:00
|
|
|
/* Truncate very long tokens to this many bytes. Hard limit is
|
|
|
|
** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
|
|
|
|
** field that occurs at the start of each leaf page (see fts5_index.c). */
|
|
|
|
#define FTS5_MAX_TOKEN_SIZE 32768
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Maximum number of prefix indexes on single FTS5 table. This must be
|
|
|
|
** less than 32. If it is set to anything large than that, an #error
|
|
|
|
** directive in fts5_index.c will cause the build to fail.
|
|
|
|
*/
|
|
|
|
#define FTS5_MAX_PREFIX_INDEXES 31
|
|
|
|
|
2019-10-09 21:36:32 +03:00
|
|
|
/*
|
|
|
|
** Maximum segments permitted in a single index
|
|
|
|
*/
|
|
|
|
#define FTS5_MAX_SEGMENT 2000
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
#define FTS5_DEFAULT_NEARDIST 10
|
2014-12-02 23:18:11 +03:00
|
|
|
#define FTS5_DEFAULT_RANK "bm25"
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2014-12-29 14:24:46 +03:00
|
|
|
/* Name of rank and rowid columns */
|
2014-07-30 23:41:58 +04:00
|
|
|
#define FTS5_RANK_NAME "rank"
|
2014-12-29 14:24:46 +03:00
|
|
|
#define FTS5_ROWID_NAME "rowid"
|
2014-07-30 23:41:58 +04:00
|
|
|
|
2015-01-23 20:43:21 +03:00
|
|
|
#ifdef SQLITE_DEBUG
|
|
|
|
# define FTS5_CORRUPT sqlite3Fts5Corrupt()
|
|
|
|
int sqlite3Fts5Corrupt(void);
|
|
|
|
#else
|
|
|
|
# define FTS5_CORRUPT SQLITE_CORRUPT_VTAB
|
|
|
|
#endif
|
|
|
|
|
2015-04-24 18:56:09 +03:00
|
|
|
/*
|
|
|
|
** The assert_nc() macro is similar to the assert() macro, except that it
|
|
|
|
** is used for assert() conditions that are true only if it can be
|
|
|
|
** guranteed that the database is not corrupt.
|
|
|
|
*/
|
2015-05-13 20:15:32 +03:00
|
|
|
#ifdef SQLITE_DEBUG
|
2015-04-24 18:56:09 +03:00
|
|
|
extern int sqlite3_fts5_may_be_corrupt;
|
|
|
|
# define assert_nc(x) assert(sqlite3_fts5_may_be_corrupt || (x))
|
|
|
|
#else
|
|
|
|
# define assert_nc(x) assert(x)
|
|
|
|
#endif
|
|
|
|
|
2019-01-25 19:54:06 +03:00
|
|
|
/*
|
|
|
|
** A version of memcmp() that does not cause asan errors if one of the pointer
|
|
|
|
** parameters is NULL and the number of bytes to compare is zero.
|
|
|
|
*/
|
2021-10-16 22:50:03 +03:00
|
|
|
#define fts5Memcmp(s1, s2, n) ((n)<=0 ? 0 : memcmp((s1), (s2), (n)))
|
2019-01-25 19:54:06 +03:00
|
|
|
|
2016-02-11 18:37:18 +03:00
|
|
|
/* Mark a function parameter as unused, to suppress nuisance compiler
|
|
|
|
** warnings. */
|
|
|
|
#ifndef UNUSED_PARAM
|
|
|
|
# define UNUSED_PARAM(X) (void)(X)
|
|
|
|
#endif
|
|
|
|
|
2016-02-11 20:01:32 +03:00
|
|
|
#ifndef UNUSED_PARAM2
|
|
|
|
# define UNUSED_PARAM2(X, Y) (void)(X), (void)(Y)
|
|
|
|
#endif
|
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
typedef struct Fts5Global Fts5Global;
|
2015-10-07 12:02:50 +03:00
|
|
|
typedef struct Fts5Colset Fts5Colset;
|
2015-10-06 23:53:26 +03:00
|
|
|
|
|
|
|
/* If a NEAR() clump or phrase may only match a specific set of columns,
|
|
|
|
** then an object of the following type is used to record the set of columns.
|
|
|
|
** Each entry in the aiCol[] array is a column that may be matched.
|
|
|
|
**
|
|
|
|
** This object is used by fts5_expr.c and fts5_index.c.
|
|
|
|
*/
|
2015-10-07 12:02:50 +03:00
|
|
|
struct Fts5Colset {
|
2015-10-06 23:53:26 +03:00
|
|
|
int nCol;
|
|
|
|
int aiCol[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/**************************************************************************
|
|
|
|
** Interface to code in fts5_config.c. fts5_config.c contains contains code
|
|
|
|
** to parse the arguments passed to the CREATE VIRTUAL TABLE statement.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct Fts5Config Fts5Config;
|
2024-05-13 23:06:08 +03:00
|
|
|
typedef struct Fts5TokenizerConfig Fts5TokenizerConfig;
|
|
|
|
|
|
|
|
struct Fts5TokenizerConfig {
|
|
|
|
Fts5Tokenizer *pTok;
|
2024-08-10 21:59:36 +03:00
|
|
|
fts5_tokenizer_v2 *pApi2;
|
|
|
|
fts5_tokenizer *pApi1;
|
2024-05-13 23:06:08 +03:00
|
|
|
const char **azArg;
|
|
|
|
int nArg;
|
|
|
|
int ePattern; /* FTS_PATTERN_XXX constant */
|
2024-08-10 21:59:36 +03:00
|
|
|
const char *pLocale; /* Current locale to use */
|
2024-08-12 20:03:37 +03:00
|
|
|
int nLocale; /* Size of pLocale in bytes */
|
2024-05-13 23:06:08 +03:00
|
|
|
};
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** An instance of the following structure encodes all information that can
|
|
|
|
** be gleaned from the CREATE VIRTUAL TABLE statement.
|
2014-11-27 23:03:45 +03:00
|
|
|
**
|
|
|
|
** And all information loaded from the %_config table.
|
2014-11-28 23:01:13 +03:00
|
|
|
**
|
|
|
|
** nAutomerge:
|
|
|
|
** The minimum number of segments that an auto-merge operation should
|
|
|
|
** attempt to merge together. A value of 1 sets the object to use the
|
|
|
|
** compile time default. Zero disables auto-merge altogether.
|
2015-04-27 19:21:49 +03:00
|
|
|
**
|
2023-07-10 23:44:09 +03:00
|
|
|
** bContentlessDelete:
|
|
|
|
** True if the contentless_delete option was present in the CREATE
|
|
|
|
** VIRTUAL TABLE statement.
|
|
|
|
**
|
2015-04-27 19:21:49 +03:00
|
|
|
** zContent:
|
|
|
|
**
|
|
|
|
** zContentRowid:
|
|
|
|
** The value of the content_rowid= option, if one was specified. Or
|
|
|
|
** the string "rowid" otherwise. This text is not quoted - if it is
|
|
|
|
** used as part of an SQL statement it needs to be quoted appropriately.
|
|
|
|
**
|
|
|
|
** zContentExprlist:
|
|
|
|
**
|
2015-05-08 12:21:05 +03:00
|
|
|
** pzErrmsg:
|
|
|
|
** This exists in order to allow the fts5_index.c module to return a
|
|
|
|
** decent error message if it encounters a file-format version it does
|
|
|
|
** not understand.
|
|
|
|
**
|
2015-06-09 23:58:39 +03:00
|
|
|
** bColumnsize:
|
|
|
|
** True if the %_docsize table is created.
|
|
|
|
**
|
2015-09-08 22:55:26 +03:00
|
|
|
** bPrefixIndex:
|
|
|
|
** This is only used for debugging. If set to false, any prefix indexes
|
|
|
|
** are ignored. This value is configured using:
|
|
|
|
**
|
|
|
|
** INSERT INTO tbl(tbl, rank) VALUES('prefix-index', $bPrefixIndex);
|
|
|
|
**
|
2024-07-31 23:49:00 +03:00
|
|
|
** bLocale:
|
|
|
|
** Set to true if locale=1 was specified when the table was created.
|
2014-06-23 15:33:22 +04:00
|
|
|
*/
|
|
|
|
struct Fts5Config {
|
|
|
|
sqlite3 *db; /* Database handle */
|
2024-05-13 23:06:08 +03:00
|
|
|
Fts5Global *pGlobal; /* Global fts5 object for handle db */
|
2014-06-23 15:33:22 +04:00
|
|
|
char *zDb; /* Database holding FTS index (e.g. "main") */
|
|
|
|
char *zName; /* Name of FTS index */
|
|
|
|
int nCol; /* Number of columns */
|
|
|
|
char **azCol; /* Column names */
|
2015-04-24 22:41:43 +03:00
|
|
|
u8 *abUnindexed; /* True for unindexed columns */
|
2014-06-23 15:33:22 +04:00
|
|
|
int nPrefix; /* Number of prefix indexes */
|
|
|
|
int *aPrefix; /* Sizes in bytes of nPrefix prefix indexes */
|
2015-01-05 23:41:39 +03:00
|
|
|
int eContent; /* An FTS5_CONTENT value */
|
2023-07-10 23:44:09 +03:00
|
|
|
int bContentlessDelete; /* "contentless_delete=" option (dflt==0) */
|
2015-01-05 23:41:39 +03:00
|
|
|
char *zContent; /* content table */
|
|
|
|
char *zContentRowid; /* "content_rowid=" option value */
|
2015-06-09 23:58:39 +03:00
|
|
|
int bColumnsize; /* "columnsize=" option value (dflt==1) */
|
2023-10-12 00:08:12 +03:00
|
|
|
int bTokendata; /* "tokendata=" option value (dflt==0) */
|
2024-07-26 23:50:33 +03:00
|
|
|
int bLocale; /* "locale=" option value (dflt==0) */
|
2015-12-28 22:55:00 +03:00
|
|
|
int eDetail; /* FTS5_DETAIL_XXX value */
|
2015-04-27 19:21:49 +03:00
|
|
|
char *zContentExprlist;
|
2024-05-13 23:06:08 +03:00
|
|
|
Fts5TokenizerConfig t;
|
2019-08-05 15:55:56 +03:00
|
|
|
int bLock; /* True when table is preparing statement */
|
2024-07-30 23:39:58 +03:00
|
|
|
|
2014-11-27 23:03:45 +03:00
|
|
|
|
|
|
|
/* Values loaded from the %_config table */
|
2023-04-12 20:40:44 +03:00
|
|
|
int iVersion; /* fts5 file format 'version' */
|
2014-11-27 23:03:45 +03:00
|
|
|
int iCookie; /* Incremented when %_config is modified */
|
|
|
|
int pgsz; /* Approximate page size used in %_data */
|
2014-11-28 23:01:13 +03:00
|
|
|
int nAutomerge; /* 'automerge' setting */
|
2015-01-23 09:50:33 +03:00
|
|
|
int nCrisisMerge; /* Maximum allowed segments per level */
|
2016-03-09 23:54:14 +03:00
|
|
|
int nUsermerge; /* 'usermerge' setting */
|
2015-11-05 21:09:16 +03:00
|
|
|
int nHashSize; /* Bytes of memory for in-memory hash */
|
2014-12-01 23:05:00 +03:00
|
|
|
char *zRank; /* Name of rank function */
|
|
|
|
char *zRankArgs; /* Arguments to rank function */
|
2023-04-12 20:40:44 +03:00
|
|
|
int bSecureDelete; /* 'secure-delete' */
|
2023-07-25 18:48:58 +03:00
|
|
|
int nDeleteMerge; /* 'deletemerge' */
|
2015-05-08 12:21:05 +03:00
|
|
|
|
|
|
|
/* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */
|
|
|
|
char **pzErrmsg;
|
2015-09-08 22:55:26 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_DEBUG
|
|
|
|
int bPrefixIndex; /* True to use prefix-indexes */
|
|
|
|
#endif
|
2014-06-23 15:33:22 +04:00
|
|
|
};
|
|
|
|
|
2023-04-12 20:40:44 +03:00
|
|
|
/* Current expected value of %_config table 'version' field. And
|
|
|
|
** the expected version if the 'secure-delete' option has ever been
|
|
|
|
** set on the table. */
|
|
|
|
#define FTS5_CURRENT_VERSION 4
|
|
|
|
#define FTS5_CURRENT_VERSION_SECUREDELETE 5
|
2015-05-07 22:29:46 +03:00
|
|
|
|
2015-01-05 23:41:39 +03:00
|
|
|
#define FTS5_CONTENT_NORMAL 0
|
|
|
|
#define FTS5_CONTENT_NONE 1
|
|
|
|
#define FTS5_CONTENT_EXTERNAL 2
|
|
|
|
|
2020-09-30 23:35:37 +03:00
|
|
|
#define FTS5_DETAIL_FULL 0
|
|
|
|
#define FTS5_DETAIL_NONE 1
|
|
|
|
#define FTS5_DETAIL_COLUMNS 2
|
2015-01-05 23:41:39 +03:00
|
|
|
|
2020-09-30 23:35:37 +03:00
|
|
|
#define FTS5_PATTERN_NONE 0
|
|
|
|
#define FTS5_PATTERN_LIKE 65 /* matches SQLITE_INDEX_CONSTRAINT_LIKE */
|
|
|
|
#define FTS5_PATTERN_GLOB 66 /* matches SQLITE_INDEX_CONSTRAINT_GLOB */
|
2015-05-07 22:29:46 +03:00
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
int sqlite3Fts5ConfigParse(
|
|
|
|
Fts5Global*, sqlite3*, int, const char **, Fts5Config**, char**
|
|
|
|
);
|
2014-06-23 15:33:22 +04:00
|
|
|
void sqlite3Fts5ConfigFree(Fts5Config*);
|
|
|
|
|
|
|
|
int sqlite3Fts5ConfigDeclareVtab(Fts5Config *pConfig);
|
|
|
|
|
|
|
|
int sqlite3Fts5Tokenize(
|
|
|
|
Fts5Config *pConfig, /* FTS5 Configuration object */
|
2015-08-28 22:56:47 +03:00
|
|
|
int flags, /* FTS5_TOKENIZE_* flags */
|
2014-06-23 15:33:22 +04:00
|
|
|
const char *pText, int nText, /* Text to tokenize */
|
|
|
|
void *pCtx, /* Context passed to xToken() */
|
2015-08-29 18:44:27 +03:00
|
|
|
int (*xToken)(void*, int, const char*, int, int, int) /* Callback */
|
2014-06-23 15:33:22 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
void sqlite3Fts5Dequote(char *z);
|
|
|
|
|
2014-11-27 23:03:45 +03:00
|
|
|
/* Load the contents of the %_config table */
|
2014-11-28 23:01:13 +03:00
|
|
|
int sqlite3Fts5ConfigLoad(Fts5Config*, int);
|
2014-11-27 23:03:45 +03:00
|
|
|
|
|
|
|
/* Set the value of a single config attribute */
|
|
|
|
int sqlite3Fts5ConfigSetValue(Fts5Config*, const char*, sqlite3_value*, int*);
|
|
|
|
|
2015-01-02 17:55:22 +03:00
|
|
|
int sqlite3Fts5ConfigParseRank(const char*, char**, char**);
|
|
|
|
|
2024-07-26 23:50:33 +03:00
|
|
|
void sqlite3Fts5ConfigErrmsg(Fts5Config *pConfig, const char *zFmt, ...);
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_config.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2014-07-03 00:18:49 +04:00
|
|
|
/**************************************************************************
|
2014-08-06 20:30:21 +04:00
|
|
|
** Interface to code in fts5_buffer.c.
|
2014-07-03 00:18:49 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Buffer object for the incremental building of string data.
|
|
|
|
*/
|
|
|
|
typedef struct Fts5Buffer Fts5Buffer;
|
|
|
|
struct Fts5Buffer {
|
|
|
|
u8 *p;
|
2016-01-23 18:57:06 +03:00
|
|
|
int n;
|
|
|
|
int nSpace;
|
2014-07-03 00:18:49 +04:00
|
|
|
};
|
|
|
|
|
2016-01-18 20:48:28 +03:00
|
|
|
int sqlite3Fts5BufferSize(int*, Fts5Buffer*, u32);
|
2014-07-03 00:18:49 +04:00
|
|
|
void sqlite3Fts5BufferAppendVarint(int*, Fts5Buffer*, i64);
|
2016-01-18 20:48:28 +03:00
|
|
|
void sqlite3Fts5BufferAppendBlob(int*, Fts5Buffer*, u32, const u8*);
|
2014-07-03 00:18:49 +04:00
|
|
|
void sqlite3Fts5BufferAppendString(int *, Fts5Buffer*, const char*);
|
|
|
|
void sqlite3Fts5BufferFree(Fts5Buffer*);
|
|
|
|
void sqlite3Fts5BufferZero(Fts5Buffer*);
|
|
|
|
void sqlite3Fts5BufferSet(int*, Fts5Buffer*, int, const u8*);
|
|
|
|
void sqlite3Fts5BufferAppendPrintf(int *, Fts5Buffer*, char *zFmt, ...);
|
|
|
|
|
2015-06-26 07:34:36 +03:00
|
|
|
char *sqlite3Fts5Mprintf(int *pRc, const char *zFmt, ...);
|
2015-06-09 23:58:39 +03:00
|
|
|
|
2014-07-03 00:18:49 +04:00
|
|
|
#define fts5BufferZero(x) sqlite3Fts5BufferZero(x)
|
2022-08-08 22:29:53 +03:00
|
|
|
#define fts5BufferAppendVarint(a,b,c) sqlite3Fts5BufferAppendVarint(a,b,(i64)c)
|
2014-07-03 00:18:49 +04:00
|
|
|
#define fts5BufferFree(a) sqlite3Fts5BufferFree(a)
|
|
|
|
#define fts5BufferAppendBlob(a,b,c,d) sqlite3Fts5BufferAppendBlob(a,b,c,d)
|
|
|
|
#define fts5BufferSet(a,b,c,d) sqlite3Fts5BufferSet(a,b,c,d)
|
2014-11-28 23:01:13 +03:00
|
|
|
|
2015-10-19 23:49:10 +03:00
|
|
|
#define fts5BufferGrow(pRc,pBuf,nn) ( \
|
2016-01-23 18:57:06 +03:00
|
|
|
(u32)((pBuf)->n) + (u32)(nn) <= (u32)((pBuf)->nSpace) ? 0 : \
|
2015-10-19 23:49:10 +03:00
|
|
|
sqlite3Fts5BufferSize((pRc),(pBuf),(nn)+(pBuf)->n) \
|
|
|
|
)
|
|
|
|
|
2014-11-28 23:01:13 +03:00
|
|
|
/* Write and decode big-endian 32-bit integer values */
|
|
|
|
void sqlite3Fts5Put32(u8*, int);
|
|
|
|
int sqlite3Fts5Get32(const u8*);
|
2014-07-03 00:18:49 +04:00
|
|
|
|
2024-08-15 23:33:05 +03:00
|
|
|
#define FTS5_POS2COLUMN(iPos) (int)((iPos >> 32) & 0x7FFFFFFF)
|
2019-01-23 00:17:40 +03:00
|
|
|
#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
|
2014-12-29 14:24:46 +03:00
|
|
|
|
2014-07-08 20:27:37 +04:00
|
|
|
typedef struct Fts5PoslistReader Fts5PoslistReader;
|
|
|
|
struct Fts5PoslistReader {
|
|
|
|
/* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */
|
|
|
|
const u8 *a; /* Position list to iterate through */
|
|
|
|
int n; /* Size of buffer at a[] in bytes */
|
|
|
|
int i; /* Current offset in a[] */
|
|
|
|
|
2015-09-01 21:08:36 +03:00
|
|
|
u8 bFlag; /* For client use (any custom purpose) */
|
|
|
|
|
2014-07-08 20:27:37 +04:00
|
|
|
/* Output variables */
|
2015-08-31 23:06:06 +03:00
|
|
|
u8 bEof; /* Set to true at EOF */
|
2014-07-08 20:27:37 +04:00
|
|
|
i64 iPos; /* (iCol<<32) + iPos */
|
|
|
|
};
|
|
|
|
int sqlite3Fts5PoslistReaderInit(
|
|
|
|
const u8 *a, int n, /* Poslist buffer to iterate through */
|
|
|
|
Fts5PoslistReader *pIter /* Iterator object to initialize */
|
|
|
|
);
|
|
|
|
int sqlite3Fts5PoslistReaderNext(Fts5PoslistReader*);
|
|
|
|
|
|
|
|
typedef struct Fts5PoslistWriter Fts5PoslistWriter;
|
|
|
|
struct Fts5PoslistWriter {
|
2014-07-18 23:59:00 +04:00
|
|
|
i64 iPrev;
|
2014-07-08 20:27:37 +04:00
|
|
|
};
|
|
|
|
int sqlite3Fts5PoslistWriterAppend(Fts5Buffer*, Fts5PoslistWriter*, i64);
|
2016-02-05 22:18:02 +03:00
|
|
|
void sqlite3Fts5PoslistSafeAppend(Fts5Buffer*, i64*, i64);
|
2014-07-08 20:27:37 +04:00
|
|
|
|
2014-07-18 23:59:00 +04:00
|
|
|
int sqlite3Fts5PoslistNext64(
|
|
|
|
const u8 *a, int n, /* Buffer containing poslist */
|
|
|
|
int *pi, /* IN/OUT: Offset within a[] */
|
|
|
|
i64 *piOff /* IN/OUT: Current offset */
|
|
|
|
);
|
|
|
|
|
2014-12-03 20:27:35 +03:00
|
|
|
/* Malloc utility */
|
2019-01-08 23:02:48 +03:00
|
|
|
void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte);
|
2015-05-02 23:35:24 +03:00
|
|
|
char *sqlite3Fts5Strndup(int *pRc, const char *pIn, int nIn);
|
2014-12-03 20:27:35 +03:00
|
|
|
|
2015-05-18 20:50:17 +03:00
|
|
|
/* Character set tests (like isspace(), isalpha() etc.) */
|
|
|
|
int sqlite3Fts5IsBareword(char t);
|
|
|
|
|
2015-12-17 23:36:13 +03:00
|
|
|
|
|
|
|
/* Bucket of terms object used by the integrity-check in offsets=0 mode. */
|
|
|
|
typedef struct Fts5Termset Fts5Termset;
|
|
|
|
int sqlite3Fts5TermsetNew(Fts5Termset**);
|
2015-12-21 21:45:09 +03:00
|
|
|
int sqlite3Fts5TermsetAdd(Fts5Termset*, int, const char*, int, int *pbPresent);
|
2015-12-17 23:36:13 +03:00
|
|
|
void sqlite3Fts5TermsetFree(Fts5Termset*);
|
|
|
|
|
2014-07-03 00:18:49 +04:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_buffer.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/**************************************************************************
|
|
|
|
** Interface to code in fts5_index.c. fts5_index.c contains contains code
|
|
|
|
** to access the data stored in the %_data table.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct Fts5Index Fts5Index;
|
|
|
|
typedef struct Fts5IndexIter Fts5IndexIter;
|
|
|
|
|
2016-01-22 22:48:34 +03:00
|
|
|
struct Fts5IndexIter {
|
|
|
|
i64 iRowid;
|
|
|
|
const u8 *pData;
|
|
|
|
int nData;
|
2016-02-02 20:40:41 +03:00
|
|
|
u8 bEof;
|
2016-01-22 22:48:34 +03:00
|
|
|
};
|
|
|
|
|
2016-02-02 20:40:41 +03:00
|
|
|
#define sqlite3Fts5IterEof(x) ((x)->bEof)
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
|
|
|
** Values used as part of the flags argument passed to IndexQuery().
|
|
|
|
*/
|
2023-12-01 23:09:59 +03:00
|
|
|
#define FTS5INDEX_QUERY_PREFIX 0x0001 /* Prefix query */
|
|
|
|
#define FTS5INDEX_QUERY_DESC 0x0002 /* Docs in descending rowid order */
|
|
|
|
#define FTS5INDEX_QUERY_TEST_NOIDX 0x0004 /* Do not use prefix index */
|
|
|
|
#define FTS5INDEX_QUERY_SCAN 0x0008 /* Scan query (fts5vocab) */
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2016-02-03 23:04:59 +03:00
|
|
|
/* The following are used internally by the fts5_index.c module. They are
|
|
|
|
** defined here only to make it easier to avoid clashes with the flags
|
|
|
|
** above. */
|
2023-12-01 23:09:59 +03:00
|
|
|
#define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
|
|
|
|
#define FTS5INDEX_QUERY_NOOUTPUT 0x0020
|
|
|
|
#define FTS5INDEX_QUERY_SKIPHASH 0x0040
|
|
|
|
#define FTS5INDEX_QUERY_NOTOKENDATA 0x0080
|
2023-12-02 20:32:16 +03:00
|
|
|
#define FTS5INDEX_QUERY_SCANONETERM 0x0100
|
2016-02-03 23:04:59 +03:00
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
|
|
|
** Create/destroy an Fts5Index object.
|
|
|
|
*/
|
|
|
|
int sqlite3Fts5IndexOpen(Fts5Config *pConfig, int bCreate, Fts5Index**, char**);
|
2015-04-28 21:35:28 +03:00
|
|
|
int sqlite3Fts5IndexClose(Fts5Index *p);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2016-01-14 17:29:57 +03:00
|
|
|
/*
|
|
|
|
** Return a simple checksum value based on the arguments.
|
|
|
|
*/
|
|
|
|
u64 sqlite3Fts5IndexEntryCksum(
|
|
|
|
i64 iRowid,
|
|
|
|
int iCol,
|
|
|
|
int iPos,
|
|
|
|
int iIdx,
|
|
|
|
const char *pTerm,
|
|
|
|
int nTerm
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Argument p points to a buffer containing utf-8 text that is n bytes in
|
|
|
|
** size. Return the number of bytes in the nChar character prefix of the
|
|
|
|
** buffer, or 0 if there are less than nChar characters in total.
|
|
|
|
*/
|
|
|
|
int sqlite3Fts5IndexCharlenToBytelen(
|
|
|
|
const char *p,
|
|
|
|
int nByte,
|
|
|
|
int nChar
|
|
|
|
);
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
2015-08-05 10:43:46 +03:00
|
|
|
** Open a new iterator to iterate though all rowids that match the
|
2014-06-23 15:33:22 +04:00
|
|
|
** specified token or token prefix.
|
|
|
|
*/
|
2014-12-03 20:27:35 +03:00
|
|
|
int sqlite3Fts5IndexQuery(
|
2014-06-23 15:33:22 +04:00
|
|
|
Fts5Index *p, /* FTS index to query */
|
|
|
|
const char *pToken, int nToken, /* Token (or prefix) to query for */
|
2014-12-03 20:27:35 +03:00
|
|
|
int flags, /* Mask of FTS5INDEX_QUERY_X flags */
|
2015-10-07 12:02:50 +03:00
|
|
|
Fts5Colset *pColset, /* Match these columns only */
|
2015-10-06 23:53:26 +03:00
|
|
|
Fts5IndexIter **ppIter /* OUT: New iterator object */
|
2014-06-23 15:33:22 +04:00
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
2015-01-29 23:59:34 +03:00
|
|
|
** The various operations on open token or token prefix iterators opened
|
|
|
|
** using sqlite3Fts5IndexQuery().
|
2014-06-23 15:33:22 +04:00
|
|
|
*/
|
2014-12-03 20:27:35 +03:00
|
|
|
int sqlite3Fts5IterNext(Fts5IndexIter*);
|
|
|
|
int sqlite3Fts5IterNextFrom(Fts5IndexIter*, i64 iMatch);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Close an iterator opened by sqlite3Fts5IndexQuery().
|
|
|
|
*/
|
|
|
|
void sqlite3Fts5IterClose(Fts5IndexIter*);
|
|
|
|
|
2019-10-20 11:26:08 +03:00
|
|
|
/*
|
|
|
|
** Close the reader blob handle, if it is open.
|
|
|
|
*/
|
|
|
|
void sqlite3Fts5IndexCloseReader(Fts5Index*);
|
|
|
|
|
2015-05-08 23:21:24 +03:00
|
|
|
/*
|
|
|
|
** This interface is used by the fts5vocab module.
|
|
|
|
*/
|
|
|
|
const char *sqlite3Fts5IterTerm(Fts5IndexIter*, int*);
|
|
|
|
int sqlite3Fts5IterNextScan(Fts5IndexIter*);
|
2021-07-07 14:51:03 +03:00
|
|
|
void *sqlite3Fts5StructureRef(Fts5Index*);
|
|
|
|
void sqlite3Fts5StructureRelease(void*);
|
|
|
|
int sqlite3Fts5StructureTest(Fts5Index*, void*);
|
2015-05-08 23:21:24 +03:00
|
|
|
|
2023-11-15 14:45:19 +03:00
|
|
|
/*
|
2023-12-02 23:35:04 +03:00
|
|
|
** Used by xInstToken():
|
2023-11-15 14:45:19 +03:00
|
|
|
*/
|
2023-12-01 23:09:59 +03:00
|
|
|
int sqlite3Fts5IterToken(Fts5IndexIter*, i64, int, int, const char**, int*);
|
2015-05-08 23:21:24 +03:00
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
|
|
|
** Insert or remove data to or from the index. Each time a document is
|
|
|
|
** added to or removed from the index, this function is called one or more
|
|
|
|
** times.
|
|
|
|
**
|
|
|
|
** For an insert, it must be called once for each token in the new document.
|
|
|
|
** If the operation is a delete, it must be called (at least) once for each
|
|
|
|
** unique token in the document with an iCol value less than zero. The iPos
|
|
|
|
** argument is ignored for a delete.
|
|
|
|
*/
|
2014-12-03 20:27:35 +03:00
|
|
|
int sqlite3Fts5IndexWrite(
|
2014-06-23 15:33:22 +04:00
|
|
|
Fts5Index *p, /* Index to write to */
|
|
|
|
int iCol, /* Column token appears in (-ve -> delete) */
|
|
|
|
int iPos, /* Position of token within column */
|
|
|
|
const char *pToken, int nToken /* Token to add or remove to or from index */
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Indicate that subsequent calls to sqlite3Fts5IndexWrite() pertain to
|
|
|
|
** document iDocid.
|
|
|
|
*/
|
2014-12-03 20:27:35 +03:00
|
|
|
int sqlite3Fts5IndexBeginWrite(
|
2014-06-23 15:33:22 +04:00
|
|
|
Fts5Index *p, /* Index to write to */
|
2015-10-02 23:04:30 +03:00
|
|
|
int bDelete, /* True if current operation is a delete */
|
2014-06-23 15:33:22 +04:00
|
|
|
i64 iDocid /* Docid to add or remove data from */
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Flush any data stored in the in-memory hash tables to the database.
|
2017-04-08 12:12:20 +03:00
|
|
|
** Also close any open blob handles.
|
2014-06-23 15:33:22 +04:00
|
|
|
*/
|
2017-04-08 12:12:20 +03:00
|
|
|
int sqlite3Fts5IndexSync(Fts5Index *p);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Discard any data stored in the in-memory hash tables. Do not write it
|
|
|
|
** to the database. Additionally, assume that the contents of the %_data
|
|
|
|
** table may have changed on disk. So any in-memory caches of %_data
|
|
|
|
** records must be invalidated.
|
|
|
|
*/
|
|
|
|
int sqlite3Fts5IndexRollback(Fts5Index *p);
|
|
|
|
|
|
|
|
/*
|
2015-09-03 17:22:27 +03:00
|
|
|
** Get or set the "averages" values.
|
2014-06-23 15:33:22 +04:00
|
|
|
*/
|
2015-09-03 17:22:27 +03:00
|
|
|
int sqlite3Fts5IndexGetAverages(Fts5Index *p, i64 *pnRow, i64 *anSize);
|
2014-08-06 20:30:21 +04:00
|
|
|
int sqlite3Fts5IndexSetAverages(Fts5Index *p, const u8*, int);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Functions called by the storage module as part of integrity-check.
|
|
|
|
*/
|
2020-09-21 17:53:21 +03:00
|
|
|
int sqlite3Fts5IndexIntegrityCheck(Fts5Index*, u64 cksum, int bUseCksum);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2014-08-06 20:30:21 +04:00
|
|
|
/*
|
|
|
|
** Called during virtual module initialization to register UDF
|
|
|
|
** fts5_decode() with SQLite
|
|
|
|
*/
|
2014-06-23 15:33:22 +04:00
|
|
|
int sqlite3Fts5IndexInit(sqlite3*);
|
|
|
|
|
2014-11-28 23:01:13 +03:00
|
|
|
int sqlite3Fts5IndexSetCookie(Fts5Index*, int);
|
2014-08-18 23:30:01 +04:00
|
|
|
|
2014-08-06 20:30:21 +04:00
|
|
|
/*
|
|
|
|
** Return the total number of entries read from the %_data table by
|
|
|
|
** this connection since it was created.
|
|
|
|
*/
|
2014-08-03 00:49:36 +04:00
|
|
|
int sqlite3Fts5IndexReads(Fts5Index *p);
|
|
|
|
|
2015-01-07 20:11:11 +03:00
|
|
|
int sqlite3Fts5IndexReinit(Fts5Index *p);
|
2015-01-07 22:33:11 +03:00
|
|
|
int sqlite3Fts5IndexOptimize(Fts5Index *p);
|
2015-04-27 14:31:56 +03:00
|
|
|
int sqlite3Fts5IndexMerge(Fts5Index *p, int nMerge);
|
2016-03-16 22:48:10 +03:00
|
|
|
int sqlite3Fts5IndexReset(Fts5Index *p);
|
2015-01-07 20:11:11 +03:00
|
|
|
|
2015-01-17 23:01:52 +03:00
|
|
|
int sqlite3Fts5IndexLoadConfig(Fts5Index *p);
|
|
|
|
|
2023-07-17 20:59:58 +03:00
|
|
|
int sqlite3Fts5IndexGetOrigin(Fts5Index *p, i64 *piOrigin);
|
|
|
|
int sqlite3Fts5IndexContentlessDelete(Fts5Index *p, i64 iOrigin, i64 iRowid);
|
2023-07-10 23:44:09 +03:00
|
|
|
|
2023-11-22 22:02:54 +03:00
|
|
|
void sqlite3Fts5IndexIterClearTokendata(Fts5IndexIter*);
|
2023-12-02 23:35:04 +03:00
|
|
|
|
|
|
|
/* Used to populate hash tables for xInstToken in detail=none/column mode. */
|
2023-11-22 22:02:54 +03:00
|
|
|
int sqlite3Fts5IndexIterWriteTokendata(
|
2023-12-01 23:09:59 +03:00
|
|
|
Fts5IndexIter*, const char*, int, i64 iRowid, int iCol, int iOff
|
2023-11-22 22:02:54 +03:00
|
|
|
);
|
|
|
|
|
2015-05-30 14:49:58 +03:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_index.c.
|
|
|
|
**************************************************************************/
|
2015-01-22 22:13:08 +03:00
|
|
|
|
2015-05-30 14:49:58 +03:00
|
|
|
/**************************************************************************
|
|
|
|
** Interface to code in fts5_varint.c.
|
|
|
|
*/
|
|
|
|
int sqlite3Fts5GetVarint32(const unsigned char *p, u32 *v);
|
2015-02-25 22:24:37 +03:00
|
|
|
int sqlite3Fts5GetVarintLen(u32 iVal);
|
2015-05-30 14:49:58 +03:00
|
|
|
u8 sqlite3Fts5GetVarint(const unsigned char*, u64*);
|
|
|
|
int sqlite3Fts5PutVarint(unsigned char *p, u64 v);
|
|
|
|
|
2023-05-03 16:48:33 +03:00
|
|
|
#define fts5GetVarint32(a,b) sqlite3Fts5GetVarint32(a,(u32*)&(b))
|
2015-05-30 14:49:58 +03:00
|
|
|
#define fts5GetVarint sqlite3Fts5GetVarint
|
2015-02-25 22:24:37 +03:00
|
|
|
|
2015-10-07 16:24:27 +03:00
|
|
|
#define fts5FastGetVarint32(a, iOff, nVal) { \
|
|
|
|
nVal = (a)[iOff++]; \
|
|
|
|
if( nVal & 0x80 ){ \
|
|
|
|
iOff--; \
|
|
|
|
iOff += fts5GetVarint32(&(a)[iOff], nVal); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
2015-05-30 14:49:58 +03:00
|
|
|
** End of interface to code in fts5_varint.c.
|
2014-06-23 15:33:22 +04:00
|
|
|
**************************************************************************/
|
|
|
|
|
2015-05-30 14:49:58 +03:00
|
|
|
|
2015-05-08 23:21:24 +03:00
|
|
|
/**************************************************************************
|
2019-01-17 20:39:15 +03:00
|
|
|
** Interface to code in fts5_main.c.
|
2015-05-08 23:21:24 +03:00
|
|
|
*/
|
|
|
|
|
2019-01-17 20:39:15 +03:00
|
|
|
/*
|
|
|
|
** Virtual-table object.
|
|
|
|
*/
|
|
|
|
typedef struct Fts5Table Fts5Table;
|
|
|
|
struct Fts5Table {
|
|
|
|
sqlite3_vtab base; /* Base class used by SQLite core */
|
|
|
|
Fts5Config *pConfig; /* Virtual table configuration */
|
|
|
|
Fts5Index *pIndex; /* Full-text index */
|
|
|
|
};
|
|
|
|
|
2024-05-13 23:06:08 +03:00
|
|
|
int sqlite3Fts5LoadTokenizer(Fts5Config *pConfig);
|
2015-05-08 23:21:24 +03:00
|
|
|
|
2019-01-17 20:39:15 +03:00
|
|
|
Fts5Table *sqlite3Fts5TableFromCsrid(Fts5Global*, i64);
|
|
|
|
|
|
|
|
int sqlite3Fts5FlushToDisk(Fts5Table*);
|
2015-05-08 23:21:24 +03:00
|
|
|
|
2024-07-26 23:50:33 +03:00
|
|
|
void sqlite3Fts5ClearLocale(Fts5Config *pConfig);
|
2024-09-10 19:19:31 +03:00
|
|
|
void sqlite3Fts5SetLocale(Fts5Config *pConfig, const char *pLoc, int nLoc);
|
2024-07-26 23:50:33 +03:00
|
|
|
|
2024-09-07 19:22:22 +03:00
|
|
|
int sqlite3Fts5IsLocaleValue(Fts5Config *pConfig, sqlite3_value *pVal);
|
2024-09-10 19:19:31 +03:00
|
|
|
int sqlite3Fts5DecodeLocaleValue(sqlite3_value *pVal,
|
|
|
|
const char **ppText, int *pnText, const char **ppLoc, int *pnLoc
|
|
|
|
);
|
2024-09-07 19:22:22 +03:00
|
|
|
|
2015-05-08 23:21:24 +03:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/**************************************************************************
|
2014-08-11 23:44:52 +04:00
|
|
|
** Interface to code in fts5_hash.c.
|
|
|
|
*/
|
|
|
|
typedef struct Fts5Hash Fts5Hash;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Create a hash table, free a hash table.
|
|
|
|
*/
|
2015-12-17 23:36:13 +03:00
|
|
|
int sqlite3Fts5HashNew(Fts5Config*, Fts5Hash**, int *pnSize);
|
2014-08-11 23:44:52 +04:00
|
|
|
void sqlite3Fts5HashFree(Fts5Hash*);
|
|
|
|
|
|
|
|
int sqlite3Fts5HashWrite(
|
|
|
|
Fts5Hash*,
|
|
|
|
i64 iRowid, /* Rowid for this entry */
|
|
|
|
int iCol, /* Column token appears in (-ve -> delete) */
|
|
|
|
int iPos, /* Position of token within column */
|
2015-05-07 22:29:46 +03:00
|
|
|
char bByte,
|
2014-08-11 23:44:52 +04:00
|
|
|
const char *pToken, int nToken /* Token to add or remove to or from index */
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Empty (but do not delete) a hash table.
|
|
|
|
*/
|
|
|
|
void sqlite3Fts5HashClear(Fts5Hash*);
|
|
|
|
|
2023-07-22 22:47:46 +03:00
|
|
|
/*
|
|
|
|
** Return true if the hash is empty, false otherwise.
|
|
|
|
*/
|
|
|
|
int sqlite3Fts5HashIsEmpty(Fts5Hash*);
|
|
|
|
|
2015-01-24 22:57:03 +03:00
|
|
|
int sqlite3Fts5HashQuery(
|
|
|
|
Fts5Hash*, /* Hash table to query */
|
2019-03-18 18:23:20 +03:00
|
|
|
int nPre,
|
2015-01-24 22:57:03 +03:00
|
|
|
const char *pTerm, int nTerm, /* Query term */
|
2019-03-18 18:23:20 +03:00
|
|
|
void **ppObj, /* OUT: Pointer to doclist for pTerm */
|
2015-01-29 23:59:34 +03:00
|
|
|
int *pnDoclist /* OUT: Size of doclist in bytes */
|
|
|
|
);
|
|
|
|
|
2015-02-27 10:23:26 +03:00
|
|
|
int sqlite3Fts5HashScanInit(
|
2015-01-29 23:59:34 +03:00
|
|
|
Fts5Hash*, /* Hash table to query */
|
|
|
|
const char *pTerm, int nTerm /* Query prefix */
|
|
|
|
);
|
|
|
|
void sqlite3Fts5HashScanNext(Fts5Hash*);
|
|
|
|
int sqlite3Fts5HashScanEof(Fts5Hash*);
|
|
|
|
void sqlite3Fts5HashScanEntry(Fts5Hash *,
|
|
|
|
const char **pzTerm, /* OUT: term (nul-terminated) */
|
2023-09-30 21:13:35 +03:00
|
|
|
int *pnTerm, /* OUT: Size of term in bytes */
|
2015-03-07 18:46:41 +03:00
|
|
|
const u8 **ppDoclist, /* OUT: pointer to doclist */
|
2015-01-29 23:59:34 +03:00
|
|
|
int *pnDoclist /* OUT: size of doclist in bytes */
|
2015-01-24 22:57:03 +03:00
|
|
|
);
|
2014-08-11 23:44:52 +04:00
|
|
|
|
|
|
|
|
2023-07-22 22:47:46 +03:00
|
|
|
|
2014-08-11 23:44:52 +04:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_hash.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
2014-06-23 15:33:22 +04:00
|
|
|
** Interface to code in fts5_storage.c. fts5_storage.c contains contains
|
|
|
|
** code to access the data stored in the %_content and %_docsize tables.
|
|
|
|
*/
|
2014-06-26 00:28:38 +04:00
|
|
|
|
|
|
|
#define FTS5_STMT_SCAN_ASC 0 /* SELECT rowid, * FROM ... ORDER BY 1 ASC */
|
|
|
|
#define FTS5_STMT_SCAN_DESC 1 /* SELECT rowid, * FROM ... ORDER BY 1 DESC */
|
|
|
|
#define FTS5_STMT_LOOKUP 2 /* SELECT rowid, * FROM ... WHERE rowid=? */
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
typedef struct Fts5Storage Fts5Storage;
|
|
|
|
|
|
|
|
int sqlite3Fts5StorageOpen(Fts5Config*, Fts5Index*, int, Fts5Storage**, char**);
|
2015-04-28 21:35:28 +03:00
|
|
|
int sqlite3Fts5StorageClose(Fts5Storage *p);
|
2015-06-10 13:45:34 +03:00
|
|
|
int sqlite3Fts5StorageRename(Fts5Storage*, const char *zName);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2015-04-28 21:35:28 +03:00
|
|
|
int sqlite3Fts5DropAll(Fts5Config*);
|
2014-11-27 23:03:45 +03:00
|
|
|
int sqlite3Fts5CreateTable(Fts5Config*, const char*, const char*, int, char **);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2024-07-27 22:46:10 +03:00
|
|
|
int sqlite3Fts5StorageDelete(Fts5Storage *p, i64, sqlite3_value**, int);
|
2015-10-02 23:04:30 +03:00
|
|
|
int sqlite3Fts5StorageContentInsert(Fts5Storage *p, sqlite3_value**, i64*);
|
|
|
|
int sqlite3Fts5StorageIndexInsert(Fts5Storage *p, sqlite3_value**, i64);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2020-09-21 17:53:21 +03:00
|
|
|
int sqlite3Fts5StorageIntegrity(Fts5Storage *p, int iArg);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2015-01-05 23:41:39 +03:00
|
|
|
int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt**, char**);
|
2014-06-24 20:59:06 +04:00
|
|
|
void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*);
|
|
|
|
|
2014-07-19 19:35:09 +04:00
|
|
|
int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
|
2014-07-26 00:30:47 +04:00
|
|
|
int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
|
|
|
|
int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
|
2014-07-19 19:35:09 +04:00
|
|
|
|
2017-04-08 12:12:20 +03:00
|
|
|
int sqlite3Fts5StorageSync(Fts5Storage *p);
|
2014-08-12 20:07:35 +04:00
|
|
|
int sqlite3Fts5StorageRollback(Fts5Storage *p);
|
2014-06-24 20:59:06 +04:00
|
|
|
|
2015-05-07 22:29:46 +03:00
|
|
|
int sqlite3Fts5StorageConfigValue(
|
|
|
|
Fts5Storage *p, const char*, sqlite3_value*, int
|
|
|
|
);
|
2014-11-27 23:03:45 +03:00
|
|
|
|
2015-01-07 20:11:11 +03:00
|
|
|
int sqlite3Fts5StorageDeleteAll(Fts5Storage *p);
|
|
|
|
int sqlite3Fts5StorageRebuild(Fts5Storage *p);
|
2015-01-07 22:33:11 +03:00
|
|
|
int sqlite3Fts5StorageOptimize(Fts5Storage *p);
|
2015-04-27 14:31:56 +03:00
|
|
|
int sqlite3Fts5StorageMerge(Fts5Storage *p, int nMerge);
|
2016-03-16 22:48:10 +03:00
|
|
|
int sqlite3Fts5StorageReset(Fts5Storage *p);
|
2015-01-07 20:11:11 +03:00
|
|
|
|
2024-07-27 22:46:10 +03:00
|
|
|
void sqlite3Fts5StorageReleaseDeleteRow(Fts5Storage*);
|
|
|
|
int sqlite3Fts5StorageFindDeleteRow(Fts5Storage *p, i64 iDel);
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_storage.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
** Interface to code in fts5_expr.c.
|
|
|
|
*/
|
|
|
|
typedef struct Fts5Expr Fts5Expr;
|
2014-06-26 00:28:38 +04:00
|
|
|
typedef struct Fts5ExprNode Fts5ExprNode;
|
2014-06-23 15:33:22 +04:00
|
|
|
typedef struct Fts5Parse Fts5Parse;
|
|
|
|
typedef struct Fts5Token Fts5Token;
|
|
|
|
typedef struct Fts5ExprPhrase Fts5ExprPhrase;
|
|
|
|
typedef struct Fts5ExprNearset Fts5ExprNearset;
|
|
|
|
|
|
|
|
struct Fts5Token {
|
|
|
|
const char *p; /* Token text (not NULL terminated) */
|
|
|
|
int n; /* Size of buffer p in bytes */
|
|
|
|
};
|
|
|
|
|
2014-06-26 00:28:38 +04:00
|
|
|
/* Parse a MATCH expression. */
|
2014-06-23 15:33:22 +04:00
|
|
|
int sqlite3Fts5ExprNew(
|
|
|
|
Fts5Config *pConfig,
|
2020-10-05 19:41:56 +03:00
|
|
|
int bPhraseToAnd,
|
2017-04-13 12:45:21 +03:00
|
|
|
int iCol, /* Column on LHS of MATCH operator */
|
2014-06-23 15:33:22 +04:00
|
|
|
const char *zExpr,
|
|
|
|
Fts5Expr **ppNew,
|
|
|
|
char **pzErr
|
|
|
|
);
|
2020-10-05 19:41:56 +03:00
|
|
|
int sqlite3Fts5ExprPattern(
|
|
|
|
Fts5Config *pConfig,
|
|
|
|
int bGlob,
|
|
|
|
int iCol,
|
|
|
|
const char *zText,
|
|
|
|
Fts5Expr **pp
|
|
|
|
);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2014-06-26 00:28:38 +04:00
|
|
|
/*
|
2015-01-24 22:57:03 +03:00
|
|
|
** for(rc = sqlite3Fts5ExprFirst(pExpr, pIdx, bDesc);
|
2014-06-26 00:28:38 +04:00
|
|
|
** rc==SQLITE_OK && 0==sqlite3Fts5ExprEof(pExpr);
|
|
|
|
** rc = sqlite3Fts5ExprNext(pExpr)
|
|
|
|
** ){
|
|
|
|
** // The document with rowid iRowid matches the expression!
|
|
|
|
** i64 iRowid = sqlite3Fts5ExprRowid(pExpr);
|
|
|
|
** }
|
|
|
|
*/
|
2015-06-05 22:05:57 +03:00
|
|
|
int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc);
|
|
|
|
int sqlite3Fts5ExprNext(Fts5Expr*, i64 iMax);
|
2014-06-26 00:28:38 +04:00
|
|
|
int sqlite3Fts5ExprEof(Fts5Expr*);
|
|
|
|
i64 sqlite3Fts5ExprRowid(Fts5Expr*);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2014-06-26 00:28:38 +04:00
|
|
|
void sqlite3Fts5ExprFree(Fts5Expr*);
|
2019-09-12 22:38:40 +03:00
|
|
|
int sqlite3Fts5ExprAnd(Fts5Expr **pp1, Fts5Expr *p2);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
/* Called during startup to register a UDF with SQLite */
|
2014-11-15 23:07:31 +03:00
|
|
|
int sqlite3Fts5ExprInit(Fts5Global*, sqlite3*);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
2014-07-16 23:15:57 +04:00
|
|
|
int sqlite3Fts5ExprPhraseCount(Fts5Expr*);
|
|
|
|
int sqlite3Fts5ExprPhraseSize(Fts5Expr*, int iPhrase);
|
|
|
|
int sqlite3Fts5ExprPoslist(Fts5Expr*, int, const u8 **);
|
|
|
|
|
2016-01-04 22:12:00 +03:00
|
|
|
typedef struct Fts5PoslistPopulator Fts5PoslistPopulator;
|
2016-01-06 00:04:35 +03:00
|
|
|
Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr*, int);
|
2015-12-28 22:55:00 +03:00
|
|
|
int sqlite3Fts5ExprPopulatePoslists(
|
2016-01-04 22:12:00 +03:00
|
|
|
Fts5Config*, Fts5Expr*, Fts5PoslistPopulator*, int, const char*, int
|
2015-12-28 22:55:00 +03:00
|
|
|
);
|
2016-01-02 22:01:56 +03:00
|
|
|
void sqlite3Fts5ExprCheckPoslists(Fts5Expr*, i64);
|
2015-12-28 22:55:00 +03:00
|
|
|
|
2016-02-11 20:01:32 +03:00
|
|
|
int sqlite3Fts5ExprClonePhrase(Fts5Expr*, int, Fts5Expr**);
|
2014-07-26 00:30:47 +04:00
|
|
|
|
2015-12-29 22:35:03 +03:00
|
|
|
int sqlite3Fts5ExprPhraseCollist(Fts5Expr *, int, const u8 **, int *);
|
|
|
|
|
2023-11-13 17:29:12 +03:00
|
|
|
int sqlite3Fts5ExprQueryToken(Fts5Expr*, int, int, const char**, int*);
|
2023-12-04 20:45:33 +03:00
|
|
|
int sqlite3Fts5ExprInstToken(Fts5Expr*, i64, int, int, int, int, const char**, int*);
|
2023-12-02 20:32:16 +03:00
|
|
|
void sqlite3Fts5ExprClearTokens(Fts5Expr*);
|
2023-11-13 17:29:12 +03:00
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
/*******************************************
|
|
|
|
** The fts5_expr.c API above this point is used by the other hand-written
|
|
|
|
** C code in this module. The interfaces below this point are called by
|
|
|
|
** the parser code in fts5parse.y. */
|
|
|
|
|
|
|
|
void sqlite3Fts5ParseError(Fts5Parse *pParse, const char *zFmt, ...);
|
|
|
|
|
2014-06-26 00:28:38 +04:00
|
|
|
Fts5ExprNode *sqlite3Fts5ParseNode(
|
|
|
|
Fts5Parse *pParse,
|
|
|
|
int eType,
|
|
|
|
Fts5ExprNode *pLeft,
|
|
|
|
Fts5ExprNode *pRight,
|
2014-06-23 15:33:22 +04:00
|
|
|
Fts5ExprNearset *pNear
|
|
|
|
);
|
|
|
|
|
2016-03-12 19:32:16 +03:00
|
|
|
Fts5ExprNode *sqlite3Fts5ParseImplicitAnd(
|
|
|
|
Fts5Parse *pParse,
|
|
|
|
Fts5ExprNode *pLeft,
|
|
|
|
Fts5ExprNode *pRight
|
|
|
|
);
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
Fts5ExprPhrase *sqlite3Fts5ParseTerm(
|
|
|
|
Fts5Parse *pParse,
|
|
|
|
Fts5ExprPhrase *pPhrase,
|
|
|
|
Fts5Token *pToken,
|
|
|
|
int bPrefix
|
|
|
|
);
|
|
|
|
|
2017-11-24 22:24:44 +03:00
|
|
|
void sqlite3Fts5ParseSetCaret(Fts5ExprPhrase*);
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
Fts5ExprNearset *sqlite3Fts5ParseNearset(
|
|
|
|
Fts5Parse*,
|
|
|
|
Fts5ExprNearset*,
|
|
|
|
Fts5ExprPhrase*
|
|
|
|
);
|
|
|
|
|
2015-10-07 12:02:50 +03:00
|
|
|
Fts5Colset *sqlite3Fts5ParseColset(
|
2015-05-29 18:55:30 +03:00
|
|
|
Fts5Parse*,
|
2015-10-07 12:02:50 +03:00
|
|
|
Fts5Colset*,
|
2015-05-29 18:55:30 +03:00
|
|
|
Fts5Token *
|
|
|
|
);
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
|
|
|
|
void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
|
2014-06-26 00:28:38 +04:00
|
|
|
void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
|
2014-06-23 15:33:22 +04:00
|
|
|
|
|
|
|
void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
|
2017-04-12 20:50:12 +03:00
|
|
|
void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
|
2016-08-09 22:48:37 +03:00
|
|
|
Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
|
2014-06-26 00:28:38 +04:00
|
|
|
void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
|
2014-06-23 15:33:22 +04:00
|
|
|
void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_expr.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2014-07-16 23:15:57 +04:00
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
|
2014-07-16 23:15:57 +04:00
|
|
|
/**************************************************************************
|
2014-11-15 23:07:31 +03:00
|
|
|
** Interface to code in fts5_aux.c.
|
2014-07-16 23:15:57 +04:00
|
|
|
*/
|
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
int sqlite3Fts5AuxInit(fts5_api*);
|
2014-07-16 23:15:57 +04:00
|
|
|
/*
|
2014-11-15 23:07:31 +03:00
|
|
|
** End of interface to code in fts5_aux.c.
|
2014-07-16 23:15:57 +04:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
2014-11-15 23:07:31 +03:00
|
|
|
** Interface to code in fts5_tokenizer.c.
|
2014-07-16 23:15:57 +04:00
|
|
|
*/
|
|
|
|
|
2014-11-15 23:07:31 +03:00
|
|
|
int sqlite3Fts5TokenizerInit(fts5_api*);
|
2020-09-30 23:35:37 +03:00
|
|
|
int sqlite3Fts5TokenizerPattern(
|
|
|
|
int (*xCreate)(void*, const char**, int, Fts5Tokenizer**),
|
|
|
|
Fts5Tokenizer *pTok
|
|
|
|
);
|
2024-05-14 20:16:09 +03:00
|
|
|
int sqlite3Fts5TokenizerPreload(Fts5TokenizerConfig*);
|
2014-07-16 23:15:57 +04:00
|
|
|
/*
|
2014-11-15 23:07:31 +03:00
|
|
|
** End of interface to code in fts5_tokenizer.c.
|
2014-07-30 23:41:58 +04:00
|
|
|
**************************************************************************/
|
|
|
|
|
2015-05-08 23:21:24 +03:00
|
|
|
/**************************************************************************
|
|
|
|
** Interface to code in fts5_vocab.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int sqlite3Fts5VocabInit(Fts5Global*, sqlite3*);
|
|
|
|
|
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_vocab.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2015-05-22 09:08:25 +03:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
** Interface to automatically generated code in fts5_unicode2.c.
|
|
|
|
*/
|
|
|
|
int sqlite3Fts5UnicodeIsdiacritic(int c);
|
|
|
|
int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic);
|
2018-07-13 22:52:43 +03:00
|
|
|
|
|
|
|
int sqlite3Fts5UnicodeCatParse(const char*, u8*);
|
2018-12-28 10:37:22 +03:00
|
|
|
int sqlite3Fts5UnicodeCategory(u32 iCode);
|
2018-07-13 22:52:43 +03:00
|
|
|
void sqlite3Fts5UnicodeAscii(u8*, u8*);
|
2015-05-22 09:08:25 +03:00
|
|
|
/*
|
|
|
|
** End of interface to code in fts5_unicode2.c.
|
|
|
|
**************************************************************************/
|
|
|
|
|
2014-06-23 15:33:22 +04:00
|
|
|
#endif
|