@@ -2346,7 +2346,8 @@ TEST_F(FunctionSearchTest, TestBuildLeafQueryExecutesSelectedSniiWildcardReader)
23462346 {INVERTED_INDEX_PARSER_KEY , INVERTED_INDEX_PARSER_ENGLISH },
23472347 {INVERTED_INDEX_PARSER_LOWERCASE_KEY , INVERTED_INDEX_PARSER_TRUE }};
23482348 std::map<std::string, std::string> selected_properties {
2349- {INVERTED_INDEX_PARSER_KEY , INVERTED_INDEX_PARSER_STANDARD },
2349+ {INVERTED_INDEX_ANALYZER_NAME_KEY , " unregistered_search_wildcard_analyzer" },
2350+ {INVERTED_INDEX_PARSER_KEY , INVERTED_INDEX_PARSER_NONE },
23502351 {INVERTED_INDEX_PARSER_LOWERCASE_KEY , INVERTED_INDEX_PARSER_TRUE }};
23512352 auto decoy_meta = make_test_inverted_index (15 , decoy_properties);
23522353 auto selected_meta = make_test_inverted_index (16 , selected_properties);
@@ -2530,6 +2531,74 @@ TEST_F(FunctionSearchTest, TestSniiNativeForwardsTermClauseAsEqualQuery) {
25302531 expect_bitmap_eq (collect_docs (scorer), {0 , 2 });
25312532}
25322533
2534+ TEST_F (FunctionSearchTest, TestSniiNativePassesSelectedAnalyzerContext) {
2535+ auto * exec_env = ExecEnv::GetInstance ();
2536+ auto * previous_policy_mgr = exec_env->index_policy_mgr ();
2537+ IndexPolicyMgr scoped_policy_mgr;
2538+ exec_env->_index_policy_mgr = &scoped_policy_mgr;
2539+ DEFER (exec_env->_index_policy_mgr = previous_policy_mgr);
2540+
2541+ TIndexPolicy tokenizer;
2542+ tokenizer.id = 910030 ;
2543+ tokenizer.name = " function_search_context_tokenizer" ;
2544+ tokenizer.type = TIndexPolicyType::TOKENIZER ;
2545+ tokenizer.properties [" type" ] = " char_group" ;
2546+ tokenizer.properties [" tokenize_on_chars" ] = " [whitespace]" ;
2547+
2548+ TIndexPolicy common_grams;
2549+ common_grams.id = 910031 ;
2550+ common_grams.name = " function_search_context_common_grams" ;
2551+ common_grams.type = TIndexPolicyType::TOKEN_FILTER ;
2552+ common_grams.properties [" type" ] = " common_grams" ;
2553+
2554+ TIndexPolicy analyzer;
2555+ analyzer.id = 910032 ;
2556+ analyzer.name = " function_search_context_analyzer" ;
2557+ analyzer.type = TIndexPolicyType::ANALYZER ;
2558+ analyzer.properties [" tokenizer" ] = tokenizer.name ;
2559+ analyzer.properties [" token_filter" ] = " lowercase," + common_grams.name ;
2560+ scoped_policy_mgr.apply_policy_changes ({tokenizer, common_grams, analyzer}, {});
2561+
2562+ auto context = std::make_shared<IndexQueryContext>();
2563+ std::map<std::string, std::string> properties {
2564+ {INVERTED_INDEX_ANALYZER_NAME_KEY , analyzer.name },
2565+ {INVERTED_INDEX_PARSER_KEY , INVERTED_INDEX_PARSER_NONE }};
2566+ auto index_meta = make_test_inverted_index (45 , properties);
2567+ auto index_file_reader = std::make_shared<RejectingCluceneIndexFileReader>();
2568+ auto reader =
2569+ std::make_shared<RecordingNativeInvertedIndexReader>(&index_meta, index_file_reader);
2570+ reader->set_query_result (" running quickly" , make_bitmap ({1 }));
2571+ segment_v2::InvertedIndexIterator iterator;
2572+ iterator.add_reader (segment_v2::InvertedIndexReaderType::FULLTEXT , reader);
2573+
2574+ std::unordered_map<std::string, IndexFieldNameAndTypePair> data_type_with_names;
2575+ data_type_with_names.emplace (
2576+ " body" , IndexFieldNameAndTypePair {" body" , std::make_shared<DataTypeString>()});
2577+ std::unordered_map<std::string, IndexIterator*> iterators;
2578+ iterators[" body" ] = &iterator;
2579+ TSearchFieldBinding field_binding;
2580+ field_binding.field_name = " body" ;
2581+ field_binding.index_properties = properties;
2582+ field_binding.__isset .index_properties = true ;
2583+ FieldReaderResolver resolver (data_type_with_names, iterators, context, {field_binding});
2584+
2585+ inverted_index::query_v2::QueryPtr query;
2586+ std::string binding_key;
2587+ auto status =
2588+ function_search->build_leaf_query (make_leaf_clause (" MATCH" , " running quickly" ), context,
2589+ resolver, &query, &binding_key, " OR" , 0 , 3 );
2590+
2591+ ASSERT_TRUE (status.ok ()) << status;
2592+ ASSERT_NE (reader->last_analyzer_ctx , nullptr );
2593+ EXPECT_EQ (reader->last_analyzer_ctx ->analyzer_key , analyzer.name );
2594+ EXPECT_EQ (reader->last_analyzer_ctx ->analyzer_name , analyzer.name );
2595+ EXPECT_EQ (reader->last_analyzer_ctx ->parser_type , InvertedIndexParserType::PARSER_NONE );
2596+ EXPECT_TRUE (reader->last_analyzer_ctx ->requires_analysis ());
2597+ ASSERT_NE (reader->last_analyzer_ctx ->analyzer_provider , nullptr );
2598+ EXPECT_TRUE (reader->last_analyzer_ctx ->analyzer_provider ->uses_common_grams ());
2599+ EXPECT_FALSE (reader->last_analyzer_ctx ->analyzer_provider ->base_analyzer_fingerprint ().empty ());
2600+ }
2601+
25332602// default_operator "and" maps a multi-token TERM clause onto MATCH_ALL_QUERY instead of the
25342603// default EQUAL_QUERY (which is an OR of terms) -- SNII has no boolean query tree to build, so
25352604// this is expressed entirely as which query type gets forwarded to the reader.
0 commit comments