Should not crash when an empty index is queried against.

This commit is contained in:
Kishore Nallan 2017-04-08 20:45:20 +05:30
parent de71afef50
commit 57bff89a97
2 changed files with 19 additions and 0 deletions

View File

@ -1332,6 +1332,9 @@ int art_fuzzy_search(art_tree *t, const unsigned char *term, const int term_len,
art_leaf *l = (art_leaf *) LEAF_RAW(t->root);
art_fuzzy_recurse(0, l->key[0], t->root, 0, term, term_len, irow, jrow, min_cost, max_cost, prefix, nodes);
} else {
if(t->root == NULL) {
return 0;
}
art_fuzzy_children(0, t->root, 0, term, term_len, irow, jrow, min_cost, max_cost, prefix, nodes);
}

View File

@ -847,4 +847,20 @@ TEST_F(CollectionTest, IndexingWithBadData) {
ASSERT_STREQ("Rank field `average` must be an integer.", bad_rank_field_op.error().c_str());
collectionManager.drop_collection("sample_collection");
}
TEST_F(CollectionTest, EmptyIndexShouldNotCrash) {
Collection *empty_coll;
std::vector<field> fields = {field("name", field_types::STRING)};
facet_fields = {field("tags", field_types::STRING_ARRAY)};
std::vector<std::string> rank_fields = {"age", "average"};
empty_coll = collectionManager.get_collection("empty_coll");
if(empty_coll == nullptr) {
empty_coll = collectionManager.create_collection("empty_coll", fields, facet_fields, rank_fields, "age");
}
nlohmann::json results = empty_coll->search("a", {"name"}, "", {}, rank_fields, 0, 10, FREQUENCY, false);
ASSERT_EQ(0, results["hits"].size());
}