split by newlines

pull/24/head
Zlatin Balevsky 2019-11-06 13:59:14 +00:00
parent 94678bad3c
commit 9181829e4a
3 changed files with 31 additions and 1 deletions

View File

@ -2,7 +2,7 @@ package com.muwire.core
class SplitPattern {
public static final String SPLIT_PATTERN = "[\\*\\+\\-,\\.:;\\(\\)=_/\\\\\\!\\\"\\\'\\\$%\\|\\[\\]\\{\\}\\?]";
public static final String SPLIT_PATTERN = "[\\*\\+\\-,\\.:;\\(\\)=_/\\\\\\!\\\"\\\'\\\$%\\|\\[\\]\\{\\}\\?\r\n]";
private static final Set<Character> SPLIT_CHARS = new HashSet<>()
static {

View File

@ -24,4 +24,12 @@ class SplitPatternTest {
assert SplitPattern.termify('"siamese cat" any cat "persian cat"') ==
['siamese cat','any','cat','persian cat']
}
@Test
void testNewLine() {
def s = "first\nsecond"
s = s.replaceAll(SplitPattern.SPLIT_PATTERN, " ")
s = s.split(" ")
assert s.length == 2
}
}

View File

@ -120,4 +120,26 @@ class SearchIndexTest {
assert index.search(['cat', 'video siamese']).size() == 0
assert index.search(['cat','video','siamese']).size() == 3
}
@Test
void testNewLine() {
initIndex(['first\nsecond'])
assert index.search(['first']).size() == 1
assert index.search(['second']).size() == 1
assert index.search(['first','second']).size() == 1
assert index.search(['second','first']).size() == 1
assert index.search(['second first']).size() == 0
assert index.search(['first second']).size() == 0
}
@Test
void testDosNewLine() {
initIndex(['first\r\nsecond'])
assert index.search(['first']).size() == 1
assert index.search(['second']).size() == 1
assert index.search(['first','second']).size() == 1
assert index.search(['second','first']).size() == 1
assert index.search(['second first']).size() == 0
assert index.search(['first second']).size() == 0
}
}