Diff
Modified: trunk/Gemfile (3445 => 3446)
--- trunk/Gemfile 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/Gemfile 2013-02-25 12:27:30 UTC (rev 3446)
@@ -23,4 +23,8 @@
gem "recaptcha", "~> 0.3.4"
gem "encrypted_strings", "~> 0.3.3"
gem "encrypted_attributes", "~> 0.4.1"
+gem "sunspot_rails", "~> 1.3.3"
+gem "sunspot_solr", "~> 1.3.3"
+gem "will_paginate", "~> 2.3.16"
+gem "ruby-debug"
Modified: trunk/Rakefile (3445 => 3446)
--- trunk/Rakefile 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/Rakefile 2013-02-25 12:27:30 UTC (rev 3446)
@@ -12,12 +12,12 @@
desc 'Rebuild Solr index'
task "myexp:refresh:solr" do
require File.dirname(__FILE__) + '/config/environment'
- Workflow.rebuild_solr_index
- Blob.rebuild_solr_index
- User.rebuild_solr_index
- Network.rebuild_solr_index
- Pack.rebuild_solr_index
- Service.rebuild_solr_index
+ Workflow.solr_reindex
+ Blob.solr_reindex
+ User.solr_reindex
+ Network.solr_reindex
+ Pack.solr_reindex
+ Service.solr_reindex
end
desc 'Refresh contribution caches'
Modified: trunk/app/controllers/blobs_controller.rb (3445 => 3446)
--- trunk/app/controllers/blobs_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/blobs_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -300,7 +300,7 @@
@blob.tags_user_id = current_user # acts_as_taggable_redux
@blob.tag_list = "address@hidden, #{convert_tags_to_gem_format params[:tag_list]}" if params[:tag_list]
@blob.update_tags # hack to get around acts_as_versioned
- @blob.solr_save if Conf.solr_enable
+ @blob.solr_index if Conf.solr_enable
respond_to do |format|
format.html {
Modified: trunk/app/controllers/bookmarks_controller.rb (3445 => 3446)
--- trunk/app/controllers/bookmarks_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/bookmarks_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -6,7 +6,6 @@
class BookmarksController < ApplicationController
before_filter :login_required
- before_filter :find_bookmarks_auth, : [:index]
before_filter :find_bookmark_auth, : [:show, :edit, :update, :destroy]
# declare sweepers and which actions should invoke them
@@ -37,14 +36,6 @@
protected
- def find_bookmarks_auth
- @bookmarks = Bookmark.find(:all,
- :conditions => ["user_id = ?", current_user.id],
- :order => "created_at DESC",
- :page => { :size => 20,
- :current => params[:page] })
- end
-
def find_bookmark_auth
begin
@bookmark = Bookmark.find(params[:id], :conditions => ["user_id = ?", current_user.id])
Modified: trunk/app/controllers/comments_controller.rb (3445 => 3446)
--- trunk/app/controllers/comments_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/comments_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -35,7 +35,7 @@
if text and text.length > 0
comment = Comment.create(:user => current_user, :comment => text)
@context.comments << comment
- @context.solr_save if @context.respond_to?(:solr_save)
+ @context.solr_index if @context.respond_to?(:solr_index)
end
respond_to do |format|
@@ -50,7 +50,7 @@
# DELETE /:context_type/:context_id/comments/:id
def destroy
@comment.destroy
- @context.solr_save if @context.respond_to?(:solr_save)
+ @context.solr_index if @context.respond_to?(:solr_index)
respond_to do |format|
format.html { render :partial => "comments/comments", :locals => { :commentable => @context } }
Modified: trunk/app/controllers/content_types_controller.rb (3445 => 3446)
--- trunk/app/controllers/content_types_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/content_types_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -13,12 +13,12 @@
params[:num] = 25 unless params[:num]
if params[:mime_type]
- @content_types = ContentType.find_all_by_mime_type(params[:mime_type], :order => 'title ASC',
- :page => { :size => params[:num], :current => params[:page] })
+ @content_types = ContentType.find_all_by_mime_type(params[:mime_type], :order => 'title ASC')
else
- @content_types = ContentType.find(:all, :order => 'title ASC',
- :page => { :size => params[:num], :current => params[:page] })
+ @content_types = ContentType.find(:all, :order => 'title ASC')
end
+
+ @content_types = @content_types.paginate(:page => params[:page], :per_page => params[:num])
end
# GET /content_types/1
Modified: trunk/app/controllers/messages_controller.rb (3445 => 3446)
--- trunk/app/controllers/messages_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/messages_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -18,10 +18,10 @@
@message_folder = "inbox"
@messages = Message.find(:all,
:conditions => ["`to` = ? AND `deleted_by_recipient` = ?", current_user.id, false],
- :order => produce_sql_ordering_string(params[:sort_by], params[:order]),
- :page => { :size => 20,
- :current => params[:page] })
+ :order => produce_sql_ordering_string(params[:sort_by], params[:order]))
+ @messages = @messages.paginate(:page => params[:page], :per_page => 20)
+
respond_to do |format|
format.html # index.rhtml
end
@@ -33,10 +33,10 @@
@message_folder = "outbox"
@messages = Message.find(:all,
:conditions => ["`from` = ? AND `deleted_by_sender` = ?", current_user.id, false],
- :order => produce_sql_ordering_string(params[:sort_by], params[:order]),
- :page => { :size => 20,
- :current => params[:page] })
+ :order => produce_sql_ordering_string(params[:sort_by], params[:order]))
+ @messages = @messages.paginate(:page => params[:page], :per_page => 20)
+
respond_to do |format|
format.html # sent.rhtml
end
Modified: trunk/app/controllers/networks_controller.rb (3445 => 3446)
--- trunk/app/controllers/networks_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/networks_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -455,7 +455,7 @@
@network.tags_user_id = current_user
@network.tag_list = "address@hidden, #{convert_tags_to_gem_format params[:tag_list]}" if params[:tag_list]
@network.update_tags # hack to get around acts_as_versioned
- @network.solr_save if Conf.solr_enable
+ @network.solr_index if Conf.solr_enable
respond_to do |format|
format.html {
@@ -487,9 +487,7 @@
def find_networks
@networks = Network.find(:all,
:order => "title ASC",
- :page => { :size => 20,
- :current => params[:page] },
- :include => [ :owner ])
+ :include => [ :owner ]).paginate(:page => params[:page], :per_page => 20)
end
def find_network
Modified: trunk/app/controllers/packs_controller.rb (3445 => 3446)
--- trunk/app/controllers/packs_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/packs_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -222,7 +222,7 @@
@pack.tags_user_id = current_user # acts_as_taggable_redux
@pack.tag_list = "address@hidden, #{convert_tags_to_gem_format params[:tag_list]}" if params[:tag_list]
@pack.update_tags # hack to get around acts_as_versioned
- @pack.solr_save if Conf.solr_enable
+ @pack.solr_index if Conf.solr_enable
respond_to do |format|
format.html {
Modified: trunk/app/controllers/profiles_controller.rb (3445 => 3446)
--- trunk/app/controllers/profiles_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/profiles_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -7,7 +7,6 @@
before_filter :login_required, :except => [:index, :show]
- before_filter :find_profiles, : [:index]
before_filter :find_profile, :except => [:index]
before_filter :auth, :except => [:index, :show]
@@ -101,14 +100,6 @@
protected
- def find_profiles
- @profiles = Profile.find(:all,
- :include => :owner,
- :order => "users.name ASC",
- :page => { :size => 20,
- :current => params[:page] })
- end
-
def find_profile
begin
@user = User.find(params[:user_id])
Modified: trunk/app/controllers/search_controller.rb (3445 => 3446)
--- trunk/app/controllers/search_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/search_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -6,6 +6,7 @@
class SearchController < ApplicationController
include ApplicationHelper
+ include SearchHelper
def show
@@ -154,7 +155,9 @@
begin
query = params["q"].downcase
- results = User.multi_solr_search(query, :models => [Workflow, Blob, User], :limit => 25).results
+ results = Sunspot.search [Workflow, Blob, User] do
+ fulltext query
+ end.results
results.each do |result|
case result.class.name
@@ -213,7 +216,7 @@
model_name = params[:type].singularize.camelize
model_name = Conf.model_aliases[model_name] if Conf.model_aliases[model_name]
- model = eval(model_name)
+ model = model_name.constantize
@collection_label = params[:type].singularize
@controller_name = model_name.underscore.pluralize
@@ -223,6 +226,8 @@
@query = params[:query] || ''
@query.strip!
+ query = @query
+
limit = params[:num] ? params[:num] : Conf.default_search_size
limit = 1 if limit < 1
@@ -232,9 +237,14 @@
if Conf.solr_enable && address@hidden
begin
- solr_results = model.find_by_solr(@query.downcase, :offset => offset, :limit => limit)
- @total_count = solr_results.total
- @collection = PaginatedArray.new(solr_results.results,
+
+ search_results = model.search do
+ fulltext query.downcase
+ paginate :page => params[:page], :per_page => limit
+ end
+
+ @total_count = search_results.total
+ @collection = PaginatedArray.new(search_results.results,
:offset => offset, :limit => limit, :total => @total_count)
rescue
flash.now[:error] = "There was a problem with your search query."
Modified: trunk/app/controllers/services_controller.rb (3445 => 3446)
--- trunk/app/controllers/services_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/services_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -11,15 +11,6 @@
# GET /algorithms;search
def search
-# @query = params[:query] || ''
-# @query.strip!
-#
-# @contributables = (Conf.solr_enable && address@hidden) ? Algorithm.find_by_solr(@query, :limit => 100).results : []
-# @total_count = (Conf.solr_enable && address@hidden) ? Algorithm.count_by_solr(@query) : 0
-#
-# respond_to do |format|
-# format.html # search.rhtml
-# end
end
# GET /services
Modified: trunk/app/controllers/users_controller.rb (3445 => 3446)
--- trunk/app/controllers/users_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/users_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -751,11 +751,11 @@
def find_users
@users = User.find(:all,
:order => "users.name ASC",
- :page => { :size => 20,
- :current => params[:page] },
:conditions => "users.activated_at IS NOT NULL",
:include => :profile)
-
+
+ @users = @users.paginate(:page => params[:page], :per_page => 20)
+
@users.each do |user|
user.salt = nil
user.crypted_password = nil
Modified: trunk/app/controllers/workflows_controller.rb (3445 => 3446)
--- trunk/app/controllers/workflows_controller.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/controllers/workflows_controller.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -108,7 +108,7 @@
end
@workflow.reload
- @workflow.solr_save if Conf.solr_enable
+ @workflow.solr_index if Conf.solr_enable
end
# GET /workflows/1;download
@@ -342,7 +342,7 @@
if params[:workflow][:tag_list]
@workflow.refresh_tags(convert_tags_to_gem_format(params[:workflow][:tag_list]), current_user)
@workflow.reload
- @workflow.solr_save if Conf.solr_enable
+ @workflow.solr_index if Conf.solr_enable
end
begin
@@ -526,7 +526,7 @@
if params[:workflow][:tag_list]
@workflow.refresh_tags(convert_tags_to_gem_format(params[:workflow][:tag_list]), current_user)
@workflow.reload
- @workflow.solr_save if Conf.solr_enable
+ @workflow.solr_index if Conf.solr_enable
end
policy_err_msg = update_policy(@workflow, params)
Modified: trunk/app/models/blob.rb (3445 => 3446)
--- trunk/app/models/blob.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/blob.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -8,6 +8,7 @@
require 'acts_as_creditable'
require 'acts_as_attributor'
require 'acts_as_attributable'
+require 'sunspot_rails'
class Blob < ActiveRecord::Base
@@ -32,9 +33,24 @@
:mutable => [ :title, :body, :body_html ]
- acts_as_solr(:fields => [{:title => {:boost => 2.0}}, :local_name, :body, :kind, :contributor_name, :tag_list],
- :include => [ :comments ]) if Conf.solr_enable
+ if Conf.solr_enable
+ searchable do
+ text :title, :boost => 2.0
+ text :local_name
+ text :body
+ text :kind
+ text :contributor_name
+ text :tags do
+ tags.map { |tag| tag.name }
+ end
+
+ text :comments do
+ comments.map { |comment| comment.comment }
+ end
+ end
+ end
+
belongs_to :content_blob, :dependent => :destroy
belongs_to :content_type
belongs_to :license
Modified: trunk/app/models/comment.rb (3445 => 3446)
--- trunk/app/models/comment.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/comment.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -13,8 +13,6 @@
# NOTE: Comments belong to a user
belongs_to :user
- acts_as_solr :fields => [ :comment ] if Conf.solr_enable
-
acts_as_simile_timeline_event(
:fields => {
:start => :created_at,
Modified: trunk/app/models/network.rb (3445 => 3446)
--- trunk/app/models/network.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/network.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -6,6 +6,7 @@
require 'acts_as_contributor'
require 'acts_as_creditor'
require 'acts_as_site_entity'
+require 'sunspot_rails'
class Network < ActiveRecord::Base
acts_as_contributor
@@ -19,10 +20,24 @@
has_many :blobs, :as => :contributor
has_many :workflows, :as => :contributor
has_many :policies, :as => :contributor
-
- acts_as_solr(:fields => [ {:title => {:boost => 2.0}}, :unique_name, :owner_name, :description, :tag_list ],
- :include => [ :comments ]) if Conf.solr_enable
+ if Conf.solr_enable
+ searchable do
+ text :title, :boost => 2.0
+ text :unique_name
+ text :owner_name
+ text :description
+
+ text :tags do
+ tags.map { |tag| tag.name }
+ end
+
+ text :comments do
+ comments.map { |comment| comment.comment }
+ end
+ end
+ end
+
format_attribute :description
def self.recently_created(limit=5)
Modified: trunk/app/models/pack.rb (3445 => 3446)
--- trunk/app/models/pack.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/pack.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -9,8 +9,8 @@
require 'zip/zip'
require 'tempfile'
require 'cgi'
+require 'sunspot_rails'
-
class Pack < ActiveRecord::Base
acts_as_site_entity :owner_text => 'Creator'
@@ -37,9 +37,22 @@
format_attribute :description
- acts_as_solr(:fields => [ {:title => {:boost => 2.0}}, :description, :contributor_name, :tag_list ],
- :include => [ :comments ]) if Conf.solr_enable
-
+ if Conf.solr_enable
+ searchable do
+ text :title, :boost => 2.0
+ text :description
+ text :contributor_name
+
+ text :tags do
+ tags.map { |tag| tag.name }
+ end
+
+ text :comments do
+ comments.map { |comment| comment.comment }
+ end
+ end
+ end
+
has_many :contributable_entries,
:class_name => "PackContributableEntry",
:foreign_key => :pack_id,
Modified: trunk/app/models/profile.rb (3445 => 3446)
--- trunk/app/models/profile.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/profile.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -39,17 +39,6 @@
acts_as_site_entity :owner_text => 'User'
- acts_as_solr :fields => [ :email,
- :website,
- :body,
- :field_or_industry,
- :occupation_or_roles,
- :organisations,
- :location_city,
- :location_country,
- :interests,
- :contact_details ] if Conf.solr_enable
-
def avatar?
not (picture_id.nil? or picture_id.zero?)
end
Modified: trunk/app/models/review.rb (3445 => 3446)
--- trunk/app/models/review.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/review.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -12,8 +12,6 @@
before_create :check_multiple
- acts_as_solr :fields => [ :title, :review ] if Conf.solr_enable
-
# returns the 'last created' Reviews
# the maximum number of results is set by #limit#
def self.latest(limit=10)
Modified: trunk/app/models/service.rb (3445 => 3446)
--- trunk/app/models/service.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/service.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -5,6 +5,7 @@
require 'acts_as_site_entity'
require 'acts_as_contributable'
+require 'sunspot_rails'
class Service < ActiveRecord::Base
acts_as_site_entity
@@ -15,12 +16,28 @@
has_many :service_tags
has_many :service_deployments
- acts_as_solr(:fields => [ :submitter_label, :name, :provider_label, :endpoint,
- :wsdl, :city, :country, :description, :extra_search_terms ]) if Conf.solr_enable
+ if Conf.solr_enable
+ searchable do
+ text :submitter_label
+ text :name
+ text :provider_label
+ text :endpoint
+ text :wsdl
+ text :city
+ text :country
+ text :description
- def extra_search_terms
- service_categories.map do |category| category.label end +
- service_tags.map do |tag| tag.label end +
- service_types.map do |types| types.label end
+ text :categories do
+ service_categories.map do |category| category.label end
+ end
+
+ text :tags do
+ service_tags.map do |tag| tag.label end
+ end
+
+ text :types do
+ service_types.map do |types| types.label end
+ end
+ end
end
end
Modified: trunk/app/models/user.rb (3445 => 3446)
--- trunk/app/models/user.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/user.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -8,6 +8,7 @@
require 'acts_as_site_entity'
require 'acts_as_contributor'
require 'acts_as_creditor'
+require 'sunspot_rails'
class User < ActiveRecord::Base
@@ -293,8 +294,27 @@
acts_as_creditor
- acts_as_solr(:fields => [ {:name => {:boost => 2.0}}, :tag_list ], :include => [ :profile ], :if => "activated_at") if Conf.solr_enable
+ if Conf.solr_enable
+ searchable :if => :activated_at do
+ text :name, :boost => 2.0
+ text :tags do
+ tags.map { |tag| tag.name }
+ end
+
+ text :email do profile.email end
+ text :website do profile.website end
+ text :body do profile.body end
+ text :field_or_industry do profile.field_or_industry end
+ text :occupation_or_roles do profile.occupation_or_roles end
+ text :organisations do profile.organisations end
+ text :location_city do profile.location_city end
+ text :location_country do profile.location_country end
+ text :interests do profile.interests end
+ text :contact_details do profile.contact_details end
+ end
+ end
+
validates_presence_of :name
has_one :profile,
Modified: trunk/app/models/workflow.rb (3445 => 3446)
--- trunk/app/models/workflow.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/models/workflow.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -11,6 +11,7 @@
require 'acts_as_reviewable'
require 'acts_as_runnable'
require 'previews'
+require 'sunspot_rails'
require 'scufl/model'
require 'scufl/parser'
@@ -59,9 +60,30 @@
:mutable => [ :contributor, :title, :unique_name, :body, :body_html,
:file_ext, :last_edited_by, :content_type_id, :image, :svg ]
- acts_as_solr(:fields => [{:title => {:boost => 2.0}}, :body, :filename, :tag_list, :contributor_name, :kind, :get_all_search_terms ],
- :include => [ :comments ]) if Conf.solr_enable
+ if Conf.solr_enable
+ searchable do
+ text :title, :boost => 2.0
+ text :body
+ text :filename
+ text :contributor_name
+ text :kind
+ text :get_all_search_terms
+
+ text :tags do
+ tags.map { |tag| tag.name }
+ end
+
+ text :comments do
+ comments.map { |comment| comment.comment }
+ end
+
+ text :reviews do
+ reviews.map { |review| review.title + " " + review.review }
+ end
+ end
+ end
+
acts_as_runnable
validates_presence_of :title
@@ -229,11 +251,26 @@
def filename(version=nil)
+ def aux(record)
+
+ extension = ""
+
+ if record.processor_class && record.processor_class.default_file_extension
+ extension = ".#{record.processor_class.default_file_extension}"
+ end
+
+ if record.file_ext
+ extension = ".#{record.file_ext}"
+ end
+
+ extension
+ end
+
if version.blank?
- return "#{unique_name}.#{file_ext || self.processor_class.default_file_extension}"
+ "#{unique_name}#{aux(self)}"
else
- return nil unless (workflow_version = self.find_version(version))
- return "#{workflow_version.unique_name}.#{workflow_version.file_ext || workflow_version.processor_class.default_file_extension}"
+ workflow_version = self.find_version(version)
+ "#{workflow_version.unique_name}#{aux(workflow_version)}"
end
end
@@ -243,14 +280,18 @@
def get_all_search_terms
- words = StringIO.new
+ begin
+ words = StringIO.new
- versions.each do |version|
- words << get_search_terms(version.version)
+ versions.each do |version|
+ words << get_search_terms(version.version)
+ end
+
+ words.rewind
+ words.read
+ rescue
+ nil
end
-
- words.rewind
- words.read
end
def get_tag_suggestions()
Modified: trunk/app/views/content_types/index.rhtml (3445 => 3446)
--- trunk/app/views/content_types/index.rhtml 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/views/content_types/index.rhtml 2013-02-25 12:27:30 UTC (rev 3446)
@@ -10,25 +10,27 @@
<%= render :partial => "layouts/paginate", :locals => { :collection => @content_types } %>
- <center>
- <table class="simple">
- <thead>
- <tr>
- <td>Title</td>
- <td>Count</td>
- <td>Category</td>
- </tr>
- </thead>
- <tbody>
- <% @content_types.each do |ct| %>
+ <div style="clear: both">
+ <center>
+ <table class="simple">
+ <thead>
<tr>
- <td><%= link_to(h(ct.title), content_type_path(ct)) %></td>
- <td style="text-align: right"><%= Contribution.count(:conditions => ['content_type_id = ?', ct.id]) -%></td>
- <td><%= visible_name(ct.category) %></td>
- <% end %>
- </tbody>
- </table>
- </center>
+ <td>Title</td>
+ <td>Count</td>
+ <td>Category</td>
+ </tr>
+ </thead>
+ <tbody>
+ <% @content_types.each do |ct| %>
+ <tr>
+ <td><%= link_to(h(ct.title), content_type_path(ct)) %></td>
+ <td style="text-align: right"><%= Contribution.count(:conditions => ['content_type_id = ?', ct.id]) -%></td>
+ <td><%= visible_name(ct.category) %></td>
+ <% end %>
+ </tbody>
+ </table>
+ </center>
+ </div>
<ul>
</ul>
Modified: trunk/app/views/layouts/_paginate.rhtml (3445 => 3446)
--- trunk/app/views/layouts/_paginate.rhtml 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/app/views/layouts/_paginate.rhtml 2013-02-25 12:27:30 UTC (rev 3446)
@@ -1,3 +1,5 @@
+<%= stylesheet_link_tag "pagination" %>
+
<% if local_assigns[:sort_by] %>
<div style="float: right; margin: 1em;">
Sort by:
@@ -20,37 +22,7 @@
</div>
<% end %>
-<% if collection.page_count != collection.first_page -%>
-<div class="pagination">
-
- <ul>
- <% if collection.previous_page? -%>
- <li class="nextpage">
- <%= link_to('« previous', request.query_parameters.merge("page" => collection.previous_page)) %>
- </li>
- <% else -%>
- <li class="disabledpage">« previous</li>
- <% end -%>
-
- <% last_page = 0 -%>
- <% windowed_pagination_links(collection, :window_size => 2, :link_to_current_page => true, :always_show_anchors => true) do |n| -%>
- <% if collection.page == n -%>
- <li class="currentpage"><%= n %></li>
- <% else -%>
- <li><%= "..." if last_page+1 < n %>
- <%= link_to(n, request.query_parameters.merge("page" => n)) %>
- </li>
- <% end -%>
- <% last_page = n -%>
- <% end -%>
-
- <% if collection.next_page? -%>
- <li class="nextpage">
- <%= link_to('next »', request.query_parameters.merge("page" => collection.next_page)) %>
- </li>
- <% else -%>
- <li class="disabledpage">next »</li>
- <% end -%>
- </ul>
+<div class="digg_pagination" style="text-align: center">
+ <%= will_paginate(collection, :outer_window => 0, :inner_window => 2) -%>
</div>
-<% end -%>
+
Modified: trunk/config/environment.rb (3445 => 3446)
--- trunk/config/environment.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/config/environment.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -33,14 +33,12 @@
:acts_as_bookmarkable,
:acts_as_commentable,
:acts_as_rateable,
- :acts_as_solr,
:acts_as_taggable_redux,
:auto_complete,
:headliner,
:oauth,
:oauth_plugin,
:open_id_authentication,
- :paginating_find,
:simile_timeline,
:validates_email_veracity_of,
:versioning
Added: trunk/config/sunspot.yml (0 => 3446)
--- trunk/config/sunspot.yml (rev 0)
+++ trunk/config/sunspot.yml 2013-02-25 12:27:30 UTC (rev 3446)
@@ -0,0 +1,18 @@
+production:
+ solr:
+ hostname: localhost
+ port: 8983
+ log_level: WARNING
+
+development:
+ solr:
+ hostname: localhost
+ port: 8982
+ log_level: INFO
+
+test:
+ solr:
+ hostname: localhost
+ port: 8981
+ log_level: WARNING
+
Modified: trunk/db/schema.rb (3445 => 3446)
--- trunk/db/schema.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/db/schema.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130124144917) do
+ActiveRecord::Schema.define(:version => 20130215162325) do
create_table "activity_limits", :force => true do |t|
t.string "contributor_type", :null => false
@@ -126,13 +126,6 @@
add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
- create_table "component_profiles", :force => true do |t|
- t.string "name"
- t.string "url"
- t.datetime "created_at"
- t.datetime "updated_at"
- end
-
create_table "concept_relations", :force => true do |t|
t.integer "subject_concept_id"
t.string "relation_type"
@@ -710,9 +703,9 @@
t.string "contributor_type"
t.string "url"
t.string "username"
- t.string "crypted_password"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "password"
end
create_table "topic_feedbacks", :force => true do |t|
@@ -836,6 +829,8 @@
t.integer "preview_id"
end
+ add_index "workflow_versions", ["workflow_id"], :name => "index_workflow_versions_on_workflow_id"
+
create_table "workflows", :force => true do |t|
t.integer "contributor_id"
t.string "contributor_type"
Modified: trunk/lib/pivoting.rb (3445 => 3446)
--- trunk/lib/pivoting.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/lib/pivoting.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -183,10 +183,12 @@
def create_search_results_table(search_query, opts)
begin
- solr_results = opts[:search_models].first.multi_solr_search(search_query,
- :models => opts[:search_models],
- :limit => opts[:search_limit],
- :results_format => :ids)
+
+ search_results = Sunspot.search opts[:search_models] do
+ fulltext search_query
+ paginate :page => 1, :per_page => opts[:search_limit]
+ end
+
rescue
return false
end
@@ -195,19 +197,16 @@
conn.execute("CREATE TEMPORARY TABLE search_results (id INT AUTO_INCREMENT UNIQUE KEY, result_type VARCHAR(255), result_id INT)")
- # This next part converts the search results to SQL values
+ # This next part converts the search results to an SQL "VALUES" clause
#
- # from: { "id" => "Workflow:4" }, { "id" => "Pack:6" }, ...
- # to: "(NULL, 'Workflow', '4'), (NULL, 'Pack', '6'), ..."
+ # e.g. "(NULL, 'Workflow', '4'), (NULL, 'Pack', '6'), ..."
- if solr_results.results.length > 0
- insert_part = solr_results.results.map do |result|
- "(NULL, " + result["id"].split(":").map do |bit|
- "'#{bit}'"
- end.join(", ") + ")"
+ if search_results.results.length > 0
+ values = search_results.results.map do |result|
+ "(NULL, '#{result.class.name}', '#{result.id}')"
end.join(", ")
- conn.execute("INSERT INTO search_results VALUES #{insert_part}")
+ conn.execute("INSERT INTO search_results VALUES #{values}")
end
true
@@ -493,12 +492,12 @@
:group => "#{group_by} #{having_clause}",
:order => order_options["order"]}
+ results = collection.find(:all, result_options)
+
unless opts[:no_pagination]
- result_options[:page] = { :size => params["num"] ? params["num"].to_i : nil, :current => params["page"] }
+ results = results.paginate(:page => params["page"], :per_page => params["num"] ? params["num"].to_i : nil)
end
- results = collection.find(:all, result_options)
-
# produce a query hash to match the current filters
opts[:filter_params] = {}
Modified: trunk/lib/rest.rb (3445 => 3446)
--- trunk/lib/rest.rb 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/lib/rest.rb 2013-02-25 12:27:30 UTC (rev 3446)
@@ -8,6 +8,7 @@
require 'xml/libxml'
require 'uri'
require 'pivoting'
+require 'will_paginate'
include LibXML
@@ -595,11 +596,10 @@
obs = find_paginated_auth( { :model => model_name.camelize, :find_args => find_args }, limit, page, filters, user) { |args, size, page|
find_args = args[:find_args].clone
- find_args[:page] = { :size => size, :current => page }
- results = eval(args[:model]).find(:all, find_args)
+ results = args[:model].constantize.find(:all, find_args).paginate(:page => page, :per_page => size)
- results unless results.page > results.page_count
+ results unless results.empty?
}
end
@@ -1587,7 +1587,11 @@
q = args[:query]
models = args[:models]
- search_result = models[0].multi_solr_search(q, :limit => size, :offset => size * (page - 1), :models => models)
+ search_result = Sunspot.search models do
+ fulltext q
+ paginate :page => page, :per_page => size
+ end
+
search_result.results unless search_result.total < (size * (page - 1))
}
end
@@ -2016,7 +2020,7 @@
event.save
end
- subject.solr_save
+ subject.solr_index
return rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
end
Modified: trunk/public/stylesheets/styles.css (3445 => 3446)
--- trunk/public/stylesheets/styles.css 2013-02-24 09:09:31 UTC (rev 3445)
+++ trunk/public/stylesheets/styles.css 2013-02-25 12:27:30 UTC (rev 3446)
@@ -909,50 +909,6 @@
border: 1px dotted #999999;
}
-/* http://www.mis-algoritmos.com/wp-content/uploads/pagstyle.php?q=manu */
-.pagination {
- padding: 3px;
- margin: 3px;
- text-align: center;
-}
-
-.pagination ul {
- list-style-type: none;
-}
-
-.pagination ul li {
- display: inline;
-}
-
-.pagination a {
- padding: 2px 5px 2px 5px;
- margin: 2px;
- border: 1px solid #317eff;
- text-decoration: none; /* no underline */
- color: #179032;
-}
-
-.pagination a:hover,.pagination a:active {
- border: 1px solid #CE0434;
- color: #179032;
-}
-
-.pagination .currentpage {
- padding: 2px 5px 2px 5px;
- margin: 2px;
- border: 1px solid #179032;
- font-weight: bold;
- background-color: #179032;
- color: #FFF;
-}
-
-.pagination .disabledpage {
- padding: 2px 5px 2px 5px;
- margin: 2px;
- border: 1px solid #EEE;
- color: #DDD;
-}
-
.network_banner { /*width: 640px;*/
padding-left: 10px;
padding-right: 10px;
@@ -2446,4 +2402,4 @@
font-weight: bold;
color: #333333;
font-size: 100%;
-}
\ No newline at end of file
+}