Showing content from https://couchbase.github.io/couchbase-lite-core/C/html/group___indexing.html below:
LiteCore: Indexes
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.
◆ C4IndexType Enumerator kC4ValueIndex
Regular index of property value.
kC4FullTextIndex
Full-text index.
kC4ArrayIndex
Index of array values, for use with UNNEST.
kC4PredictiveIndex
Index of prediction() results (Enterprise Edition only)
kC4VectorIndex
Index of ML vector similarity (Enterprise Edition only)
◆ c4coll_createIndex()
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.
-
Note
-
The caller must use a lock for Database when this function is called.
-
Parameters
-
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.
-
Returns
-
True on success, false on failure.
◆ c4coll_deleteIndex()
Deletes an index that was created by c4coll_createIndex
.
-
Note
-
The caller must use a lock for Database when this function is called.
-
Parameters
-
collection The collection to index. name The name of the index to delete outError On failure, will be set to the error status.
-
Returns
-
True on success, false on failure.
◆ c4coll_getIndex()
Returns an object representing an existing index.
-
Note
-
The caller must use a lock for Database when this function is called.
◆ c4coll_getIndexesInfo()
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).
-
Note
-
The caller must use a lock for Database when this function is called.
-
Parameters
-
collection The collection to check outError On failure, will be set to the error status.
-
Returns
-
A Fleece-encoded array of dictionaries, or NULL on failure.
◆ c4coll_isIndexTrained()
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.
-
Note
-
The caller must use a lock for Database when this function is called.
-
Parameters
-
collection The collection to index. name The name of the index outError On failure, will be set to the error status.
-
Returns
-
True if the index is trained.
◆ c4db_createIndex() ◆ c4db_createIndex2() ◆ c4db_deleteIndex() ◆ c4db_getIndexesInfo()
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).
-
Note
-
The caller must use a lock for Database when this function is called.
-
Parameters
-
database The database to check outError On failure, will be set to the error status.
-
Returns
-
A Fleece-encoded array of dictionaries, or NULL on failure.
◆ c4index_getCollection()
Returns the collection this index belongs to.
-
Note
-
This function is thread-safe.
◆ c4index_getExpression()
Returns the indexed expression.
-
Note
-
This function is thread-safe.
◆ c4index_getName()
Returns the name of this index.
-
Note
-
This function is thread-safe.
◆ c4index_getOptions()
Gets the index's FTS/vector options, if any.
-
Note
-
This function is thread-safe.
-
Parameters
-
index The index. outOpts The options will be written here, if they exist.
-
Returns
-
True if there are options, false if not.
◆ c4index_getQueryLanguage()
Returns the index's query language (JSON or N1QL).
-
Note
-
This function is thread-safe.
◆ c4index_getType()
Returns the index's type.
-
Note
-
This function is thread-safe.
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4