support postgresql ts_vector fulltextsearch, thanks to genesis

This commit is contained in:
Garvin Hicking 2008-08-26 13:19:54 +00:00
parent 87ffb16164
commit 44290653bb
2 changed files with 18 additions and 1 deletions

View File

@ -3,6 +3,9 @@
Version 1.4 ()
------------------------------------------------------------------------
* Add support for postgreSQL ts_vector fulltext search, thanks
to genesis.
* Bulletproof: Added support for custom, randomized header image.
If you enter a path (relative to the domain root, like
'/blog/uploads/'), any of the contained images will be rotated.

View File

@ -743,7 +743,21 @@ function &serendipity_searchEntries($term, $limit = '') {
$serendipity['dbType'] == 'pdo-postgres') {
$cond['group'] = '';
$cond['distinct'] = 'DISTINCT';
$cond['find_part'] = "(title ILIKE '%$term%' OR body ILIKE '%$term%' OR extended ILIKE '%$term%')";
$r = serendipity_db_query("SELECT count(routine_name) AS counter
FROM information_schema.routines
WHERE routine_name LIKE 'to_tsvector'
AND specific_catalog = '" . $serendipity['dbName'] . "'");
if (is_array($r) && $r[0]['counter'] > 0) {
$term = str_replace('&', '&', $term);
$cond['find_part'] = "(
to_tsvector('english', title) @@to_tsquery('$term') OR
to_tsvector('english', body) @@to_tsquery('$term') OR
to_tsvector('english', extended) @@to_tsquery('$term')
)");
} else {
$cond['find_part'] = "(title ILIKE '%$term%' OR body ILIKE '%$term%' OR extended ILIKE '%$term%')";
}
} elseif ($serendipity['dbType'] == 'sqlite' || $serendipity['dbType'] == 'sqlite3') {
// Very extensive SQLite search. There currently seems no other way to perform fulltext search in SQLite
// But it's better than no search at all :-D