Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBL-6359: C4 APIs for the ArrayIndex #2170

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions C/include/c4IndexTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ typedef struct C4IndexOptions {
separated by spaces. */
const char* C4NULLABLE stopWords;

/** The property path to the array property to be unnested. If this property is nested in a
parent array property, e.g. interests in students[i].interests[j], the unnestPath would
be represented by students[].interests */
const char* C4NULLABLE unnestPath;

#ifdef COUCHBASE_ENTERPRISE
/** Options for vector indexes. */
C4VectorIndexOptions vector;
Expand Down
2 changes: 2 additions & 0 deletions LiteCore/Database/CollectionImpl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ namespace litecore {
IndexSpec::Options options;
switch ( indexType ) {
case kC4ValueIndex:
break;
case kC4ArrayIndex:
if ( indexOptions ) { options.emplace<IndexSpec::ArrayOptions>(indexOptions->unnestPath); }
break;
case kC4FullTextIndex:
if ( indexOptions ) {
Expand Down
11 changes: 10 additions & 1 deletion LiteCore/Query/IndexSpec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ namespace litecore {
const char* stopWords{}; ///< NULL for default, or comma-delimited string, or empty
};

/// Options for an ArrayIndex
struct ArrayOptions {
alloc_slice unnestPath;

ArrayOptions(string_view unnestPath_) : unnestPath(alloc_slice::nullPaddedString(unnestPath_)) {}
};

/// Options for a vector index.
using VectorOptions = vectorsearch::IndexSpec;

static constexpr vectorsearch::SQEncoding DefaultEncoding{8};

/// Index options. If not empty (the first state), must match the index type.
using Options = std::variant<std::monostate, FTSOptions, VectorOptions>;
using Options = std::variant<std::monostate, FTSOptions, VectorOptions, ArrayOptions>;

/// Constructs an index spec.
/// @param name_ Name of the index (must be unique in its collection.)
Expand All @@ -76,6 +83,8 @@ namespace litecore {

const VectorOptions* vectorOptions() const { return std::get_if<VectorOptions>(&options); }

const ArrayOptions* arrayOptions() const { return std::get_if<ArrayOptions>(&options); }

/** The required WHAT clause: the list of expressions to index */
FLArray what() const;

Expand Down
Loading