diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-08-14 20:13:55 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-08-14 20:13:55 +0000 |
commit | 211980ceb241316ab541d8676f1d810735940ca9 (patch) | |
tree | aeb9360028e0d2e6581709f1867bcda2006b37d2 /modules | |
parent | d9c682e6afe91d32719e1e9872fac205fc53672c (diff) | |
download | brdo-211980ceb241316ab541d8676f1d810735940ca9.tar.gz brdo-211980ceb241316ab541d8676f1d810735940ca9.tar.bz2 |
- Patch #257912 by douggreen, Damien Tournoud: improve performance by flipping two queries during indexing.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/search/search.module | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/modules/search/search.module b/modules/search/search.module index dfcc12edc..5b659364a 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -573,11 +573,12 @@ function search_index($sid, $type, $text) { // Insert results into search index foreach ($results[0] as $word => $score) { - // The database will collate similar words (accented and non-accented forms, etc.), - // and the score is additive, so first add and then insert. - db_query("UPDATE {search_index} SET score = score + %d WHERE word = '%s' AND sid = '%d' AND type = '%s'", $score, $word, $sid, $type); + // Try inserting first because this will succeed most times, but because + // the database collates similar words (accented and non-accented), the + // insert can fail, in which case we need to add the word scores together. + @db_query("INSERT INTO {search_index} (word, sid, type, score) VALUES ('%s', %d, '%s', %f)", $word, $sid, $type, $score); if (!db_affected_rows()) { - db_query("INSERT INTO {search_index} (word, sid, type, score) VALUES ('%s', %d, '%s', %f)", $word, $sid, $type, $score); + db_query("UPDATE {search_index} SET score = score + %f WHERE word = '%s' AND sid = %d AND type = '%s'", $score, $word, $sid, $type); } search_dirty($word); } |