diff --git a/system/includes/functions.php b/system/includes/functions.php index bf875f1..8dab1ff 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -1323,13 +1323,18 @@ function get_keyword($keyword, $page, $perpage) $tmp = array(); - $words = explode(' ', $keyword); - foreach ($posts as $index => $v) { - $arr = explode('_', $v['basename']); - $filter = $arr[1] . ' ' . $arr[2]; - foreach ($words as $word) { - if (stripos($filter, $word) !== false) { + + $filepath = $v['dirname'] . '/' . $v['basename']; + + $findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // Add word boundaries (find whole-words only) + + $findRx = "~{$findRxWhole}~iu"; // Case-insensitive and UTF-8 mode + + $lines = file($filepath); + + foreach ($lines as $line) { + if (preg_match ($findRx, $line)) { if (!in_array($v, $tmp)) { $tmp[] = $v; } @@ -1505,23 +1510,30 @@ function get_tagcount($var) return count($tmp); } -// Return search result count +/// Return search result count function keyword_count($keyword) { $posts = get_blog_posts(); $tmp = array(); - $words = explode(' ', $keyword); - foreach ($posts as $index => $v) { - $arr = explode('_', $v['basename']); - $filter = $arr[1] . ' ' . $arr[2]; - foreach ($words as $word) { - if (stripos($filter, $word) !== false) { - $tmp[] = $v; - } - } + + $filepath = $v['dirname'] . '/' . $v['basename']; + + $findRxWhole = '\b' . preg_quote($keyword, '~') . '\b'; // Add word boundaries (find whole-words only) + + $findRx = "~{$findRxWhole}~iu"; // Case-insensitive and UTF-8 mode + + $lines = file($filepath); + + foreach ($lines as $line) { + if (preg_match ($findRx, $line)) { + if (!in_array($v, $tmp)) { + $tmp[] = $v; + } + } + } } $tmp = array_unique($tmp, SORT_REGULAR); diff --git a/themes/doks/main.html.php b/themes/doks/main.html.php index 7d3ab50..c1035d6 100644 --- a/themes/doks/main.html.php +++ b/themes/doks/main.html.php @@ -28,9 +28,11 @@ -
+ +
-

title;?>

+

Search: title;?> (count;?>)

+