fix: test was added

This commit is contained in:
Volodymyr Yavdoshenko 2025-05-09 16:12:27 +03:00
parent 01e72683b6
commit 4000cef7c4
No known key found for this signature in database
GPG key ID: 24BC74845F4F4064
3 changed files with 32 additions and 3 deletions

View file

@ -279,12 +279,14 @@ struct BasicSearch {
template <typename C> template <typename C>
IndexResult CollectSuffixMatches(BaseStringIndex<C>* index, std::string_view suffix) { IndexResult CollectSuffixMatches(BaseStringIndex<C>* index, std::string_view suffix) {
// TODO: Implement full text search for suffix // TODO: Implement full text search for suffix
error_ = "Not implemented";
return IndexResult{}; return IndexResult{};
} }
template <typename C> template <typename C>
IndexResult CollectInfixMatches(BaseStringIndex<C>* index, std::string_view infix) { IndexResult CollectInfixMatches(BaseStringIndex<C>* index, std::string_view infix) {
// TODO: Implement full text search for infix // TODO: Implement full text search for infix
error_ = "Not implemented";
return IndexResult{}; return IndexResult{};
} }
@ -368,11 +370,13 @@ struct BasicSearch {
IndexResult Search(const AstSuffixNode& node, string_view active_field) { IndexResult Search(const AstSuffixNode& node, string_view active_field) {
// TODO: Implement full text search for suffix // TODO: Implement full text search for suffix
error_ = "Not implemented";
return IndexResult{}; return IndexResult{};
} }
IndexResult Search(const AstInfixNode& node, string_view active_field) { IndexResult Search(const AstInfixNode& node, string_view active_field) {
// TODO: Implement full text search for infix // TODO: Implement full text search for infix
error_ = "Not implemented";
return IndexResult{}; return IndexResult{};
} }

View file

@ -237,9 +237,8 @@ TEST_F(SearchParserTest, Parse) {
EXPECT_EQ(1, Parse(" @foo:@bar ")); EXPECT_EQ(1, Parse(" @foo:@bar "));
EXPECT_EQ(1, Parse(" @foo: ")); EXPECT_EQ(1, Parse(" @foo: "));
// We don't support suffix/any other position for now EXPECT_EQ(0, Parse("*suffix"));
EXPECT_EQ(1, Parse("*pre")); EXPECT_EQ(0, Parse("*infix"));
EXPECT_EQ(1, Parse("*pre*"));
EXPECT_EQ(1, Parse("pre***")); EXPECT_EQ(1, Parse("pre***"));
} }

View file

@ -872,6 +872,32 @@ TEST_F(SearchTest, InvalidVectorParameter) {
ASSERT_FALSE(algo.Init("*=>[KNN 2 @v $b]", &query_params)); 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", &params);
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*", &params);
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 search
} // namespace dfly } // namespace dfly