This commit is contained in:
Victor Shcherb 2020-07-31 14:09:46 +02:00
parent 0a77312535
commit 7b10a094ef
2 changed files with 25 additions and 1 deletions

View file

@ -160,7 +160,7 @@ public class SearchPhrase {
public SearchPhrase generateNewPhrase(String text, SearchSettings settings) { public SearchPhrase generateNewPhrase(String text, SearchSettings settings) {
String textToSearch = text; String textToSearch = Algorithms.normalizeSearchText(text);
List<SearchWord> leftWords = this.words; List<SearchWord> leftWords = this.words;
String thisTxt = getText(true); String thisTxt = getText(true);
List<SearchWord> foundWords = new ArrayList<>(); List<SearchWord> foundWords = new ArrayList<>();
@ -183,6 +183,7 @@ public class SearchPhrase {
} }
public static SearchPhrase emptyPhrase() { public static SearchPhrase emptyPhrase() {
return emptyPhrase(null); return emptyPhrase(null);
} }

View file

@ -44,6 +44,29 @@ public class Algorithms {
public static boolean isEmpty(Collection<?> c) { public static boolean isEmpty(Collection<?> c) {
return c == null || c.size() == 0; return c == null || c.size() == 0;
} }
private static char[] CHARS_TO_NORMALIZE_KEY = new char[''];
private static char[] CHARS_TO_NORMALIZE_VALUE = new char['\''];
public static String normalizeSearchText(String s) {
boolean norm = false;
for (int i = 0; i < s.length() && !norm; i++) {
char ch = s.charAt(i);
for (int j = 0; j < CHARS_TO_NORMALIZE_KEY.length; j++) {
if (ch == CHARS_TO_NORMALIZE_KEY[j]) {
norm = true;
break;
}
}
}
if (!norm) {
return s;
}
for (int k = 0; k < CHARS_TO_NORMALIZE_KEY.length; k++) {
s = s.replace(CHARS_TO_NORMALIZE_KEY[k], CHARS_TO_NORMALIZE_VALUE[k]);
}
return s;
}
public static boolean isEmpty(Map<?, ?> map) { public static boolean isEmpty(Map<?, ?> map) {
return map == null || map.size() == 0; return map == null || map.size() == 0;