diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-02 21:51:26 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-02 21:51:26 +0200 |
commit | ad9bc429171c8196a9cd68d36794e3de9b6d7270 (patch) | |
tree | b695924cffc22c5ef13bd39ec207f629cab90279 /src/main/java | |
parent | 66835b12c35dad7a8ddbe816556635635b836e95 (diff) |
fixed search term parser for empty terms
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/FtsUtils.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/FtsUtils.java b/src/main/java/de/pixart/messenger/utils/FtsUtils.java index 86eeeeeaf..c6870d07e 100644 --- a/src/main/java/de/pixart/messenger/utils/FtsUtils.java +++ b/src/main/java/de/pixart/messenger/utils/FtsUtils.java @@ -44,10 +44,10 @@ public class FtsUtils { if (part.isEmpty()) { continue; } - final String cleaned = part.substring(getStartIndex(part), getEndIndex(part) + 1); + final String cleaned = clean(part); if (isKeyword(cleaned)) { term.add(part); - } else { + } else if (!cleaned.isEmpty()) { term.add(cleaned); } } @@ -76,9 +76,13 @@ public class FtsUtils { } private static int getStartIndex(String term) { + int length = term.length(); int index = 0; while (term.charAt(index) == '*') { ++index; + if (index >= length) { + break; + } } return index; } @@ -87,8 +91,20 @@ public class FtsUtils { int index = term.length() - 1; while (term.charAt(index) == '*') { --index; + if (index < 0) { + break; + } } return index; } + private static String clean(String input) { + int begin = getStartIndex(input); + int end = getEndIndex(input); + if (begin > end) { + return ""; + } else { + return input.substring(begin, end + 1); + } + } }
\ No newline at end of file |