Partially match strings in case of List.contains(String)

后端 未结 9 882
夕颜
夕颜 2020-12-10 11:23

I have a List

List list = new ArrayList();
list.add(\"ABCD\");
list.add(\"EFGH\");
list.add(\"IJ KL\")         


        
9条回答
  •  被撕碎了的回忆
    2020-12-10 12:06

    Yes, you can! Sort of.

    What you are looking for, is often called fuzzy searching or approximate string matching and there are several solutions to this problem.

    With the FuzzyWuzzy lib, for example, you can have all your strings assigned a score based on how similar they are to a particular search term. The actual values seem to be integer percentages of the number of characters matching with regards to the search string length.

    After invoking FuzzySearch.extractAll, it is up to you to decide what the minimum score would be for a string to be considered a match.

    There are also other, similar libraries worth checking out, like google-diff-match-patch or the Apache Commons Text Similarity API, and so on.

    If you need something really heavy-duty, your best bet would probably be Lucene (as also mentioned by Ryan Shillington)

提交回复
热议问题