-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract SolrDocument references from controllers and models and define
the solr document class to use in the blacklight configuration. - add blacklight_config.solr_document_model configuration (defaults to SolrDocument) - make Bookmarks polymorphic and refactor Bookmarks to use objects instead of passing IDs around
- Loading branch information
Showing
21 changed files
with
214 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
# -*- encoding : utf-8 -*- | ||
class Bookmark < ActiveRecord::Base | ||
|
||
belongs_to :user | ||
validates_presence_of :user_id, :scope=>:document_id | ||
attr_accessible :id, :document_id, :title if Rails::VERSION::MAJOR < 4 | ||
belongs_to :user, polymorphic: true | ||
belongs_to :document, polymorphic: true | ||
|
||
validates_presence_of :user_id, :scope=>:document_id | ||
attr_accessible :id, :document_id, :document_type, :title if Rails::VERSION::MAJOR < 4 | ||
|
||
def document | ||
SolrDocument.new SolrDocument.unique_key => document_id | ||
document_type.new document_type.unique_key => document_id | ||
end | ||
|
||
def document_type | ||
(super.constantize if defined?(super)) || default_document_type | ||
end | ||
|
||
def default_document_type | ||
SolrDocument | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class SolrDocument | ||
|
||
include Blacklight::Solr::Document | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
db/migrate/20140320000000_add_polymorphic_type_to_bookmarks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- encoding : utf-8 -*- | ||
class AddPolymorphicTypeToBookmarks < ActiveRecord::Migration | ||
def change | ||
add_column(:bookmarks, :document_type, :string) | ||
|
||
add_index :bookmarks, :user_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Blacklight::SolrResponse::Response | ||
def response | ||
self[:response] || {} | ||
end | ||
|
||
# short cut to response['numFound'] | ||
def total | ||
response[:numFound].to_s.to_i | ||
end | ||
|
||
def start | ||
response[:start].to_s.to_i | ||
end | ||
|
||
def empty? | ||
total == 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.