make the index String to String

This commit is contained in:
Zlatin Balevsky
2018-07-21 06:02:07 +01:00
parent a8eb37458f
commit d16f0a40bb
2 changed files with 13 additions and 15 deletions

View File

@@ -3,27 +3,26 @@ package com.muwire.core.files
class SearchIndex {
final Map<String, Set<File>> keywords = new HashMap<>()
final Map<String, Set<String>> 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<File> existing = keywords.get(it)
Set<String> existing = keywords.get(it)
if (existing == null) {
existing = new HashSet<>()
keywords.put(it, existing)
}
existing.add(f)
existing.add(string)
}
}
File[] search(List<String> terms) {
Set<File> rv = null;
String[] search(List<String> terms) {
Set<String> rv = null;
terms.each {
Set<File> forWord = keywords.get it
Set<String> forWord = keywords.get it
if (rv == null) {
rv = forWord
} else {

View File

@@ -9,8 +9,7 @@ class SearchIndexTest {
private void initIndex(List<String> 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")
}
}