diff --git a/modules/search/search.module b/modules/search/search.module
index 910cb65..ef8bda9 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -1189,7 +1189,7 @@ function search_excerpt($keys, $text) {
             // Account for the added spaces.
             $q = max($q - 1, 0);
             $s = min($s, strlen($end) - 1);
-            $ranges[$q] = $p + $s;
+            $ranges[$q < $p ? $q : $p] = $p + $s;
             $length += $p + $s - $q;
             $included[$key] = $p + 1;
           }
