From 211980ceb241316ab541d8676f1d810735940ca9 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 14 Aug 2008 20:13:55 +0000 Subject: - Patch #257912 by douggreen, Damien Tournoud: improve performance by flipping two queries during indexing. --- modules/search/search.module | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'modules') 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); } -- cgit v1.2.3