From 01617f876d20f2cbdd9f27b8ff95c223ed3ff366 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 21 Jul 2018 09:15:32 +0100 Subject: [PATCH] fixes for not found scenarios --- .../com/muwire/core/search/SearchIndex.groovy | 6 ++++-- .../com/muwire/core/search/SearchIndexTest.groovy | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy b/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy index b5ba2e25..dfb97440 100644 --- a/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy +++ b/core/src/main/groovy/com/muwire/core/search/SearchIndex.groovy @@ -22,7 +22,7 @@ class SearchIndex { Set rv = null; terms.each { - Set forWord = keywords.get it + Set forWord = keywords.getOrDefault(it,[]) if (rv == null) { rv = forWord } else { @@ -31,6 +31,8 @@ class SearchIndex { } - rv.asList() + if (rv != null) + return rv.asList() + [] } } diff --git a/core/src/test/groovy/com/muwire/core/search/SearchIndexTest.groovy b/core/src/test/groovy/com/muwire/core/search/SearchIndexTest.groovy index 652a66d3..6e24ce97 100644 --- a/core/src/test/groovy/com/muwire/core/search/SearchIndexTest.groovy +++ b/core/src/test/groovy/com/muwire/core/search/SearchIndexTest.groovy @@ -40,4 +40,19 @@ class SearchIndexTest { assert found.size() == 1 assert found.contains("c d.e") } + + @Test + void testNotFound() { + initIndex(["a b.c"]) + def found = index.search(["d"]) + assert found.size() == 0 + } + + @Test + void testSomeNotFound() { + initIndex(["a b.c"]) + def found = index.search(["a","d"]) + assert found.size() == 0 + + } }