mirror of
https://github.com/typesense/typesense.git
synced 2025-05-22 06:40:30 +08:00
Allow exact matches on longer strings.
Earlier, N will become zero so no results will be returned.
This commit is contained in:
parent
bff9585ee7
commit
59e1fd0e4f
@ -2776,7 +2776,8 @@ void Index::fuzzy_search_fields(const std::vector<search_field_t>& the_fields,
|
||||
|
||||
auto product = []( long long a, std::vector<int>& b ) { return a*b.size(); };
|
||||
long long n = 0;
|
||||
long long int N = std::accumulate(token_to_costs.begin(), token_to_costs.end(), 1LL, product);
|
||||
long long int N = token_to_costs.size() > 30 ? 1 :
|
||||
std::accumulate(token_to_costs.begin(), token_to_costs.end(), 1LL, product);
|
||||
|
||||
const long long combination_limit = exhaustive_search ? Index::COMBINATION_MAX_LIMIT : Index::COMBINATION_MIN_LIMIT;
|
||||
|
||||
|
@ -723,3 +723,28 @@ TEST_F(CollectionSpecificMoreTest, OrderWithThreeSortFields) {
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
||||
TEST_F(CollectionSpecificMoreTest, LongString) {
|
||||
std::vector<field> fields = {field("name", field_types::STRING, false),};
|
||||
|
||||
Collection* coll1 = collectionManager.create_collection("coll1", 1, fields).get();
|
||||
|
||||
std::string name;
|
||||
for(size_t i = 0; i < 100; i++) {
|
||||
name += "foo" + std::to_string(i) + " ";
|
||||
}
|
||||
|
||||
nlohmann::json doc1;
|
||||
doc1["name"] = name;
|
||||
|
||||
ASSERT_TRUE(coll1->add(doc1.dump()).ok());
|
||||
|
||||
auto results = coll1->search(name, {"name"},
|
||||
"", {}, sort_fields, {2}, 10,
|
||||
1, FREQUENCY, {true},
|
||||
0).get();
|
||||
|
||||
ASSERT_EQ(1, results["hits"].size());
|
||||
|
||||
collectionManager.drop_collection("coll1");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user