From ec63eb8bbeea44274519d75d3f582dbd0cddd542 Mon Sep 17 00:00:00 2001 From: Joshua Siegel <39130209+joshbsiegel@users.noreply.github.com> Date: Wed, 10 Dec 2025 14:39:08 -0500 Subject: [PATCH] SERVER-115175 Add dedicated `LiteParsed` classes for search stages (#45076) GitOrigin-RevId: d7d4108b7255cee4dee6adf72f4215cd6d59ad43 --- .../search/document_source_search.cpp | 6 +-- .../pipeline/search/document_source_search.h | 3 ++ .../search/document_source_search_meta.cpp | 4 +- .../search/document_source_search_meta.h | 3 ++ .../search/document_source_vector_search.cpp | 4 +- .../search/document_source_vector_search.h | 3 ++ .../db/pipeline/search/lite_parsed_search.h | 38 +++++++++++-------- 7 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/mongo/db/pipeline/search/document_source_search.cpp b/src/mongo/db/pipeline/search/document_source_search.cpp index 4162ee6500c..c6346a18a7a 100644 --- a/src/mongo/db/pipeline/search/document_source_search.cpp +++ b/src/mongo/db/pipeline/search/document_source_search.cpp @@ -65,10 +65,10 @@ StringData removePrefixWorkaround(StringData key, StringData pre) { } } // namespace -ALLOCATE_STAGE_PARAMS_ID(searchStage, SearchStageStageParams::id); +ALLOCATE_STAGE_PARAMS_ID(search, SearchStageParams::id); REGISTER_DOCUMENT_SOURCE(search, - LiteParsedSearchStage::parse, + SearchLiteParsed::parse, DocumentSourceSearch::createFromBson, AllowedWithApiStrict::kNeverInVersion1); @@ -77,7 +77,7 @@ ALLOCATE_DOCUMENT_SOURCE_ID(search, DocumentSourceSearch::id) // $searchBeta is supported as an alias for $search for compatibility with applications that used // search during its beta period. REGISTER_DOCUMENT_SOURCE(searchBeta, - LiteParsedSearchStage::parse, + SearchLiteParsed::parse, DocumentSourceSearch::createFromBson, AllowedWithApiStrict::kNeverInVersion1); diff --git a/src/mongo/db/pipeline/search/document_source_search.h b/src/mongo/db/pipeline/search/document_source_search.h index 61ce14ed577..7f7b833e854 100644 --- a/src/mongo/db/pipeline/search/document_source_search.h +++ b/src/mongo/db/pipeline/search/document_source_search.h @@ -33,6 +33,7 @@ #include "mongo/db/pipeline/document_source_set_variable_from_subpipeline.h" #include "mongo/db/pipeline/lite_parsed_document_source.h" #include "mongo/db/pipeline/search/document_source_internal_search_mongot_remote.h" +#include "mongo/db/pipeline/search/lite_parsed_search.h" #include "mongo/db/pipeline/search/search_helper.h" #include "mongo/db/query/search/internal_search_mongot_remote_spec_gen.h" #include "mongo/db/query/search/mongot_cursor.h" @@ -41,6 +42,8 @@ namespace mongo { +DEFINE_LITE_PARSED_SEARCH_STAGE_DERIVED(Search); + /** * The $search stage expands to multiple internal stages when parsed, namely * $_internalSearchMongotRemote and $_internalSearchIdLookup. $setVariableFromSubPipeline may also diff --git a/src/mongo/db/pipeline/search/document_source_search_meta.cpp b/src/mongo/db/pipeline/search/document_source_search_meta.cpp index 4ba677ffa89..cf246a306a8 100644 --- a/src/mongo/db/pipeline/search/document_source_search_meta.cpp +++ b/src/mongo/db/pipeline/search/document_source_search_meta.cpp @@ -61,8 +61,10 @@ auto cloneEachOne(std::list> stages, const } } // namespace +ALLOCATE_STAGE_PARAMS_ID(searchMeta, SearchMetaStageParams::id); + REGISTER_DOCUMENT_SOURCE(searchMeta, - LiteParsedSearchStage::parse, + SearchMetaLiteParsed::parse, DocumentSourceSearchMeta::createFromBson, AllowedWithApiStrict::kNeverInVersion1); diff --git a/src/mongo/db/pipeline/search/document_source_search_meta.h b/src/mongo/db/pipeline/search/document_source_search_meta.h index 5d5e1994969..a54250a5fda 100644 --- a/src/mongo/db/pipeline/search/document_source_search_meta.h +++ b/src/mongo/db/pipeline/search/document_source_search_meta.h @@ -31,10 +31,13 @@ #include "mongo/db/pipeline/document_source.h" #include "mongo/db/pipeline/search/document_source_internal_search_mongot_remote.h" +#include "mongo/db/pipeline/search/lite_parsed_search.h" #include "mongo/util/modules.h" namespace mongo { +DEFINE_LITE_PARSED_SEARCH_STAGE_DERIVED(SearchMeta); + /** * The $searchMeta stage is similar to the $_internalMongotRemote stage except that it consumes * metadata cursors. diff --git a/src/mongo/db/pipeline/search/document_source_vector_search.cpp b/src/mongo/db/pipeline/search/document_source_vector_search.cpp index 70e4d43b122..2fb0507821d 100644 --- a/src/mongo/db/pipeline/search/document_source_vector_search.cpp +++ b/src/mongo/db/pipeline/search/document_source_vector_search.cpp @@ -49,8 +49,10 @@ namespace mongo { using boost::intrusive_ptr; +ALLOCATE_STAGE_PARAMS_ID(vectorSearch, VectorSearchStageParams::id); + REGISTER_DOCUMENT_SOURCE(vectorSearch, - LiteParsedSearchStage::parse, + VectorSearchLiteParsed::parse, DocumentSourceVectorSearch::createFromBson, AllowedWithApiStrict::kNeverInVersion1); ALLOCATE_DOCUMENT_SOURCE_ID(vectorSearch, DocumentSourceVectorSearch::id) diff --git a/src/mongo/db/pipeline/search/document_source_vector_search.h b/src/mongo/db/pipeline/search/document_source_vector_search.h index b6aa1327fff..86ee97c2fb3 100644 --- a/src/mongo/db/pipeline/search/document_source_vector_search.h +++ b/src/mongo/db/pipeline/search/document_source_vector_search.h @@ -32,6 +32,7 @@ #include "mongo/bson/bsonobj.h" #include "mongo/db/pipeline/document_source.h" #include "mongo/db/pipeline/document_source_limit.h" +#include "mongo/db/pipeline/search/lite_parsed_search.h" #include "mongo/db/query/query_knobs_gen.h" #include "mongo/db/query/search/internal_search_mongot_remote_spec_gen.h" #include "mongo/util/modules.h" @@ -42,6 +43,8 @@ namespace mongo { +DEFINE_LITE_PARSED_SEARCH_STAGE_DERIVED(VectorSearch); + /** * Interface used to retrieve the execution stats of explain(). * diff --git a/src/mongo/db/pipeline/search/lite_parsed_search.h b/src/mongo/db/pipeline/search/lite_parsed_search.h index d374552811b..5110a680961 100644 --- a/src/mongo/db/pipeline/search/lite_parsed_search.h +++ b/src/mongo/db/pipeline/search/lite_parsed_search.h @@ -34,20 +34,12 @@ namespace mongo { -DECLARE_STAGE_PARAMS_DERIVED_DEFAULT(SearchStage); - /** - * A 'LiteParsed' representation of either a $search or $searchMeta stage. - * This is the parent class for the $listSearchIndexes stage. + * A 'LiteParsed' representation of a search stage. This is the parent class for the + * $listSearchIndexes stage. */ -class LiteParsedSearchStage : public LiteParsedDocumentSource { +class LiteParsedSearchStageBase : public LiteParsedDocumentSource { public: - static std::unique_ptr parse(const NamespaceString& nss, - const BSONElement& spec, - const LiteParserOptions& options) { - return std::make_unique(spec, std::move(nss)); - } - stdx::unordered_set getInvolvedNamespaces() const override { // There are no foreign namespaces. return stdx::unordered_set{}; @@ -75,14 +67,28 @@ public: transactionNotSupported(getParseTimeName()); } - std::unique_ptr getStageParams() const final { - return std::make_unique(_originalBson); - } - - explicit LiteParsedSearchStage(const BSONElement& spec, NamespaceString nss) + explicit LiteParsedSearchStageBase(const BSONElement& spec, NamespaceString nss) : LiteParsedDocumentSource(spec), _nss(std::move(nss)) {} private: const NamespaceString _nss; }; + +#define DEFINE_LITE_PARSED_SEARCH_STAGE_DERIVED(stageName) \ + DECLARE_STAGE_PARAMS_DERIVED_DEFAULT(stageName); \ + class stageName##LiteParsed : public mongo::LiteParsedSearchStageBase { \ + public: \ + stageName##LiteParsed(const mongo::BSONElement& originalBson, mongo::NamespaceString nss) \ + : mongo::LiteParsedSearchStageBase(originalBson, nss) {} \ + static std::unique_ptr parse( \ + const mongo::NamespaceString& nss, \ + const mongo::BSONElement& spec, \ + const mongo::LiteParserOptions& options) { \ + return std::make_unique(spec, nss); \ + } \ + std::unique_ptr getStageParams() const final { \ + return std::make_unique(_originalBson); \ + } \ + }; + } // namespace mongo