function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
satheesh k 18satheesh k 18 

Search result using Like operator in Where condition

Hi Team,
I am using below query to search the result. 
searchquery='select title,id, UrlName, Summary, ArticleType from knowledgearticleversion where Title like \'%'+searchstring+'%\'';
We have three records with title 'Wi-Fi', but if i am searching with keyword WiFi there is no result.  However if I am searching with exact Wi-Fi text only the results are coming.
Question: I want to build my query in such a way that if user enter Wifi or Wi-Fi the results should come. 
Please let me know.

Thanks
Satheesh K
 
Raj VakatiRaj Vakati
Try something like below 
 
String searchstring='Wi-fi' ; 
String searchquery
    ='select title,id, UrlName, Summary, ArticleType from knowledgearticleversion where Title like \'%'
    +searchstring.replace('-','')+' OR '+ searchstring +'%\'';



 
satheesh k 18satheesh k 18
Hi Raj,

Thank you for your response,

String searchquery ='select title,id, UrlName, Summary, ArticleType from knowledgearticleversion where Title like \'%' +searchstring.replace('-','')+' OR '+ searchstring +'%\'';
 The above query is not working for both the case means if i enter wifi or Wi-Fi.

Please help me
Thanks
Satheesh K

 
Raj VakatiRaj Vakati
try this .. 
 
String searchstring='Wi-fi' ; 
String searchquery
    ='select title,id, UrlName, Summary, ArticleType from knowledgearticleversion where Title like \'%'
    +searchstring.replace('-','')+''%\' OR Title like \'%''+ searchstring +'%\'';

 
satheesh k 18satheesh k 18
Hi Raj,
Compile Error: Found punctuation symbol or operator '%' that isn't valid in Apex