diff --git a/C/include/c4IndexTypes.h b/C/include/c4IndexTypes.h index 7a802c253..7d12d1b62 100644 --- a/C/include/c4IndexTypes.h +++ b/C/include/c4IndexTypes.h @@ -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; diff --git a/LiteCore/Database/CollectionImpl.hh b/LiteCore/Database/CollectionImpl.hh index d7d1d9275..6692eebb9 100644 --- a/LiteCore/Database/CollectionImpl.hh +++ b/LiteCore/Database/CollectionImpl.hh @@ -398,7 +398,9 @@ namespace litecore { IndexSpec::Options options; switch ( indexType ) { case kC4ValueIndex: + break; case kC4ArrayIndex: + if ( indexOptions ) { options.emplace(indexOptions->unnestPath); } break; case kC4FullTextIndex: if ( indexOptions ) { diff --git a/LiteCore/Query/IndexSpec.hh b/LiteCore/Query/IndexSpec.hh index 03390f49a..71716b148 100644 --- a/LiteCore/Query/IndexSpec.hh +++ b/LiteCore/Query/IndexSpec.hh @@ -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; + using Options = std::variant; /// Constructs an index spec. /// @param name_ Name of the index (must be unique in its collection.) @@ -76,6 +83,8 @@ namespace litecore { const VectorOptions* vectorOptions() const { return std::get_if(&options); } + const ArrayOptions* arrayOptions() const { return std::get_if(&options); } + /** The required WHAT clause: the list of expressions to index */ FLArray what() const;