Diff
Modified: trunk/app/controllers/search_controller.rb (2218 => 2219)
--- trunk/app/controllers/search_controller.rb 2009-06-09 19:11:23 UTC (rev 2218)
+++ trunk/app/controllers/search_controller.rb 2009-06-10 15:12:11 UTC (rev 2219)
@@ -1,3 +1,8 @@
+# myExperiment: app/controllers/search_controller.rb
+#
+# Copyright (c) 2007 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
class SearchController < ApplicationController
def show
@@ -21,7 +26,8 @@
if @type == "all"
search_all
else
- redirect_to :controller => params[:type], :action ="" "search", :query => params[:query]
+ search_model
+#redirect_to :controller => params[:type], :action ="" "search", :query => params[:query]
end
end
@@ -170,4 +176,35 @@
format.html # search.rhtml
end
end
+
+ def search_model
+
+ @collection_label = params[:type].singularize
+ @controller_name = Conf.model_aliases[params[:type].camelize.singularize].underscore.pluralize
+ @visible_name = params[:type].capitalize
+ @query_type = params[:type]
+ model = eval(Conf.model_aliases[params[:type].singularize.camelize])
+
+ @query = params[:query] || ''
+ @query.strip!
+
+ limit = params[:num] ? params[:num] : Conf.default_search_size
+
+ limit = 1 if limit < 1
+ limit = Conf.max_search_size if limit > Conf.max_search_size
+
+ offset = params[:page] ? limit * (params[:page].to_i - 1) : 0
+
+ if Conf.solr_enable && address@hidden
+ solr_results = model.find_by_solr(@query, :offset => offset, :limit => limit)
+ @total_count = solr_results.total
+ @collection = PaginatedArray.new(solr_results.results,
+ :offset => offset, :limit => limit, :total => @total_count)
+ else
+ @total_count = 0
+ @collection = PaginatedArray.new([], :offset => offset, :limit => limit, :total => 0)
+ end
+
+ render("search/model")
+ end
end
Modified: trunk/app/controllers/workflows_controller.rb (2218 => 2219)
--- trunk/app/controllers/workflows_controller.rb 2009-06-09 19:11:23 UTC (rev 2218)
+++ trunk/app/controllers/workflows_controller.rb 2009-06-10 15:12:11 UTC (rev 2219)
@@ -34,15 +34,7 @@
# GET /workflows;search
def search
- @query = params[:query] || ''
- @query.strip!
-
- @workflows = (Conf.solr_enable && address@hidden) ? Workflow.find_by_solr(@query, :limit => 100).results : []
- @workflows_found_total_count = (Conf.solr_enable && address@hidden) ? Workflow.count_by_solr(@query) : 0
-
- respond_to do |format|
- format.html # search.rhtml
- end
+ redirect_to(search_path + "?type=workflows&query=" + params[:query])
end
# POST /workflows/1;favourite
Modified: trunk/app/views/layouts/_paginate.rhtml (2218 => 2219)
--- trunk/app/views/layouts/_paginate.rhtml 2009-06-09 19:11:23 UTC (rev 2218)
+++ trunk/app/views/layouts/_paginate.rhtml 2009-06-10 15:12:11 UTC (rev 2219)
@@ -3,7 +3,7 @@
<ul>
<% if collection.previous_page? -%>
<li class="nextpage">
- <%= link_to '« previous', { :page => collection.previous_page } %>
+ <%= link_to '« previous', { :query => @query, :type => @query_type, :page => collection.previous_page } %>
</li>
<% else -%>
<li class="disabledpage">« previous</li>
@@ -15,7 +15,7 @@
<li class="currentpage"><%= n %></li>
<% else -%>
<li><%= "..." if last_page+1 < n %>
- <%= link_to n, :id => params[:id], :page => n %>
+ <%= link_to n, :query => @query, :type => @query_type, :id => params[:id], :page => n %>
</li>
<% end -%>
<% last_page = n -%>
@@ -23,7 +23,7 @@
<% if collection.next_page? -%>
<li class="nextpage">
- <%= link_to 'next »', { :page => collection.next_page } %>
+ <%= link_to 'next »', { :query => @query, :type => @query_type, :page => collection.next_page } %>
</li>
<% else -%>
<li class="disabledpage">next »</li>
Modified: trunk/lib/conf.rb (2218 => 2219)
--- trunk/lib/conf.rb 2009-06-09 19:11:23 UTC (rev 2218)
+++ trunk/lib/conf.rb 2009-06-10 15:12:11 UTC (rev 2219)
@@ -41,6 +41,10 @@
self.fetch_entry('admins')
end
+ def self.curators
+ self.fetch_entry('curators')
+ end
+
def self.main_tabs
self.fetch_entry('main_tabs')
end
@@ -104,7 +108,15 @@
def self.label_icons
self.fetch_entry('label_icons', {})
end
+
+ def self.default_search_size
+ self.fetch_entry('default_search_size')
+ end
+ def self.max_search_size
+ self.fetch_entry('max_search_size')
+ end
+
# This method is required to create an administrator in the test fixtures
def self.admins=(value)
Added: trunk/lib/paginated_array.rb (0 => 2219)
--- trunk/lib/paginated_array.rb (rev 0)
+++ trunk/lib/paginated_array.rb 2009-06-10 15:12:11 UTC (rev 2219)
@@ -0,0 +1,57 @@
+# myExperiment: lib/paginated_array.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class PaginatedArray < Array
+
+ def initialize(collection, args = {})
+
+ collection.each do |item| self << item end
+
+ @total = args[:total]
+ @limit = args[:limit]
+ @offset = args[:offset]
+ end
+
+ def page_count
+ return 1 if @total == 0
+ ((@total - 1) / @limit) + 1
+ end
+
+ def first_page
+ 1
+ end
+
+ def last_page
+ page_count
+ end
+
+ def previous_page?
+ page != first_page
+ end
+
+ def previous_page
+ page - 1
+ end
+
+ def next_page?
+ page != last_page
+ end
+
+ def next_page
+ page + 1
+ end
+
+ def page
+ (@offset / @limit) + 1
+ end
+
+ def page_exists?(x)
+ return false if x < first_page
+ return false if x > last_page
+
+ true
+ end
+end
+
Modified: trunk/lib/rest.rb (2218 => 2219)
--- trunk/lib/rest.rb 2009-06-09 19:11:23 UTC (rev 2218)
+++ trunk/lib/rest.rb 2009-06-10 15:12:11 UTC (rev 2219)
@@ -982,6 +982,20 @@
#
# end
+def paginated_search_index(query, models, num, page, user)
+
+ return [] if not Conf.solr_enable or query.nil? or query == ""
+
+ find_paginated_auth( { :query => query, :models => models }, num, page, [], user) { |args, size, page|
+
+ q = args[:query]
+ models = args[:models]
+
+ search_result = models[0].multi_solr_search(q, :limit => size, :offset => size * (page - 1), :models => models)
+ search_result.results unless search_result.total < (size * (page - 1))
+ }
+end
+
def search(req_uri, rules, user, query)
search_query = query['query']
@@ -1024,20 +1038,8 @@
attributes['query'] = search_query
attributes['type'] = query['type'] if models.length == 1
- obs = []
+ obs = paginated_search_index(search_query, models, num, page, user)
- if Conf.solr_enable and not query.nil? and query != ""
-
- obs = find_paginated_auth( { :query => search_query, :models => models }, num, page, [], user) { |args, size, page|
-
- q = args[:query]
- models = args[:models]
-
- search_result = models[0].multi_solr_search(q, :limit => size, :offset => size * (page - 1), :models => models)
- search_result.results unless search_result.total < (size * (page - 1))
- }
- end
-
produce_rest_list(req_uri, rules, query, obs, 'search', attributes, user)
end