diff --git a/auto_tag_plugin/auto_tag_plugin.php b/auto_tag_plugin/auto_tag_plugin.php index 60ffb21..7ff599f 100644 --- a/auto_tag_plugin/auto_tag_plugin.php +++ b/auto_tag_plugin/auto_tag_plugin.php @@ -152,7 +152,6 @@ function fetch_page_content($url) function calculate_tags(array $keywordsToTags, array $searchContents): array { - // Context weights $contextWeights = [ 'title' => 3, 'url' => 3, @@ -166,16 +165,17 @@ function calculate_tags(array $keywordsToTags, array $searchContents): array foreach ($keywordsToTags as $keywords => $tags) { $keywordList = explode(',', $keywords); foreach ($keywordList as $keyword) { - $keyword = trim($keyword); + $keyword = preg_quote(trim($keyword), '/'); + $regex = '/\b' . $keyword . '\b/i'; + foreach ($searchContents as $context => $content) { - if (stripos($content, $keyword) !== false) { + if (preg_match($regex, $content)) { $tagList = explode(',', $tags); foreach ($tagList as $tag) { $tag = trim($tag); if (!isset($tagScores[$tag])) { $tagScores[$tag] = 0; } - // Add weight based on context $tagScores[$tag] += $contextWeights[$context]; } }