make the index String to String
This commit is contained in:
@@ -3,27 +3,26 @@ package com.muwire.core.files
|
|||||||
|
|
||||||
class SearchIndex {
|
class SearchIndex {
|
||||||
|
|
||||||
final Map<String, Set<File>> keywords = new HashMap<>()
|
final Map<String, Set<String>> keywords = new HashMap<>()
|
||||||
|
|
||||||
void add(File f) {
|
void add(String string) {
|
||||||
String name = f.getName()
|
String name = string.replaceAll("\\."," ")
|
||||||
name = name.replaceAll("\\."," ")
|
|
||||||
String [] split = name.split(" ")
|
String [] split = name.split(" ")
|
||||||
split.each {
|
split.each {
|
||||||
Set<File> existing = keywords.get(it)
|
Set<String> existing = keywords.get(it)
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
existing = new HashSet<>()
|
existing = new HashSet<>()
|
||||||
keywords.put(it, existing)
|
keywords.put(it, existing)
|
||||||
}
|
}
|
||||||
existing.add(f)
|
existing.add(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File[] search(List<String> terms) {
|
String[] search(List<String> terms) {
|
||||||
Set<File> rv = null;
|
Set<String> rv = null;
|
||||||
|
|
||||||
terms.each {
|
terms.each {
|
||||||
Set<File> forWord = keywords.get it
|
Set<String> forWord = keywords.get it
|
||||||
if (rv == null) {
|
if (rv == null) {
|
||||||
rv = forWord
|
rv = forWord
|
||||||
} else {
|
} else {
|
||||||
|
@@ -9,8 +9,7 @@ class SearchIndexTest {
|
|||||||
private void initIndex(List<String> entries) {
|
private void initIndex(List<String> entries) {
|
||||||
index = new SearchIndex()
|
index = new SearchIndex()
|
||||||
entries.each {
|
entries.each {
|
||||||
File f = new File(it)
|
index.add(it)
|
||||||
index.add(f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ class SearchIndexTest {
|
|||||||
|
|
||||||
def found = index.search(["a"])
|
def found = index.search(["a"])
|
||||||
assert found.size() == 1
|
assert found.size() == 1
|
||||||
assert found.contains(new File("a b.c"))
|
assert found.contains("a b.c")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -29,8 +28,8 @@ class SearchIndexTest {
|
|||||||
|
|
||||||
def found = index.search(["c"])
|
def found = index.search(["c"])
|
||||||
assert found.size() == 2
|
assert found.size() == 2
|
||||||
assert found.contains(new File("a b.c"))
|
assert found.contains("a b.c")
|
||||||
assert found.contains(new File("c d.e"))
|
assert found.contains("c d.e")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -39,6 +38,6 @@ class SearchIndexTest {
|
|||||||
|
|
||||||
def found = index.search(["c", "e"])
|
def found = index.search(["c", "e"])
|
||||||
assert found.size() == 1
|
assert found.size() == 1
|
||||||
assert found.contains(new File("c d.e"))
|
assert found.contains("c d.e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user