Case-insensitive Quicksearch

Found a bug? Tell us!!
Post Reply
chris_at
Regular
Posts: 9
Joined: Tue Oct 18, 2005 3:57 pm
Contact:

Case-insensitive Quicksearch

Post by chris_at »

This is not a bug per se. I noticed that virtually all of my visitors use the Quicksearch with lower caps, which makes most searches fail. Example: I have quite a few entries concerning Firefox, but searching for "firefox" fails.

I'd be grateful if you could tell me where the code for the Quicksearch is located. Even more if you tell me what I would have to change :wink:

This is a terrific product, by the way. I spent hours looking for open source blog software with PostgreSQL support, but most only support that toy database MySQL.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Case-insensitive Quicksearch

Post by garvinhicking »

You find this code in include/functions_entries.inc.php in the function serendipity_searchEntries():

Code: Select all

 if ($serendipity['dbType'] == 'postgres') {
        $group     = '';
        $distinct  = 'DISTINCT';
        $find_part = "(title~'$term' OR body~'$term' OR extended~'$term')";
Since I don't know postgres, what is the function to do lowercase searching? In the same file you'll see how it is done in sqlite and stuff. If you tell me how to modify it, I'll patch it up in the distribution :)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
chris_at
Regular
Posts: 9
Joined: Tue Oct 18, 2005 3:57 pm
Contact:

Post by chris_at »

Great!

All you have to do is replace the "~" operator with the "~*" (tilde-star) operator.

These operators match regular expressions, though. If all you're looking for is a plain text match, then you should probably be using the "LIKE" or the "ILIKE" (for case-insensitive matches) operator.

Code: Select all

$find_part = "(title ILIKE '%$term%' OR body ILIKE '%$term%' OR extended ILIKE '%$term%')";
Thanks for the quick reply!

Christian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Great, thank you. I think ILIKE is preferred in this case, or do you know if ~* would match faster?

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
chris_at
Regular
Posts: 9
Joined: Tue Oct 18, 2005 3:57 pm
Contact:

Post by chris_at »

Actually, I think it should be slower. Matching a regexp is definitely more complex than the standard LIKE matching, but I'm not familiar with how the internals deals with them, or optimizes matching.

As soon as I have a bit more data in my DB, I'll run some comparisons and report them.

Chris
Post Reply