From 88bb25f2f6737d2ec26d705c06b41bf7ff94264b Mon Sep 17 00:00:00 2001
From: Robin Ward <robin.ward@gmail.com>
Date: Mon, 11 Mar 2013 12:18:25 -0400
Subject: [PATCH] Fixes #313 - Without a slug the search urls were wrong.

---
 lib/search.rb | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/search.rb b/lib/search.rb
index 11a2026cf..aa1291e96 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -98,7 +98,7 @@ module Search
     return nil if term.blank?
 
     # We are stripping only symbols taking place in FTS and simply sanitizing the rest.
-    sanitized_term = PG::Connection.escape_string(term.gsub(/[:()&!]/,'')) 
+    sanitized_term = PG::Connection.escape_string(term.gsub(/[:()&!]/,''))
 
     # really short terms are totally pointless
     return nil if sanitized_term.blank? || sanitized_term.length < min_search_term_length
@@ -155,7 +155,11 @@ module Search
       type = row.delete('type')
 
       # Add the slug for topics
-      row['url'].gsub!('slug', Slug.for(row['title'])) if type == 'topic'
+      if type == 'topic'
+        new_slug = Slug.for(row['title'])
+        new_slug = "topic" if new_slug.blank?
+        row['url'].gsub!('slug', new_slug)
+      end
 
       # Remove attributes when we know they don't matter
       row.delete('id')