public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://dogfood.insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Catching Ultrasphinx::UsageError exception
Michael Hartl (author)
Fri Oct 03 17:56:40 -0700 2008
commit  c6e150c302042e52ced8dc306534edaea1fdf5f4
tree    57cc13746a79f53804b480eb9db1ecc345af1626
parent  b68e9e73f5f60f9e4e678931186b29df6300f070
...
26
27
28
 
29
30
...
26
27
28
29
30
31
0
@@ -26,4 +26,5 @@ vendor/**/**/doc/*
0
 vendor/plugins/footnotes/*
0
 rsa_key*
0
 sphinx/*
0
+sphinx_test/*
0
 config/ultrasphinx/*.conf
0
\ No newline at end of file
...
7
8
9
10
 
11
12
13
...
38
39
40
 
 
 
41
42
43
...
7
8
9
 
10
11
12
13
...
38
39
40
41
42
43
44
45
46
0
@@ -7,7 +7,7 @@ class SearchesController < ApplicationController
0
     
0
     redirect_to(home_url) and return if params[:q].nil?
0
     
0
-    query = params[:q].strip
0
+    query = params[:q].strip.inspect
0
     model = strip_admin(params[:model])
0
     page  = params[:page] || 1
0
 
0
@@ -38,6 +38,9 @@ class SearchesController < ApplicationController
0
         @results.map!{ |person| Person.find(person) }
0
       end
0
     end
0
+  rescue Ultrasphinx::UsageError
0
+    flash[:error] = "Invalid search query"
0
+    redirect_to searches_url(:q => "", :model => params[:model])
0
   end
0
   
0
   private
...
30
31
32
33
 
34
35
36
 
 
37
38
39
 
40
41
42
...
47
48
49
50
 
51
52
53
...
61
62
63
64
 
65
66
67
...
30
31
32
 
33
34
 
 
35
36
37
38
 
39
40
41
42
...
47
48
49
 
50
51
52
53
...
61
62
63
 
64
65
66
67
0
@@ -30,13 +30,13 @@ searchd
0
   # Daemon options
0
   # What interface the search daemon should listen on and where to store its logs
0
   address = 0.0.0.0
0
-  port = 3312
0
+  port = 3322
0
   seamless_rotate = 1
0
-  log = log/searchd.log
0
-  query_log = log/query.log
0
+  log = log/searchd_test.log
0
+  query_log = log/query_test.log
0
   read_timeout = 5
0
   max_children = 300
0
-  pid_file = log/searchd.pid
0
+  pid_file = log/searchd_test.pid
0
   max_matches = 100000
0
 }
0
 
0
@@ -47,7 +47,7 @@ client
0
   dictionary_name = ap
0
   # How your application connects to the search daemon (not necessarily the same as above)
0
   server_host = localhost
0
-  server_port = 3312
0
+  server_port = 3322
0
 }
0
 
0
 source
0
@@ -61,7 +61,7 @@ source
0
 index
0
 {
0
   # Index building options
0
-  path = sphinx
0
+  path = sphinx_test
0
   docinfo = extern # just leave this alone
0
   morphology = stem_en
0
   stopwords = # /path/to/stopwords.txt
...
175
176
177
 
 
 
 
 
 
 
 
 
178
179
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
0
@@ -175,4 +175,13 @@ describe SearchesController do
0
     end
0
   end
0
   
0
+  describe "error handling" do
0
+    it "should catch Ultrasphinx::UsageError exceptions" do
0
+      invalid_query = "foo@bar"
0
+      get :index, :q => invalid_query, :model => "Person"
0
+      response.should be_redirect
0
+      response.should redirect_to(searches_url(:q => "", :model => "Person"))
0
+    end
0
+  end
0
+  
0
 end if testing_search?
0
\ No newline at end of file

Comments