public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Search Repo:
Made a hacked version of search, will fix when changing to Sphinx
Michael Hartl (author)
Fri Apr 04 17:53:58 -0700 2008
commit  d010b2371ea3455fcfe98529b98b5b680fdf5d79
tree    b51a12c79879323c5dfbb714aa00bd91680f260d
parent  8dad71a005152fa50126f3fcd79434c8de4da896
...
41
42
43
44
45
 
 
 
46
47
48
49
50
51
52
53
54
55
56
 
 
 
57
58
59
...
41
42
43
 
 
44
45
46
47
48
 
 
 
 
 
 
 
 
 
49
50
51
52
53
54
0
@@ -41,19 +41,14 @@ class Message < Communication
0
   class << self
0
     def search(options = {})
0
       query = options[:q]
0
- return [].paginate if query.blank?
0
- limit = [total_hits(query), SEARCH_LIMIT].min
0
+ query = options[:q]
0
+ return [].paginate if query.blank? or query == "*"
0
+ # This is ineffecient. We'll fix it when we move to Sphinx.
0
       conditions = ["recipient_id = ? AND recipient_deleted_at IS NULL",
0
                     options[:recipient]]
0
- paginate_by_contents(query, { :total_entries => limit },
0
- { :page => options[:page],
0
- :per_page => SEARCH_PER_PAGE,
0
- :conditions => conditions })
0
- rescue RuntimeError
0
- # Weird behavior: if paginate_by_contents is nonempty before
0
- # the conditions are applied, but empty *after*, Ferret raises a
0
- # RuntimeError. We will definitely switch to Sphinx at some point.
0
- return [].paginate
0
+ results = find_by_contents(query, :conditions => conditions)
0
+ results[0...SEARCH_LIMIT].paginate(:page => options[:page],
0
+ :per_page => SEARCH_PER_PAGE)
0
     end
0
     
0
   end
...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
 
 
 
 
 
108
109
110
...
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
99
100
101
102
103
0
@@ -92,19 +92,12 @@ class Person < ActiveRecord::Base
0
     # People search.
0
     def search(options = {})
0
       query = options[:q]
0
- return [].paginate if query.blank?
0
- limit = [total_hits(query), SEARCH_LIMIT].min
0
- return [].paginate if limit.zero?
0
- paginate_by_contents(query, { :total_entries => limit },
0
- { :page => options[:page],
0
- :per_page => SEARCH_PER_PAGE,
0
- :conditions => ["deactivated = ?",
0
- false] })
0
- rescue RuntimeError
0
- # Weird behavior: if paginate_by_contents is nonempty before
0
- # the conditions are applied, but empty *after*, Ferret raises a
0
- # RuntimeError. We will definitely switch to Sphinx at some point.
0
- return [].paginate
0
+ return [].paginate if query.blank? or query == "*"
0
+ # This is ineffecient. We'll fix it when we move to Sphinx.
0
+ conditions = ["deactivated = ?", false]
0
+ results = find_by_contents(query, :conditions => conditions)
0
+ results[0...SEARCH_LIMIT].paginate(:page => options[:page],
0
+ :per_page => SEARCH_PER_PAGE)
0
     end
0
     
0
     def find_recent
...
1
2
 
3
4
5
6
7
8
 
 
 
 
 
 
 
9
10
11
...
1
 
2
3
 
 
 
 
 
4
5
6
7
8
9
10
11
12
13
0
@@ -1,11 +1,13 @@
0
 <% column_div :type => :primary do %>
0
-
0
+ <h1>Search results</h1>
0
   <%= will_paginate(@results) %>
0
-
0
- <ul class="search">
0
- <%= render :partial => partial(@results), :collection => @results %>
0
- </ul>
0
-
0
+ <div class="search section clear">
0
+ <%- if @results.empty? -%>
0
+ <h1>No results</h1>
0
+ <%- else -%>
0
+ <%= render :partial => partial(@results), :collection => @results %>
0
+ <%- end -%>
0
+ </div>
0
   <%= will_paginate(@results) %>
0
 <%- end -%>
0
 

Comments

    No one has commented yet.