Page 1 of 1
Do you use the current search functionality?
Posted: Tue Apr 25, 2023 7:45 pm
by cobber
Hi guys.
Loving Bludit and am taking a bit of a change of direction and changing the look and goals for my website. What are your thoughts on the current search functionality within Bludit?
I'm asking because I have search working but it's a bit of a hit and miss. I get relevant results but I also receive addition results that shouldn't be there.
The tags search works brilliantly but the normal search . . . meh
Just wondered what everyone else uses if anything at all.
Many thanks
Re: Do you use the current search functionality?
Posted: Tue Jun 06, 2023 1:17 pm
by haywardgg
I found that it was searching Case sensitive (so seaerching 'jackson' wouldn't return pages with 'Jackson' and vise versa). I changed the search function in the search plugin and fixed it. But I still get results that don't have the keywords, which is annoying haha!
Code: Select all
private function search($text)
{
// Read the cache file
$json = file_get_contents($this->cacheFile());
$cache = json_decode($json, true);
// Convert search text to lowercase
$text = strtolower($text);
// Convert cache data to lowercase
$cache = array_map('array_change_key_case', $cache);
// Include Fuzz algorithm
require_once($this->phpPath().'vendors/fuzz.php');
$fuzz = new Fuzz($cache, 10, 1, true);
$results = $fuzz->search($text, $this->getValue('minChars'));
return array_keys($results);
}
Re: Do you use the current search functionality?
Posted: Tue Jun 06, 2023 1:35 pm
by haywardgg
cobber wrote: ↑Tue Apr 25, 2023 7:45 pm
Hi guys.
Loving Bludit and am taking a bit of a change of direction and changing the look and goals for my website. What are your thoughts on the current search functionality within Bludit?
I'm asking because I have search working but it's a bit of a hit and miss. I get relevant results but I also receive addition results that shouldn't be there.
The tags search works brilliantly but the normal search . . . meh
Just wondered what everyone else uses if anything at all.
Many thanks
In your search plugin folder, edit plugin.php and replace the search function with this:
Code: Select all
private function search($text)
{
// Read the cache file
$json = file_get_contents($this->cacheFile());
$cache = json_decode($json, true);
// Convert search text to lowercase
$text = strtolower($text);
// Convert cache data to lowercase
$cache = array_map('array_change_key_case', $cache);
// Include Fuzz algorithm
require_once($this->phpPath().'vendors/fuzz.php');
$fuzz = new Fuzz($cache, 10, 1, true);
$results = [];
foreach ($cache as $key => $value) {
// Perform exact word match using regular expression
if (preg_match('/\b' . preg_quote($text) . '\b/i', strtolower($value['title']))) {
$results[$key] = $value;
}
}
return array_keys($results);
}
What was happening for me, is that "jackson" would return any result with any page that contain the string "son" , "jack" etc.. My code fixed that
for me anyway.
Re: Do you use the current search functionality?
Posted: Sat Sep 23, 2023 8:25 pm
by medicamin
haywardgg wrote: ↑Tue Jun 06, 2023 1:35 pm
In your search plugin folder, edit plugin.php and replace the search function with this:
Thank you for this code. I found that if I replace 'title' with 'content', I get the results which has the search text in their content.
But there is a problem with your code. Persian or Arabic alphabet search breaks. searching in these languages return 0 results. Is there any solution for this?
Re: Do you use the current search functionality?
Posted: Sat Sep 23, 2023 8:43 pm
by haywardgg
medicamin wrote: ↑Sat Sep 23, 2023 8:25 pm
haywardgg wrote: ↑Tue Jun 06, 2023 1:35 pm
In your search plugin folder, edit plugin.php and replace the search function with this:
Thank you for this code. I found that if I replace 'title' with 'content', I get the results which has the search text in their content.
But there is a problem with your code. Persian or Arabic alphabet search breaks. searching in these languages return 0 results. Is there any solution for this?
Try this:
Code: Select all
private function search($text)
{
// Read the cache file
$json = file_get_contents($this->cacheFile());
$cache = json_decode($json, true);
// Convert search text to lowercase with multibyte support
$text = mb_strtolower($text, 'UTF-8');
// Convert cache data to lowercase with multibyte support
$cache = array_map(function ($item) {
return array_map('mb_strtolower', $item, array_fill(0, count($item), 'UTF-8'));
}, $cache);
// Include Fuzz algorithm
require_once($this->phpPath().'vendors/fuzz.php');
$fuzz = new Fuzz($cache, 10, 1, true);
$results = [];
foreach ($cache as $key => $value) {
// Perform exact word match using regular expression with Unicode word boundaries
if (preg_match('/\b' . preg_quote($text, '/') . '\b/u', $value['title'])) {
$results[$key] = $value;
}
}
return array_keys($results);
}
Re: Do you use the current search functionality?
Posted: Sun Sep 24, 2023 8:39 am
by medicamin
Tried, but now even searching with English characters returns no results.
Re: Do you use the current search functionality?
Posted: Sun Sep 24, 2023 12:19 pm
by haywardgg
medicamin wrote: ↑Sun Sep 24, 2023 8:39 am
Tried, but now even searching with English characters returns no results.
Try the original code (the one that worked for you before) and just replace the strtolower block with:
Code: Select all
// Convert search text to lowercase with multibyte support
$text = mb_strtolower($text, 'UTF-8');
I can't test it at the moment, I'm with family. But will have another look this evening when I'm home!
Re: Do you use the current search functionality?
Posted: Fri Sep 29, 2023 4:04 pm
by medicamin
I just thought something with preg-match could prevent UTF-8 characters matches together. And yes, it was preg-match.
I used this line in results and now I get true results in utf8 characters:
Code: Select all
if (preg_match('/(*UTF8)' . preg_quote($text ) . '/i', strtolower($value['content']))) {
I must say that \b should be removed to make this work. I don't know why!