Page 1 of 1
Case-insensitive Quicksearch
Posted: Tue Oct 18, 2005 4:13 pm
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
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.
Re: Case-insensitive Quicksearch
Posted: Tue Oct 18, 2005 5:01 pm
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
Posted: Tue Oct 18, 2005 6:00 pm
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
Posted: Tue Oct 18, 2005 9:14 pm
by garvinhicking
Great, thank you. I think ILIKE is preferred in this case, or do you know if ~* would match faster?
Best regards,
Garvin
Posted: Tue Oct 18, 2005 9:33 pm
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