Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Make match score computation predictable and consistent across multiple indexes.

Kishore Nallan78b9ee52ec4c
diff --git a/include/art.h b/include/art.h
index fe82890b..8de3b7a7 100644
--- a/include/art.h
+++ b/include/art.h
@@ -93,17 +93,6 @@ typedef struct {
array offsets;
} art_values;
-/*
- * Represents a document to be indexed.
- * `offsets` refer to the index locations where a token appeared in the document
- */
-typedef struct {
- int32_t score;
- uint32_t id;
- uint32_t offsets_len;
- uint32_t* offsets;
-} art_document;
-
/**
* Represents a leaf. These are
* of arbitrary size, as they include the key.
@@ -123,6 +112,17 @@ typedef struct {
uint64_t size;
} art_tree;
+/*
+ * Represents a document to be indexed.
+ * `offsets` refer to the index locations where a token appeared in the document
+ */
+typedef struct {
+ int32_t score;
+ uint32_t id;
+ uint32_t offsets_len;
+ uint32_t* offsets;
+} art_document;
+
enum token_ordering {
FREQUENCY,
MAX_SCORE
diff --git a/include/index.h b/include/index.h
index ff88b6a0..ebce5288 100644
--- a/include/index.h
+++ b/include/index.h
@@ -11,6 +11,12 @@
#include <field.h>
#include <option.h>
+struct token_candidates {
+ std::string token;
+ size_t cost;
+ std::vector<art_leaf*> candidates;
+};
+
class Index {
private:
std::string name;
@@ -31,7 +37,7 @@ private:
spp::sparse_hash_map<std::string, spp::sparse_hash_map<uint32_t, number_t>*> sort_index;
- static inline std::vector<art_leaf *> next_suggestion(const std::vector<std::vector<art_leaf *>> &token_leaves,
+ static inline std::vector<art_leaf *> next_suggestion(const std::vector<token_candidates> &token_candidates_vec,
long long int n);
void log_leaves(const int cost, const std::string &token, const std::vector<art_leaf *> &leaves) const;
@@ -54,11 +60,10 @@ private:
size_t & all_result_ids_len, const token_ordering token_order = FREQUENCY, const bool prefix = false);
void search_candidates(uint32_t* filter_ids, size_t filter_ids_length, std::vector<facet> & facets,
- const std::vector<sort_by> & sort_fields, int & candidate_rank,
- std::vector<std::vector<art_leaf*>> & token_to_candidates,
- std::vector<std::vector<art_leaf*>> & searched_queries, Topster<100> & topster,
- size_t & total_results, uint32_t** all_result_ids, size_t & all_result_ids_len,
- const size_t & max_results, const bool prefix);
+ const std::vector<sort_by> & sort_fields, std::vector<token_candidates> & token_to_candidates,
+ const token_ordering token_order, std::vector<std::vector<art_leaf*>> & searched_queries,
+ Topster<100> & topster, size_t & total_results, uint32_t** all_result_ids,
+ size_t & all_result_ids_len, const size_t & max_results, const bool prefix);
void index_string_field(const std::string & text, const uint32_t score, art_tree *t, uint32_t seq_id,
const bool verbatim) const;
@@ -90,7 +95,7 @@ public:
~Index();
Option<size_t> search(std::string query, const std::vector<std::string> search_fields,
- const std::string & simple_filter_query, std::vector<facet> facets,
+ const std::string & simple_filter_query, std::vector<facet> & facets,
std::vector<sort_by> sort_fields_std, const int num_typos,
const size_t per_page, const size_t page,
const token_ordering token_order, const bool prefix,
@@ -99,9 +104,9 @@ public:
Option<uint32_t> remove(const uint32_t seq_id, nlohmann::json & document);
- void score_results(const std::vector<sort_by> & sort_fields, const int & query_index, const int & candidate_rank,
- Topster<100> &topster, const std::vector<art_leaf *> & query_suggestion, const uint32_t *result_ids,
- const size_t result_size) const;
+ void score_results(const std::vector<sort_by> & sort_fields, const int & query_index, const uint32_t total_cost,
+ Topster<100> &topster, const std::vector<art_leaf *> & query_suggestion,
+ const uint32_t *result_ids, const size_t result_size) const;
Option<uint32_t> index_in_memory(const nlohmann::json & document, uint32_t seq_id, int32_t points);
diff --git a/src/collection.cpp b/src/collection.cpp
index 1178c062..8afdd46a 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -27,7 +27,7 @@ Collection::Collection(const std::string name, const uint32_t collection_id, con
num_indices = 4;
for(auto i = 0; i < num_indices; i++) {
- indices.push_back(new Index(name, search_schema, facet_schema, sort_schema));
+ indices.push_back(new Index(name+std::to_string(i), search_schema, facet_schema, sort_schema));
}
num_documents = 0;
@@ -295,11 +295,13 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<s
std::vector<std::vector<art_leaf*>> searched_queries;
std::vector<std::pair<int, Topster<100>::KV>> field_order_kvs;
- size_t all_result_ids_len = 0;
+ size_t total_found = 0;
for(Index* index: indices) {
+ size_t all_result_ids_len = 0;
index->search(query, search_fields, simple_filter_query, facets, sort_fields_std, num_typos,
per_page, page, token_order, prefix, field_order_kvs, all_result_ids_len, searched_queries);
+ total_found += all_result_ids_len;
}
// All fields are sorted descending
@@ -312,7 +314,7 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<s
nlohmann::json result = nlohmann::json::object();
result["hits"] = nlohmann::json::array();
- result["found"] = all_result_ids_len;
+ result["found"] = total_found;
const int start_result_index = (page - 1) * per_page;
const int kvsize = field_order_kvs.size();
diff --git a/src/index.cpp b/src/index.cpp
index a17afbda..c84d4a45 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -273,20 +273,20 @@ void Index::do_facets(std::vector<facet> & facets, uint32_t* result_ids, size_t
}
void Index::search_candidates(uint32_t* filter_ids, size_t filter_ids_length, std::vector<facet> & facets,
- const std::vector<sort_by> & sort_fields, int & candidate_rank,
- std::vector<std::vector<art_leaf*>> & token_to_candidates,
+ const std::vector<sort_by> & sort_fields,
+ std::vector<token_candidates> & token_candidates_vec, const token_ordering token_order,
std::vector<std::vector<art_leaf*>> & searched_queries, Topster<100> & topster,
size_t & total_results, uint32_t** all_result_ids, size_t & all_result_ids_len,
const size_t & max_results, const bool prefix) {
const size_t combination_limit = 10;
const size_t prefix_candidates_limit = 5;
- auto product = []( long long a, std::vector<art_leaf*>& b ) { return a*b.size(); };
- long long int N = std::accumulate(token_to_candidates.begin(), token_to_candidates.end(), 1LL, product);
+ auto product = []( long long a, token_candidates & b ) { return a*b.candidates.size(); };
+ long long int N = std::accumulate(token_candidates_vec.begin(), token_candidates_vec.end(), 1LL, product);
for(long long n=0; n<N && n<combination_limit; ++n) {
// every element in `query_suggestion` contains a token and its associated hits
- std::vector<art_leaf *> query_suggestion = next_suggestion(token_to_candidates, n);
+ std::vector<art_leaf *> query_suggestion = next_suggestion(token_candidates_vec, n);
/*for(auto i=0; i < query_suggestion.size(); i++) {
std::cout << "i: " << i << " - " << query_suggestion[i]->key << std::endl;
@@ -298,8 +298,12 @@ void Index::search_candidates(uint32_t* filter_ids, size_t filter_ids_length, st
continue;
}
+ uint32_t total_cost = 0;
uint32_t* result_ids = query_suggestion[0]->values->ids.uncompress();
- candidate_rank += 1;
+
+ for(auto tc: token_candidates_vec) {
+ total_cost += tc.cost;
+ }
// intersect the document ids for each token to find docs that contain all the tokens (stored in `result_ids`)
for(auto i=1; i < query_suggestion.size(); i++) {
@@ -318,7 +322,7 @@ void Index::search_candidates(uint32_t* filter_ids, size_t filter_ids_length, st
result_size, &filtered_result_ids);
uint32_t* new_all_result_ids;
- all_result_ids_len += ArrayUtils::or_scalar(*all_result_ids, all_result_ids_len, filtered_result_ids,
+ all_result_ids_len = ArrayUtils::or_scalar(*all_result_ids, all_result_ids_len, filtered_result_ids,
filtered_results_size, &new_all_result_ids);
delete [] *all_result_ids;
*all_result_ids = new_all_result_ids;
@@ -326,7 +330,7 @@ void Index::search_candidates(uint32_t* filter_ids, size_t filter_ids_length, st
do_facets(facets, filtered_result_ids, filtered_results_size);
// go through each matching document id and calculate match score
- score_results(sort_fields, searched_queries.size(), candidate_rank, topster, query_suggestion,
+ score_results(sort_fields, searched_queries.size(), total_cost, topster, query_suggestion,
filtered_result_ids, filtered_results_size);
delete[] filtered_result_ids;
@@ -335,12 +339,12 @@ void Index::search_candidates(uint32_t* filter_ids, size_t filter_ids_length, st
do_facets(facets, result_ids, result_size);
uint32_t* new_all_result_ids;
- all_result_ids_len += ArrayUtils::or_scalar(*all_result_ids, all_result_ids_len, result_ids,
+ all_result_ids_len = ArrayUtils::or_scalar(*all_result_ids, all_result_ids_len, result_ids,
result_size, &new_all_result_ids);
delete [] *all_result_ids;
*all_result_ids = new_all_result_ids;
- score_results(sort_fields, searched_queries.size(), candidate_rank, topster, query_suggestion,
+ score_results(sort_fields, searched_queries.size(), total_cost, topster, query_suggestion,
result_ids, result_size);
delete[] result_ids;
}
@@ -348,11 +352,7 @@ void Index::search_candidates(uint32_t* filter_ids, size_t filter_ids_length, st
total_results += topster.size;
searched_queries.push_back(query_suggestion);
- if(!prefix && total_results >= max_results) {
- break;
- }
-
- if(prefix && candidate_rank >= prefix_candidates_limit) {
+ if(total_results >= max_results) {
break;
}
}
@@ -467,7 +467,9 @@ Option<uint32_t> Index::do_filtering(uint32_t** filter_ids_out, const std::strin
uint32_t filter_ids_length = 0;
// process the filters first
- for(const filter & a_filter: filters) {
+ for(auto i = 0; i < filters.size(); i++) {
+ const filter & a_filter = filters[i];
+
if(search_index.count(a_filter.field_name) != 0) {
art_tree* t = search_index.at(a_filter.field_name);
field f = search_schema.at(a_filter.field_name);
@@ -541,7 +543,7 @@ Option<uint32_t> Index::do_filtering(uint32_t** filter_ids_out, const std::strin
uint32_t* result_ids = nullptr;
size_t result_ids_length = union_of_ids(filter_result_array_pairs, &result_ids);
- if(filter_ids == nullptr) {
+ if(i == 0) {
filter_ids = result_ids;
filter_ids_length = result_ids_length;
} else {
@@ -564,7 +566,7 @@ Option<uint32_t> Index::do_filtering(uint32_t** filter_ids_out, const std::strin
}
Option<size_t> Index::search(std::string query, const std::vector<std::string> search_fields,
- const std::string & simple_filter_query, std::vector<facet> facets,
+ const std::string & simple_filter_query, std::vector<facet> & facets,
std::vector<sort_by> sort_fields_std, const int num_typos,
const size_t per_page, const size_t page, const token_ordering token_order,
const bool prefix, std::vector<std::pair<int, Topster<100>::KV>> & field_order_kvs,
@@ -629,7 +631,7 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
StringUtils::split(query, tokens, " ");
const int max_cost = (num_typos < 0 || num_typos > 2) ? 2 : num_typos;
- const size_t max_results = std::min(num_results, (size_t) Index::MAX_RESULTS);
+ const size_t max_results = Index::MAX_RESULTS;
size_t total_results = topster.size;
@@ -660,11 +662,10 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
}
// stores candidates for each token, i.e. i-th index would have all possible tokens with a cost of "c"
- std::vector<std::vector<art_leaf*>> token_to_candidates;
+ std::vector<token_candidates> token_candidates_vec;
const size_t combination_limit = 10;
auto product = []( long long a, std::vector<int>& b ) { return a*b.size(); };
- int candidate_rank = 0;
long long n = 0;
long long int N = std::accumulate(token_to_costs.begin(), token_to_costs.end(), 1LL, product);
@@ -678,7 +679,7 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
costs[i] = token_to_costs[i][q.rem];
}
- token_to_candidates.clear();
+ token_candidates_vec.clear();
int token_index = 0;
while(token_index < tokens.size()) {
@@ -687,8 +688,7 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
const std::string token_cost_hash = token + std::to_string(costs[token_index]);
std::vector<art_leaf*> leaves;
- /*std::cout << "\nSearching for: " << token << " - cost: " << costs[token_index] << ", candidate_rank: "
- << candidate_rank << std::endl;*/
+ //std::cout << "\nSearching for: " << token << " - cost: " << costs[token_index] << std::endl;
if(token_cost_cache.count(token_cost_hash) != 0) {
leaves = token_cost_cache[token_cost_hash];
@@ -696,8 +696,9 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
// prefix should apply only for last token
const bool prefix_search = prefix && ((token_index == tokens.size()-1) ? true : false);
const int token_len = prefix_search ? (int) token.length() : (int) token.length() + 1;
- const int max_candidates = prefix_search ? 5 : 3;
+ // If this is a prefix search, we should for more candidates and do a union of those document IDs
+ const int max_candidates = prefix_search ? 10 : 3;
art_fuzzy_search(search_index.at(field), (const unsigned char *) token.c_str(), token_len,
costs[token_index], costs[token_index], max_candidates, token_order, prefix_search, leaves);
@@ -707,8 +708,8 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
}
if(!leaves.empty()) {
- //!log_leaves(costs[token_index], token, leaves);
- token_to_candidates.push_back(leaves);
+ //log_leaves(costs[token_index], token, leaves);
+ token_candidates_vec.push_back(token_candidates{token, costs[token_index], leaves});
token_to_count[token] = std::max(token_to_count[token], leaves.at(0)->values->ids.getLength());
} else {
// No result at `cost = costs[token_index]`. Remove costs until `cost` for token and re-do combinations
@@ -720,6 +721,7 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
if(token_to_costs[token_index].empty()) {
token_to_costs.erase(token_to_costs.begin()+token_index);
tokens.erase(tokens.begin()+token_index);
+ costs.erase(costs.begin()+token_index);
token_index--;
}
}
@@ -733,21 +735,16 @@ void Index::search_field(std::string & query, const std::string & field, uint32_
token_index++;
}
- if(token_to_candidates.size() != 0 && token_to_candidates.size() == tokens.size()) {
+ if(token_candidates_vec.size() != 0 && token_candidates_vec.size() == tokens.size()) {
// If all tokens were found, go ahead and search for candidates with what we have so far
- search_candidates(filter_ids, filter_ids_length, facets, sort_fields, candidate_rank, token_to_candidates,
- searched_queries, topster, total_results, all_result_ids, all_result_ids_len,
+ search_candidates(filter_ids, filter_ids_length, facets, sort_fields, token_candidates_vec,
+ token_order, searched_queries, topster, total_results, all_result_ids, all_result_ids_len,
max_results, prefix);
- if (!prefix && total_results >= max_results) {
+ if (total_results >= max_results) {
// If we don't find enough results, we continue outerloop (looking at tokens with greater cost)
break;
}
-
- // only allow upto 10 prefix candidate tokens
- if(prefix && candidate_rank > 10) {
- break;
- }
}
n++;
@@ -791,11 +788,11 @@ void Index::log_leaves(const int cost, const std::string &token, const std::vect
}
}
-void Index::score_results(const std::vector<sort_by> & sort_fields, const int & query_index, const int & candidate_rank,
- Topster<100> & topster, const std::vector<art_leaf *> &query_suggestion,
- const uint32_t *result_ids, const size_t result_size) const {
+void Index::score_results(const std::vector<sort_by> & sort_fields, const int & query_index,
+ const uint32_t total_cost, Topster<100> & topster,
+ const std::vector<art_leaf *> &query_suggestion,
+ const uint32_t *result_ids, const size_t result_size) const {
- const int max_candidate_rank = 250;
spp::sparse_hash_map<const art_leaf*, uint32_t*> leaf_to_indices;
for (art_leaf *token_leaf : query_suggestion) {
@@ -859,12 +856,12 @@ void Index::score_results(const std::vector<sort_by> & sort_fields, const int &
mscore = MatchScore::match_score(seq_id, token_positions);
}
- int candidate_rank_score = max_candidate_rank - candidate_rank;
-
// Construct a single match_score from individual components (for multi-field sort)
- const uint64_t match_score = ((uint64_t)(mscore.words_present) << 16) +
- (candidate_rank_score << 8) +
- (MAX_SEARCH_TOKENS - mscore.distance);
+ const uint64_t match_score = ((int64_t)(mscore.words_present) << 56) |
+ ((int64_t)(255 - total_cost) << 48) |
+ ((int64_t)(1) << 16) |
+ ((int64_t)(MAX_SEARCH_TOKENS - mscore.distance));
+
const int64_t default_score = 0;
const number_t & primary_rank_score = (primary_rank_scores && primary_rank_scores->count(seq_id) > 0) ?
@@ -876,9 +873,10 @@ void Index::score_results(const std::vector<sort_by> & sort_fields, const int &
const number_t & secondary_rank_value = secondary_rank_score * secondary_rank_factor;
topster.add(seq_id, query_index, match_score, primary_rank_value, secondary_rank_value);
- /*std::cout << "candidate_rank: " << candidate_rank << ", candidate_rank_score: " << candidate_rank_score
+ /*std::cout << name << ", total_cost: " << total_cost
<< ", words_present: " << mscore.words_present << ", match_score: " << match_score
- << ", primary_rank_score: " << primary_rank_score.intval << ", seq_id: " << seq_id << std::endl;*/
+ << ", primary_rank_score: " << primary_rank_score.intval << ", distance: " << mscore.distance
+ << ", seq_id: " << seq_id << std::endl;*/
}
for (auto it = leaf_to_indices.begin(); it != leaf_to_indices.end(); it++) {
@@ -912,15 +910,15 @@ void Index::populate_token_positions(const std::vector<art_leaf *> &query_sugges
}
}
-inline std::vector<art_leaf *> Index::next_suggestion(const std::vector<std::vector<art_leaf *>> &token_leaves,
- long long int n) {
- std::vector<art_leaf*> query_suggestion(token_leaves.size());
+inline std::vector<art_leaf *> Index::next_suggestion(const std::vector<token_candidates> &token_candidates_vec,
+ long long int n) {
+ std::vector<art_leaf*> query_suggestion(token_candidates_vec.size());
// generate the next combination from `token_leaves` and store it in `query_suggestion`
ldiv_t q { n, 0 };
- for(long long i = 0 ; i < token_leaves.size(); i++) {
- q = ldiv(q.quot, token_leaves[i].size());
- query_suggestion[i] = token_leaves[i][q.rem];
+ for(long long i = 0 ; i < token_candidates_vec.size(); i++) {
+ q = ldiv(q.quot, token_candidates_vec[i].candidates.size());
+ query_suggestion[i] = token_candidates_vec[i].candidates[q.rem];
}
// sort ascending based on matched documents for each token for faster intersection
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 64896ff6..def6c454 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -157,9 +157,9 @@ TEST_F(CollectionTest, ExactPhraseSearch) {
// Check pagination
results = collection->search("rocket launch", query_fields, "", facets, sort_fields, 0, 3).get();
ASSERT_EQ(3, results["hits"].size());
- ASSERT_EQ(4, results["found"].get<uint32_t>());
+ ASSERT_EQ(5, results["found"].get<uint32_t>());
- ids = {"8", "1", "17", "16", "13"};
+ ids = {"8", "1", "17"};
for(size_t i = 0; i < 3; i++) {
nlohmann::json result = results["hits"].at(i);
@@ -219,9 +219,9 @@ TEST_F(CollectionTest, SkipUnindexedTokensDuringPhraseSearch) {
TEST_F(CollectionTest, PartialPhraseSearch) {
std::vector<std::string> facets;
nlohmann::json results = collection->search("rocket research", query_fields, "", facets, sort_fields, 0, 10).get();
- ASSERT_EQ(4, results["hits"].size());
+ ASSERT_EQ(6, results["hits"].size());
- std::vector<std::string> ids = {"1", "8", "16", "17"};
+ std::vector<std::string> ids = {"19", "1", "10", "8", "16", "17"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -263,7 +263,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {
std::vector<std::string> facets;
nlohmann::json results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 2, 1, MAX_SCORE, false).get();
ASSERT_EQ(2, results["hits"].size());
- std::vector<std::string> ids = {"22", "23"};
+ std::vector<std::string> ids = {"22", "3"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -274,7 +274,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {
results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 3, 1, FREQUENCY, false).get();
ASSERT_EQ(3, results["hits"].size());
- ids = {"3", "12", "24"};
+ ids = {"22", "3", "12"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -285,20 +285,20 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {
// Check pagination
results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 1, 1, FREQUENCY, false).get();
- ASSERT_EQ(3, results["found"].get<int>());
+ ASSERT_EQ(5, results["found"].get<int>());
ASSERT_EQ(1, results["hits"].size());
std::string solo_id = results["hits"].at(0)["id"];
- ASSERT_STREQ("3", solo_id.c_str());
+ ASSERT_STREQ("22", solo_id.c_str());
results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 2, 1, FREQUENCY, false).get();
- ASSERT_EQ(3, results["found"].get<int>());
+ ASSERT_EQ(5, results["found"].get<int>());
ASSERT_EQ(2, results["hits"].size());
// Check total ordering
results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 10, 1, FREQUENCY, false).get();
ASSERT_EQ(5, results["hits"].size());
- ids = {"3", "12", "24", "22", "23"};
+ ids = {"22", "3", "12", "23", "24"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -309,7 +309,7 @@ TEST_F(CollectionTest, TypoTokenRankedByScoreAndFrequency) {
results = collection->search("loox", query_fields, "", facets, sort_fields, 1, 10, 1, MAX_SCORE, false).get();
ASSERT_EQ(5, results["hits"].size());
- ids = {"22", "23", "3", "12", "24"};
+ ids = {"22", "3", "12", "23", "24"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -324,9 +324,9 @@ TEST_F(CollectionTest, TextContainingAnActualTypo) {
std::vector<std::string> facets;
nlohmann::json results = collection->search("ISX what", query_fields, "", facets, sort_fields, 1, 4, 1, FREQUENCY, false).get();
ASSERT_EQ(4, results["hits"].size());
- ASSERT_EQ(4, results["found"].get<uint32_t>());
+ ASSERT_EQ(9, results["found"].get<uint32_t>());
- std::vector<std::string> ids = {"19", "6", "21", "8"};
+ std::vector<std::string> ids = {"8", "19", "6", "21"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -340,7 +340,7 @@ TEST_F(CollectionTest, TextContainingAnActualTypo) {
ASSERT_EQ(8, results["hits"].size());
ASSERT_EQ(8, results["found"].get<uint32_t>());
- ids = {"20", "19", "6", "3", "21", "4", "10", "8"};
+ ids = {"20", "19", "6", "4", "3", "10", "8", "21"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -395,7 +395,7 @@ TEST_F(CollectionTest, PrefixSearching) {
std::vector<std::string> facets;
nlohmann::json results = collection->search("ex", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY, true).get();
ASSERT_EQ(2, results["hits"].size());
- std::vector<std::string> ids = {"12", "6"};
+ std::vector<std::string> ids = {"6", "12"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);
@@ -440,7 +440,7 @@ TEST_F(CollectionTest, PrefixSearching) {
results = collection->search("t", query_fields, "", facets, sort_fields, 0, 2, 1, FREQUENCY, true).get();
ASSERT_EQ(2, results["hits"].size());
- ids = {"1", "foo"};
+ ids = {"19", "22"};
for(size_t i = 0; i < results["hits"].size(); i++) {
nlohmann::json result = results["hits"].at(i);