Skip to content

Commit

Permalink
fix issue for projects search using keywords with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mah0001 committed Oct 2, 2024
1 parent df4d009 commit 044b078
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion application/libraries/Project_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ private function apply_search_filters($search_options)
//keywords
if (isset($search_options['keywords']) && !empty($search_options['keywords'])) {
$keywords_query=$this->build_keywords_fulltext_query($search_options['keywords']);
$escaped_keywords=$this->ci->db->escape('%'.$search_options['keywords'].'%');

$escaped_keywords=$this->ci->db->escape('%'.trim($search_options['keywords']).'%');
$where = sprintf('(title like %s OR idno like %s OR study_idno like %s) OR %s',
$escaped_keywords,
$escaped_keywords,
Expand Down Expand Up @@ -276,6 +277,10 @@ function build_keywords_like_query($keywords)

function build_keywords_fulltext_query($keywords)
{
//remove characters that are not allowed in fulltext search
$keywords=preg_replace('/[@+\-&|!(){}[\]^"~*?:\/\\\]/','',$keywords);
$keywords=trim($keywords);

$keywords_list=explode(" ",$keywords);
$keyword_query=array();
foreach($keywords_list as $idx=>$keyword){
Expand Down

0 comments on commit 044b078

Please sign in to comment.