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:
parent
f281d46ffa
commit
b0a9ec99da
1 changed files with 17 additions and 19 deletions
|
@ -135,29 +135,27 @@ public class DictionaryController implements Initializable {
|
||||||
|
|
||||||
|
|
||||||
searchBox.textProperty().addListener((observable, oldValue, newValue) -> {
|
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
|
table.refresh(); // This fixes the table highlighting issue
|
||||||
|
|
||||||
if (newValue == null || newValue.isEmpty()) { // If filter text is empty, display all dictionary entries
|
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.
|
// need all same case for compare.
|
||||||
String lowerCaseFilter = newValue.toLowerCase();
|
String lowerCaseFilter = newValue.toLowerCase();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (dictionaryEntry.getWelsh().toLowerCase().contains(lowerCaseFilter)) {
|
if (dictionaryEntry.getWelsh().toLowerCase().contains(lowerCaseFilter)) {
|
||||||
return true; // Filter matches Welsh
|
returnVal = true; // Filter matches Welsh
|
||||||
} else if (dictionaryEntry.getEnglish().toLowerCase().contains(lowerCaseFilter)) {
|
} else if (dictionaryEntry.getEnglish().toLowerCase().contains(lowerCaseFilter)) {
|
||||||
return true; // Filter matches English
|
returnVal = true; // Filter matches English
|
||||||
}else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseFilter)) {
|
} else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseFilter)) {
|
||||||
return true; // Filter matches Word Type
|
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
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false; // No match
|
return returnVal;
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue