My answer may not be for your circuit, but I know that this may help.
I have an address table that has the columns addressid, address1, address2, address3, city, zip, province, countryid, regionid, modified, modifiedby, VERSION, created, createdby .
My requirement is to search by relevance, not case sensitive. At the highest priority, the CITY column is indicated for relevance. Then it is ADDRESS3 , ADDRESS2 and ADDRESS1 .
I have :searchKey as a bind variable that must be entered by the user (I use SQL Developer in the Oracle database). I have successfully used the following:
SELECT addressid, address1, address2, address3, city, zip , province, regionid, countryid FROM address WHERE UPPER(address1||' '||address2||' '||address3||' '||city) LIKE '%' || UPPER(:searchKey) || '%' -- << Makes search case insensitive ORDER BY CASE WHEN UPPER(city) = UPPER(:searchKey) THEN 10 WHEN UPPER(city) LIKE UPPER(:searchKey) || '%' THEN 9 WHEN UPPER(city) LIKE '%'|| UPPER(:searchKey) ||'%' THEN 8 ELSE 0 END DESC -- << Highest priority given to cities that match the best , CASE WHEN UPPER(address3) LIKE UPPER(:searchKey) ||'%' THEN 5 WHEN UPPER(address3) LIKE '%'|| UPPER(:searchKey) ||'%' THEN 4 ELSE 0 END DESC , CASE WHEN UPPER(address2) LIKE UPPER(:searchKey) ||'%' THEN 3 WHEN UPPER(address2) LIKE '%'|| UPPER(:searchKey) ||'%' THEN 2 ELSE 0 END DESC , CASE WHEN UPPER(address1) LIKE UPPER(:searchKey) ||'%' THEN 2 WHEN UPPER(address1) LIKE '%'|| UPPER(:searchKey) ||'%' THEN 1 ELSE 0 END DESC ;
You can change the values ββin the CASE construct to allow relevance to suit your priorities.