From 4000cef7c4e9148e166e81d1c124024fca6cb706 Mon Sep 17 00:00:00 2001 From: Volodymyr Yavdoshenko Date: Fri, 9 May 2025 16:12:27 +0300 Subject: [PATCH] fix: test was added --- src/core/search/search.cc | 4 ++++ src/core/search/search_parser_test.cc | 5 ++--- src/core/search/search_test.cc | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/core/search/search.cc b/src/core/search/search.cc index 66a14648b..6b90babcc 100644 --- a/src/core/search/search.cc +++ b/src/core/search/search.cc @@ -279,12 +279,14 @@ struct BasicSearch { template IndexResult CollectSuffixMatches(BaseStringIndex* index, std::string_view suffix) { // TODO: Implement full text search for suffix + error_ = "Not implemented"; return IndexResult{}; } template IndexResult CollectInfixMatches(BaseStringIndex* index, std::string_view infix) { // TODO: Implement full text search for infix + error_ = "Not implemented"; return IndexResult{}; } @@ -368,11 +370,13 @@ struct BasicSearch { IndexResult Search(const AstSuffixNode& node, string_view active_field) { // TODO: Implement full text search for suffix + error_ = "Not implemented"; return IndexResult{}; } IndexResult Search(const AstInfixNode& node, string_view active_field) { // TODO: Implement full text search for infix + error_ = "Not implemented"; return IndexResult{}; } diff --git a/src/core/search/search_parser_test.cc b/src/core/search/search_parser_test.cc index 8affceb5a..8043a25a2 100644 --- a/src/core/search/search_parser_test.cc +++ b/src/core/search/search_parser_test.cc @@ -237,9 +237,8 @@ TEST_F(SearchParserTest, Parse) { EXPECT_EQ(1, Parse(" @foo:@bar ")); EXPECT_EQ(1, Parse(" @foo: ")); - // We don't support suffix/any other position for now - EXPECT_EQ(1, Parse("*pre")); - EXPECT_EQ(1, Parse("*pre*")); + EXPECT_EQ(0, Parse("*suffix")); + EXPECT_EQ(0, Parse("*infix")); EXPECT_EQ(1, Parse("pre***")); } diff --git a/src/core/search/search_test.cc b/src/core/search/search_test.cc index 05f571978..f9fa987df 100644 --- a/src/core/search/search_test.cc +++ b/src/core/search/search_test.cc @@ -872,6 +872,32 @@ TEST_F(SearchTest, InvalidVectorParameter) { ASSERT_FALSE(algo.Init("*=>[KNN 2 @v $b]", &query_params)); } +TEST_F(SearchTest, NotImplementedSearchTypes) { + auto schema = MakeSimpleSchema({{"title", SchemaField::TEXT}}); + FieldIndices indices{schema, kEmptyOptions, PMR_NS::get_default_resource(), nullptr}; + + SearchAlgorithm algo{}; + QueryParams params; + + // Add a document for testing + MockedDocument doc{Map{{"title", "text for search"}}}; + indices.Add(0, doc); + + // Test suffix search (words ending with "search") + algo.Init("*search", ¶ms); + auto suffix_result = algo.Search(&indices); + EXPECT_TRUE(suffix_result.ids.empty()) << "Suffix search should return empty result"; + EXPECT_THAT(suffix_result.error, testing::HasSubstr("Not implemented")) + << "Suffix search should return a not implemented error"; + + // Test infix search (words containing "for") + algo.Init("*for*", ¶ms); + auto infix_result = algo.Search(&indices); + EXPECT_TRUE(infix_result.ids.empty()) << "Infix search should return empty result"; + EXPECT_THAT(infix_result.error, testing::HasSubstr("Not implemented")) + << "Infix search should return a not implemented error"; +} + } // namespace search } // namespace dfly