Live search with verbs improved

Live search now matches both ['to' + a word] or [a word] if the word is a verb
This commit is contained in:
law39 2020-04-22 19:04:58 +01:00
parent f281d46ffa
commit b0a9ec99da

View file

@ -135,29 +135,27 @@ public class DictionaryController implements Initializable {
searchBox.textProperty().addListener((observable, oldValue, newValue) -> {
filteredList.setPredicate(dictionaryEntry -> {
filteredList.setPredicate(dictionaryEntry -> { // returns true on a filter match, false if no match
boolean returnVal = false;
table.refresh(); // This fixes the table highlighting issue
if (newValue == null || newValue.isEmpty()) { // If filter text is empty, display all dictionary entries
return true;
returnVal = true;
}else {
// need all same case for compare.
String lowerCaseFilter = newValue.toLowerCase();
if (dictionaryEntry.getWelsh().toLowerCase().contains(lowerCaseFilter)) {
returnVal = true; // Filter matches Welsh
} else if (dictionaryEntry.getEnglish().toLowerCase().contains(lowerCaseFilter)) {
returnVal = true; // Filter matches English
} else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseFilter)) {
returnVal = true; // Filter matches Word Type
} else if (dictionaryEntry.getWordType().equals("verb") && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseFilter)) {
returnVal = true; // Filter matches ['to' + a word] or [a word] if word is a verb
}
}
// need all same case for compare.
String lowerCaseFilter = newValue.toLowerCase();
if (dictionaryEntry.getWelsh().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches Welsh
} else if (dictionaryEntry.getEnglish().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches English
}else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches Word Type
}
return false; // No match
return returnVal;
});
});