Browse Source

optimize textSearchSimilar

Laserlicht 10 months ago
parent
commit
07b494632b
1 changed files with 4 additions and 1 deletions
  1. 4 1
      lib/texts/TextOperations.cpp

+ 4 - 1
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)