From 8fd5d8173e472284c13807a7cff9003dc3ec0350 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 12 Aug 2014 10:19:56 -0400 Subject: [PATCH] filter: Clear the result set before filtering Ocarina was preserving the results set even if there were 0 search results for the entire search string. So a search for "walllllll" would still return results for "wall". Signed-off-by: Anna Schumaker --- core/filter.cpp | 1 + tests/core/filter.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/filter.cpp b/core/filter.cpp index a998c759..71a82ccb 100644 --- a/core/filter.cpp +++ b/core/filter.cpp @@ -114,6 +114,7 @@ void filter :: search(const std::string &text, std::set &res) std::list::iterator it; IndexEntry *found; + res.clear(); parse_text(text, parsed); if (parsed.size() == 0) return; diff --git a/tests/core/filter.cpp b/tests/core/filter.cpp index 7e5781c0..127e70f5 100644 --- a/tests/core/filter.cpp +++ b/tests/core/filter.cpp @@ -64,7 +64,8 @@ static void test_add() static void do_test_search(const std::string &text, unsigned int len, unsigned int *ids) { - std::set res; + int init_values[] = { 1, 2, 3, 4, 5 }; + std::set res(init_values, init_values + 5); std::set::iterator it; filter :: search(text, res); @@ -96,9 +97,7 @@ static void test_search() unsigned int res5[] = {}; do_test_search("unknown terms", 0, res5); - - unsigned int res6[] = {}; - do_test_search("the chestZ", 0, res6); + do_test_search("the chestZ", 0, res5); } int main(int argc, char **argv)