diff --git a/core/src/main/groovy/com/muwire/core/SplitPattern.groovy b/core/src/main/groovy/com/muwire/core/SplitPattern.groovy index 606c903a..8cca0d94 100644 --- a/core/src/main/groovy/com/muwire/core/SplitPattern.groovy +++ b/core/src/main/groovy/com/muwire/core/SplitPattern.groovy @@ -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 SPLIT_CHARS = new HashSet<>() static { diff --git a/core/src/test/groovy/com/muwire/core/SplitPatternTest.groovy b/core/src/test/groovy/com/muwire/core/SplitPatternTest.groovy index 10853dcd..4cd085de 100644 --- a/core/src/test/groovy/com/muwire/core/SplitPatternTest.groovy +++ b/core/src/test/groovy/com/muwire/core/SplitPatternTest.groovy @@ -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 + } } 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 6d80052c..238d2d94 100644 --- a/core/src/test/groovy/com/muwire/core/search/SearchIndexTest.groovy +++ b/core/src/test/groovy/com/muwire/core/search/SearchIndexTest.groovy @@ -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 + } }