From 07b494632b357e3f5ca43791937474409a9a3cbd Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 8 Feb 2025 13:22:11 +0100 Subject: [PATCH] optimize textSearchSimilar --- lib/texts/TextOperations.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/texts/TextOperations.cpp b/lib/texts/TextOperations.cpp index d29dbefdf..ad99c5128 100644 --- a/lib/texts/TextOperations.cpp +++ b/lib/texts/TextOperations.cpp @@ -307,7 +307,10 @@ bool TextOperations::textSearchSimilar(const std::string & s, const std::string if(boost::algorithm::contains(haystack, needle)) return true; - for(int i = 0; i < haystack.size() - needle.size(); i++) + if(needle.size() > haystack.size()) + return false; + + for(int i = 0; i < haystack.size() - needle.size() + 1; i++) { auto dist = getLevenshteinDistance(haystack.substr(i, needle.size()), needle); if(needle.size() > 2 && dist <= 1)