diff modules/search/search.module @ 11:589fb7c02327 6.5

Drupal 6.5
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:32:19 +0100
parents acef7ccb09b5
children
line wrap: on
line diff
--- a/modules/search/search.module	Tue Dec 23 14:32:08 2008 +0100
+++ b/modules/search/search.module	Tue Dec 23 14:32:19 2008 +0100
@@ -1,5 +1,5 @@
 <?php
-// $Id: search.module,v 1.250.2.3 2008/08/13 06:59:49 dries Exp $
+// $Id: search.module,v 1.250.2.4 2008/09/17 06:42:20 goba Exp $
 
 /**
  * @file
@@ -572,11 +572,12 @@
 
   // 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);
   }