Modifying Levenshtein Distance algorithm to not calculate all distances

后端 未结 6 1781
渐次进展
渐次进展 2020-12-31 19:40

I\'m working on a fuzzy search implementation and as part of the implementation, we\'re using Apache\'s StringUtils.getLevenshteinDistance. At the moment, we\'re going for a

6条回答
  •  耶瑟儿~
    2020-12-31 19:53

    I used the original code and places this just before the end of the j for loop:

        if (p[n] > s.length() + 5)
            break;
    

    The +5 is arbitrary but for our purposes, if the distances is the query length plus five (or whatever number we settle upon), it doesn't really matter what is returned because we consider the match as simply being too different. It does cut down on things a bit. Still, pretty sure this isn't the idea that the Wiki statement was talking about, if anyone understands that better.

提交回复
热议问题