my modification:KB search-multi words search feature

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

my modification:KB search-multi words search feature

Post by deserteagle369 »

Script URL:
Version of script: 2.41
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:

Write your message below:
For user:
D:\wamp\www\hesk\knowledgebase.php
function hesk_kb_search($query) after hesk_kb_header($hesk_settings['kb_link']);
from

Code: Select all

$sql = 'SELECT t1.* FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_articles` AS t1 LEFT JOIN `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` AS t2 ON t1.`catid` = t2.`id`  WHERE t1.`type`=\'0\' AND t2.`type`=\'0\' AND (`subject` LIKE \'%'.hesk_dbEscape($query).'%\' OR `content` LIKE \'%'.hesk_dbEscape($query).'%\') LIMIT '.hesk_dbEscape($hesk_settings['kb_search_limit']);
to

Code: Select all

$arr=preg_split('/[\s,]+/',$query); // eagle:seperate with space or comma
 for ($i=0;$i<count($arr);$i++) $arr[$i]='CONCAT(subject,content) LIKE ""%'.$arr[$i].'%""'; //eagle:create conditions
 $cond=join(' AND ', $arr);
 $sql = 'SELECT t1.* FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_articles` AS t1 LEFT JOIN `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` AS t2 ON t1.`catid` = t2.`id` WHERE t1.`type`=\'0\' AND t2.`type`=\'0\' AND ('.$cond.') ORDER BY subject DESC LIMIT '.hesk_dbEscape($hesk_settings['kb_search_limit']);
For admin:
D:\wamp\www\hesk\admin\knowledgebase_private.php
function hesk_kb_search($query) after hesk_kb_header($hesk_settings['kb_link']);
from:

Code: Select all

$sql = 'SELECT t1.* FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_articles` AS t1 LEFT JOIN `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` AS t2 ON t1.`catid` = t2.`id`  WHERE t1.`type`=\'0\' AND t2.`type`=\'0\' AND (`subject` LIKE \'%'.hesk_dbEscape($query).'%\' OR `content` LIKE \'%'.hesk_dbEscape($query).'%\') LIMIT '.hesk_dbEscape($hesk_settings['kb_search_limit']);
to:

Code: Select all

"$arr=preg_split('/[\s,]+/',$query); // eagle:seperate with space or comma
 for ($i=0;$i<count($arr);$i++) $arr[$i]='CONCAT(subject,content) LIKE ""%'.$arr[$i].'%""'; //eagle:create conditions
 $cond=join(' AND ', $arr);
 $sql = 'SELECT t1.* FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_articles` AS t1 LEFT JOIN `'.hesk_dbEscape($hesk_settings['db_pfix']).'kb_categories` AS t2 ON t1.`catid` = t2.`id` WHERE t1.`type`=\'0\' AND t2.`type`=\'0\' AND ('.$cond.') ORDER BY subject DESC LIMIT '.hesk_dbEscape($hesk_settings['kb_search_limit']);"
enjoy!
Eagle
Life is a journey.
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: my modification:KB search-multi words search feature

Post by Klemen »

Thanks for sharing.

Just be careful because this can create a long SQL query that can have poor performance in large databases.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

Re: my modification:KB search-multi words search feature

Post by deserteagle369 »

yes, if I try more than 3 Chinese word, sometimes it show a blank page without error even I turn on debug mode, still looking for the reason.
Eagle
Life is a journey.
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: my modification:KB search-multi words search feature

Post by Klemen »

Perhaps you are reaching server limits for execution time or memory used on complex queries?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

Re: my modification:KB search-multi words search feature

Post by deserteagle369 »

Is there better way to do multi words query?
Eagle
Life is a journey.
Klemen
Site Admin
Posts: 10135
Joined: Fri Feb 11, 2005 4:04 pm

Re: my modification:KB search-multi words search feature

Post by Klemen »

The best thing to do would probably be to keep default code and rather edit MySQL settings

Code: Select all

ft_min_word_len=1
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply