|
Couchbase Lite C
Couchbase Lite C API
|
Indexes are used to speed up queries by allowing fast – O(log n) – lookup of documents that have specific values or ranges of values. More...
Data Structures | |
| struct | CBLValueIndexConfiguration |
| Value Index Configuration. More... | |
| struct | CBLFullTextIndexConfiguration |
| Full-Text Index Configuration. More... | |
| struct | CBLArrayIndexConfiguration |
| Array Index Configuration for indexing property values within arrays in documents, intended for use with the UNNEST query. More... | |
| struct | CBLVectorIndexConfiguration |
| ENTERPRISE EDITION ONLY. More... | |
Typedefs | |
| typedef struct CBLQueryIndex | CBLQueryIndex |
| A query index. | |
| typedef struct CBLIndexUpdater | CBLIndexUpdater |
CBLQueryIndex | |
CBLQueryIndex represents an existing index in a collection. Available in the enterprise edition, the CBLQueryIndex can be used to obtain a CBLIndexUpdater object for updating the vector index in lazy mode. | |
| CBLINLINE const CBLQueryIndex * | CBLQueryIndex_Retain (const CBLQueryIndex *_cbl_nullable t) |
| CBLINLINE void | CBLQueryIndex_Release (const CBLQueryIndex *_cbl_nullable t) |
| FLString | CBLQueryIndex_Name (const CBLQueryIndex *index) |
| Returns the index's name. | |
| CBLCollection * | CBLQueryIndex_Collection (const CBLQueryIndex *index) |
| Returns the collection that the index belongs to. | |
| CBLINLINE const CBLIndexUpdater * | CBLIndexUpdater_Retain (const CBLIndexUpdater *_cbl_nullable t) |
| CBLINLINE void | CBLIndexUpdater_Release (const CBLIndexUpdater *_cbl_nullable t) |
| _cbl_warn_unused CBLIndexUpdater *_cbl_nullable | CBLQueryIndex_BeginUpdate (CBLQueryIndex *index, size_t limit, CBLError *_cbl_nullable outError) |
| ENTERPRISE EDITION ONLY. | |
IndexUpdater | |
CBLIndexUpdater used for updating the index in lazy mode. Currently, the vector index is the only index type that can be updated lazily. | |
| size_t | CBLIndexUpdater_Count (const CBLIndexUpdater *updater) |
| ENTERPRISE EDITION ONLY. | |
| FLValue | CBLIndexUpdater_Value (CBLIndexUpdater *updater, size_t index) |
| ENTERPRISE EDITION ONLY. | |
| bool | CBLIndexUpdater_SetVector (CBLIndexUpdater *updater, size_t index, const float vector[_cbl_nullable], size_t dimension, CBLError *_cbl_nullable outError) |
| ENTERPRISE EDITION ONLY. | |
| void | CBLIndexUpdater_SkipVector (CBLIndexUpdater *updater, size_t index) |
| ENTERPRISE EDITION ONLY. | |
| bool | CBLIndexUpdater_Finish (CBLIndexUpdater *updater, CBLError *_cbl_nullable outError) |
| ENTERPRISE EDITION ONLY. | |
Indexes are used to speed up queries by allowing fast – O(log n) – lookup of documents that have specific values or ranges of values.
The values may be properties, or expressions based on properties.
An index will speed up queries that use the expression it indexes, but it takes up space in the database file, and it slows down document saves slightly because it needs to be kept up to date when documents change.
Tuning a database with indexes can be a tricky task. Fortunately, a lot has been written about it in the relational-database (SQL) realm, and much of that advice holds for Couchbase Lite. You may find SQLite's documentation particularly helpful since Couchbase Lite's querying is based on SQLite.
Supported index types: 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() function in a query. A FTS index is required for full-text search: a query with a MATCH() function will fail to compile unless there is already a FTS index for the property/expression being matched.
(Enterprise Edition Only) Vector indexes allows efficient search of ML vectors by using the VECTOR_MATCH() function in a query. The CouchbaseLiteVectorSearch extension library is required to use the functionality. Use CBL_EnableVectorSearch function to set the directoary path containing the extension library.
| typedef struct CBLIndexUpdater CBLIndexUpdater |
| typedef struct CBLQueryIndex CBLQueryIndex |
A query index.
| typedef struct CBLVectorEncoding CBLVectorEncoding |
An opaque object representing vector encoding type to use in CBLVectorIndexConfiguration.
| enum CBLDistanceMetric : uint32_t |
| enum CBLScalarQuantizerType : uint32_t |
| size_t CBLIndexUpdater_Count | ( | const CBLIndexUpdater * | updater | ) |
ENTERPRISE EDITION ONLY.
Returns the total number of vectors to compute and set for updating the index.
| updater | The index updater. |
| bool CBLIndexUpdater_Finish | ( | CBLIndexUpdater * | updater, |
| CBLError *_cbl_nullable | outError ) |
ENTERPRISE EDITION ONLY.
Updates the index with the computed vectors and removes any index rows for which null vector was given. If there are any indexes that do not have their vector value set or are skipped, a error will be returned.
| updater | The index updater. |
| outError | On failure, an error is written here. |
| CBLINLINE void CBLIndexUpdater_Release | ( | const CBLIndexUpdater *_cbl_nullable | t | ) |
| CBLINLINE const CBLIndexUpdater * CBLIndexUpdater_Retain | ( | const CBLIndexUpdater *_cbl_nullable | t | ) |
| bool CBLIndexUpdater_SetVector | ( | CBLIndexUpdater * | updater, |
| size_t | index, | ||
| const float | vector[_cbl_nullable], | ||
| size_t | dimension, | ||
| CBLError *_cbl_nullable | outError ) |
ENTERPRISE EDITION ONLY.
Sets the vector for the value corresponding to the given index. Setting null vector means that there is no vector for the value, and any existing vector will be removed when the CBLIndexUpdater_Finish is called.
| updater | The index updater. |
| index | The zero-based index. |
| vector | A pointer to the vector which is an array of floats, or NULL if there is no vector. |
| dimension | The dimension of vector. Must be equal to the dimension value set in the vector index config. |
| outError | On failure, an error is written here. |
| void CBLIndexUpdater_SkipVector | ( | CBLIndexUpdater * | updater, |
| size_t | index ) |
ENTERPRISE EDITION ONLY.
Skip setting the vector for the value corresponding to the index. The vector will be required to compute and set again when the CBLQueryIndex_BeginUpdate is later called.
| updater | The index updater. |
| index | The zero-based index. |
| FLValue CBLIndexUpdater_Value | ( | CBLIndexUpdater * | updater, |
| size_t | index ) |
ENTERPRISE EDITION ONLY.
Returns the valut at the given index to compute a vector from.
| updater | The index updater. |
| index | The zero-based index. |
| _cbl_warn_unused CBLIndexUpdater *_cbl_nullable CBLQueryIndex_BeginUpdate | ( | CBLQueryIndex * | index, |
| size_t | limit, | ||
| CBLError *_cbl_nullable | outError ) |
ENTERPRISE EDITION ONLY.
Finds new or updated documents for which vectors need to be (re)computed and returns an CBLIndexUpdater object for setting the computed vectors to update the index. If the index is not lazy, an error will be returned.
| index | The index. |
| limit | The maximum number of vectors to be computed. |
| outError | On failure, an error is written here. |
| CBLCollection * CBLQueryIndex_Collection | ( | const CBLQueryIndex * | index | ) |
Returns the collection that the index belongs to.
| index | The index. |
| FLString CBLQueryIndex_Name | ( | const CBLQueryIndex * | index | ) |
Returns the index's name.
| index | The index. |
| CBLINLINE void CBLQueryIndex_Release | ( | const CBLQueryIndex *_cbl_nullable | t | ) |
| CBLINLINE const CBLQueryIndex * CBLQueryIndex_Retain | ( | const CBLQueryIndex *_cbl_nullable | t | ) |
| _cbl_warn_unused CBLVectorEncoding * CBLVectorEncoding_CreateNone | ( | void | ) |
Creates a no-encoding type to use in CBLVectorIndexConfiguration; 4 bytes per dimension, no data loss.
| _cbl_warn_unused CBLVectorEncoding * CBLVectorEncoding_CreateProductQuantizer | ( | unsigned | subquantizers, |
| unsigned | bits ) |
Creates a Product Quantizer encoding to use in CBLVectorIndexConfiguration.
| subquantizers | Number of subquantizers. Must be > 1 and a factor of vector dimensions. |
| bits | Number of bits. Must be >= 4 and <= 12. |
| _cbl_warn_unused CBLVectorEncoding * CBLVectorEncoding_CreateScalarQuantizer | ( | CBLScalarQuantizerType | type | ) |
Creates a Scalar Quantizer encoding to use in CBLVectorIndexConfiguration.
| type | Scalar Quantizer Type. |
| void CBLVectorEncoding_Free | ( | CBLVectorEncoding * | _cbl_nullable | ) |
Frees a CBLVectorEncoding object.
The encoding object can be freed after the index is created.