From d16f0a40bbcc2ace95856b46b084fba1bdc659b0 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Sat, 21 Jul 2018 06:02:07 +0100 Subject: [PATCH] make the index String to String --- .../com/muwire/core/files/SearchIndex.groovy | 17 ++++++++--------- .../muwire/core/files/SearchIndexTest.groovy | 11 +++++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/files/SearchIndex.groovy b/core/src/main/groovy/com/muwire/core/files/SearchIndex.groovy index 0da0f3c8..36878aa2 100644 --- a/core/src/main/groovy/com/muwire/core/files/SearchIndex.groovy +++ b/core/src/main/groovy/com/muwire/core/files/SearchIndex.groovy @@ -3,27 +3,26 @@ package com.muwire.core.files class SearchIndex { - final Map> keywords = new HashMap<>() + final Map> keywords = new HashMap<>() - void add(File f) { - String name = f.getName() - name = name.replaceAll("\\."," ") + void add(String string) { + String name = string.replaceAll("\\."," ") String [] split = name.split(" ") split.each { - Set existing = keywords.get(it) + Set existing = keywords.get(it) if (existing == null) { existing = new HashSet<>() keywords.put(it, existing) } - existing.add(f) + existing.add(string) } } - File[] search(List terms) { - Set rv = null; + String[] search(List terms) { + Set rv = null; terms.each { - Set forWord = keywords.get it + Set forWord = keywords.get it if (rv == null) { rv = forWord } else { diff --git a/core/src/test/groovy/com/muwire/core/files/SearchIndexTest.groovy b/core/src/test/groovy/com/muwire/core/files/SearchIndexTest.groovy index 07b759db..2ce3ac1b 100644 --- a/core/src/test/groovy/com/muwire/core/files/SearchIndexTest.groovy +++ b/core/src/test/groovy/com/muwire/core/files/SearchIndexTest.groovy @@ -9,8 +9,7 @@ class SearchIndexTest { private void initIndex(List entries) { index = new SearchIndex() entries.each { - File f = new File(it) - index.add(f) + index.add(it) } } @@ -20,7 +19,7 @@ class SearchIndexTest { def found = index.search(["a"]) assert found.size() == 1 - assert found.contains(new File("a b.c")) + assert found.contains("a b.c") } @Test @@ -29,8 +28,8 @@ class SearchIndexTest { def found = index.search(["c"]) assert found.size() == 2 - assert found.contains(new File("a b.c")) - assert found.contains(new File("c d.e")) + assert found.contains("a b.c") + assert found.contains("c d.e") } @Test @@ -39,6 +38,6 @@ class SearchIndexTest { def found = index.search(["c", "e"]) assert found.size() == 1 - assert found.contains(new File("c d.e")) + assert found.contains("c d.e") } }