LiteCore
Couchbase Lite cross-platform core implementation
|
Data Structures | |
struct | C4IndexOptions |
Options for indexes; these each apply to specific types of indexes. More... | |
Enumerations | |
enum | C4IndexType : uint32_t { kC4ValueIndex , kC4FullTextIndex , kC4ArrayIndex , kC4PredictiveIndex , kC4VectorIndex } |
Functions | |
NODISCARD CBL_CORE_API bool | c4coll_createIndex (C4Collection *collection, C4String name, C4String indexSpec, C4QueryLanguage queryLanguage, C4IndexType indexType, const C4IndexOptions *indexOptions, C4Error *outError) |
Creates a collection index, of the values of specific expressions across all documents. | |
CBL_CORE_API C4Index * | c4coll_getIndex (C4Collection *collection, C4String name, C4Error *outError) |
Returns an object representing an existing index. | |
NODISCARD CBL_CORE_API bool | c4coll_deleteIndex (C4Collection *collection, C4String name, C4Error *outError) |
Deletes an index that was created by c4coll_createIndex . | |
CBL_CORE_API C4SliceResult | c4coll_getIndexesInfo (C4Collection *collection, C4Error *outError) |
Returns information about all indexes in the collection. | |
CBL_CORE_API C4SliceResult | c4db_getIndexesInfo (C4Database *database, C4Error *outError) |
Returns information about all indexes in the database. | |
CBL_CORE_API C4Slice | c4index_getName (C4Index *index) |
Returns the name of this index. | |
CBL_CORE_API C4Collection * | c4index_getCollection (C4Index *index) |
Returns the collection this index belongs to. | |
CBL_CORE_API C4IndexType | c4index_getType (C4Index *) |
Returns the index's type. | |
CBL_CORE_API C4QueryLanguage | c4index_getQueryLanguage (C4Index *) |
Returns the index's query language (JSON or N1QL). | |
CBL_CORE_API C4String | c4index_getExpression (C4Index *) |
Returns the indexed expression. | |
CBL_CORE_API bool | c4index_getOptions (C4Index *index, C4IndexOptions *outOpts) |
Gets the index's FTS/vector options, if any. | |
NODISCARD CBL_CORE_API bool | c4db_createIndex (C4Database *database, C4String name, C4String indexSpecJSON, C4IndexType indexType, const C4IndexOptions *indexOptions, C4Error *outError) |
NODISCARD CBL_CORE_API bool | c4db_createIndex2 (C4Database *database, C4String name, C4String indexSpec, C4QueryLanguage queryLanguage, C4IndexType indexType, const C4IndexOptions *indexOptions, C4Error *outError) |
NODISCARD CBL_CORE_API bool | c4db_deleteIndex (C4Database *database, C4String name, C4Error *outError) |
CBL_CORE_API bool | c4coll_isIndexTrained (C4Collection *collection, C4String name, C4Error *outError) |
Returns whether a vector index has been trained yet or not. | |
enum C4IndexType : uint32_t |
NODISCARD CBL_CORE_API bool c4coll_createIndex | ( | C4Collection * | collection, |
C4String | name, | ||
C4String | indexSpec, | ||
C4QueryLanguage | queryLanguage, | ||
C4IndexType | indexType, | ||
const C4IndexOptions * | indexOptions, | ||
C4Error * | outError ) |
Creates a collection index, of the values of specific expressions across all documents.
The name is used to identify the index for later updating or deletion; if an index with the same name already exists, it will be replaced unless it has the exact same expressions.
Currently five types of indexes are supported:
Value indexes speed up queries by making it possible to look up property (or expression) values without scanning every document. They're just like regular indexes in SQL or N1QL. Multiple expressions are supported; the first is the primary key, second is secondary. Expressions must evaluate to scalar types (boolean, number, string). Full-Text Search (FTS) indexes enable fast search of natural-language words or phrases by using the MATCH
operator in a query. A FTS index is required for full-text search: a query with a MATCH
operator will fail to compile unless there is already a FTS index for the property/expression being matched. Only a single expression is currently allowed, and it must evaluate to a string. Array indexes optimize UNNEST queries, by materializing an unnested array property (across all documents) as a table in the SQLite database, and creating a SQL index on it. Predictive indexes optimize queries that use the PREDICTION() function, by materializing the function's results as a table and creating a SQL index on a result property. Vector indexes store high-dimensional vectors/embeddings and support efficient Approximate Nearest Neighbor (ANN) queries for finding the nearest vectors to a query vector.
Note: If some documents are missing the values to be indexed, those documents will just be omitted from the index. It's not an error.
In an array index, the first expression must evaluate to an array to be unnested; it's usually a property path but could be some other expression type. If the array items are nonscalar (dictionaries or arrays), you should add a second expression defining the sub- property (or computed value) to index, relative to the array item.
In a predictive index, the expression is a PREDICTION() call in JSON query syntax, including the optional 3rd parameter that gives the result property to extract (and index.)
The indexSpec
argument is an expression, relative to a document, that describes what to index. It can be in either the JSON query schema, or in N1QL syntax. It usually names a property, but may also be a computed value based on properties.
collection | The collection to index. |
name | The name of the index. Any existing index with the same name will be replaced, unless it has the identical expressions (in which case this is a no-op.) |
indexSpec | The definition of the index in JSON or N1QL form. (See above.) |
queryLanguage | The language of indexSpec , either JSON or N1QL. |
indexType | The type of index (value full-text, etc.) |
indexOptions | Options for the index. If NULL, each option will get a default value. |
outError | On failure, will be set to the error status. |
NODISCARD CBL_CORE_API bool c4coll_deleteIndex | ( | C4Collection * | collection, |
C4String | name, | ||
C4Error * | outError ) |
Deletes an index that was created by c4coll_createIndex
.
collection | The collection to index. |
name | The name of the index to delete |
outError | On failure, will be set to the error status. |
CBL_CORE_API C4Index * c4coll_getIndex | ( | C4Collection * | collection, |
C4String | name, | ||
C4Error * | outError ) |
Returns an object representing an existing index.
CBL_CORE_API C4SliceResult c4coll_getIndexesInfo | ( | C4Collection * | collection, |
C4Error * | outError ) |
Returns information about all indexes in the collection.
The result is a Fleece-encoded array of dictionaries, one per index. Each dictionary has keys "name"
, "type"
(a C4IndexType
), and "expr"
(the source expression).
collection | The collection to check |
outError | On failure, will be set to the error status. |
CBL_CORE_API bool c4coll_isIndexTrained | ( | C4Collection * | collection, |
C4String | name, | ||
C4Error * | outError ) |
Returns whether a vector index has been trained yet or not.
If the index doesn't exist, or is not a vector index, then this method will return false with an appropriate error set. Otherwise, in the absence of errors, this method will zero the error and set the return value.
collection | The collection to index. |
name | The name of the index |
outError | On failure, will be set to the error status. |
NODISCARD CBL_CORE_API bool c4db_createIndex | ( | C4Database * | database, |
C4String | name, | ||
C4String | indexSpecJSON, | ||
C4IndexType | indexType, | ||
const C4IndexOptions * | indexOptions, | ||
C4Error * | outError ) |
NODISCARD CBL_CORE_API bool c4db_createIndex2 | ( | C4Database * | database, |
C4String | name, | ||
C4String | indexSpec, | ||
C4QueryLanguage | queryLanguage, | ||
C4IndexType | indexType, | ||
const C4IndexOptions * | indexOptions, | ||
C4Error * | outError ) |
NODISCARD CBL_CORE_API bool c4db_deleteIndex | ( | C4Database * | database, |
C4String | name, | ||
C4Error * | outError ) |
CBL_CORE_API C4SliceResult c4db_getIndexesInfo | ( | C4Database * | database, |
C4Error * | outError ) |
Returns information about all indexes in the database.
The result is a Fleece-encoded array of dictionaries, one per index. Each dictionary has keys "name"
, "type"
(a C4IndexType
), and "expr"
(the source expression).
database | The database to check |
outError | On failure, will be set to the error status. |
CBL_CORE_API C4Collection * c4index_getCollection | ( | C4Index * | index | ) |
Returns the collection this index belongs to.
CBL_CORE_API C4String c4index_getExpression | ( | C4Index * | ) |
Returns the indexed expression.
CBL_CORE_API C4Slice c4index_getName | ( | C4Index * | index | ) |
Returns the name of this index.
CBL_CORE_API bool c4index_getOptions | ( | C4Index * | index, |
C4IndexOptions * | outOpts ) |
Gets the index's FTS/vector options, if any.
index | The index. |
outOpts | The options will be written here, if they exist. |
CBL_CORE_API C4QueryLanguage c4index_getQueryLanguage | ( | C4Index * | ) |
Returns the index's query language (JSON or N1QL).
CBL_CORE_API C4IndexType c4index_getType | ( | C4Index * | ) |
Returns the index's type.