Created
January 31, 2021 13:57
-
-
Save alphamikle/ca57f261efc058ebc963678d6ae05241 to your computer and use it in GitHub Desktop.
Filter items function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Depending on the set flag [USE_SIMILARITY] | |
/// whether or not search with string similarity is used | |
List<Item> filterItems(Packet2<List<Item>, String> itemsAndInputValue) { | |
return itemsAndInputValue.value.where((Item item) { | |
return item.profile.contains(itemsAndInputValue.value2) || (USE_SIMILARITY && isStringsSimilar(item.profile, itemsAndInputValue.value2)); | |
}).toList(); | |
} | |
bool isStringsSimilar(String first, String second) { | |
return max(StringSimilarity.compareTwoStrings(first, second), StringSimilarity.compareTwoStrings(second, first)) >= 0.3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment