-
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.
- Loading branch information
Showing
5 changed files
with
215 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Document < ActiveRecord::Base | ||
include Blacklight::Document | ||
|
||
def to_partial_path | ||
'catalog/document' | ||
end | ||
|
||
def key? k | ||
attributes.has_key? k.to_s | ||
end | ||
|
||
def _source | ||
self | ||
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,48 @@ | ||
# -*- encoding : utf-8 -*- | ||
class CreateDocument < ActiveRecord::Migration | ||
def self.up | ||
create_table :documents do |t| | ||
|
||
t.string :lc_1letter_facet | ||
t.string :author_t | ||
t.string :marc_display | ||
t.string :published_display | ||
t.string :author_display | ||
t.string :lc_callnum_display | ||
t.string :title_t | ||
t.string :pub_date | ||
t.string :pub_date_sort | ||
t.string :format | ||
t.string :material_type_display | ||
t.string :lc_b4cutter_facet | ||
t.string :title_display | ||
t.string :title_sort | ||
t.string :author_sort | ||
t.string :title_addl_t | ||
t.string :author_addl_t | ||
t.string :lc_alpha_facet | ||
t.string :language_facet | ||
t.string :subtitle_display | ||
t.string :author_vern_display | ||
t.string :subject_addl_t | ||
t.string :subject_era_facet | ||
t.string :isbn_t | ||
t.string :subject_geo_facet | ||
t.string :subject_topic_facet | ||
t.string :title_series_t | ||
t.string :subtitle_t | ||
t.string :title_vern_display | ||
t.string :published_vern_display | ||
t.string :subtitle_vern_display | ||
t.string :subject_t | ||
t.string :title_added_entry_t | ||
t.string :url_suppl_display | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :documents | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
module Blacklight | ||
module Ar | ||
class Repository < Blacklight::AbstractRepository | ||
|
||
class SingleDocumentResponse | ||
def initialize doc | ||
@doc = doc | ||
end | ||
|
||
def documents | ||
[@doc] | ||
end | ||
end | ||
|
||
class FacetResponse | ||
attr_reader :name, :counts | ||
|
||
def initialize name, counts | ||
@name = name | ||
@counts = counts | ||
end | ||
|
||
def items | ||
counts.map do |key, count| | ||
OpenStruct.new(name: name, value: key, hits: count) | ||
end | ||
end | ||
|
||
def sort; end | ||
def offset; end | ||
def limit; end | ||
end | ||
|
||
class Aggregations | ||
def initialize response | ||
@response = response | ||
end | ||
|
||
def [] key | ||
FacetResponse.new(key, @response.response.group(key).count) | ||
end | ||
end | ||
|
||
class SearchResponse | ||
attr_reader :response, :params | ||
|
||
include Kaminari::PageScopeMethods | ||
include Kaminari::ConfigurationMethods::ClassMethods | ||
|
||
def initialize response, params | ||
@response = response | ||
@params = params | ||
end | ||
|
||
def grouped? | ||
false | ||
end | ||
|
||
def results | ||
response | ||
end | ||
|
||
def total | ||
response.total_count | ||
end | ||
|
||
alias_method :documents, :results | ||
|
||
delegate :empty?, to: :results | ||
|
||
def aggregations | ||
Aggregations.new(self) | ||
end | ||
|
||
alias_method :total_count, :total | ||
|
||
def start | ||
params.start | ||
end | ||
alias_method :offset_value, :start | ||
|
||
def limit_value | ||
params.per | ||
end | ||
alias_method :rows, :limit_value | ||
|
||
def sort | ||
params.send(:sort) | ||
end | ||
|
||
def spelling | ||
nil | ||
end | ||
|
||
end | ||
|
||
## | ||
# Find a single document result (by id) using the document configuration | ||
# @param [String] document's unique key value | ||
def find id, params = {} | ||
response = SingleDocumentResponse.new(blacklight_config.document_model.find(id)) | ||
response | ||
end | ||
|
||
## | ||
# Execute a search query | ||
# @param [Hash] elastic search query parameters | ||
def search params = {} | ||
Rails.logger.info "AR parameters: #{params.inspect}" | ||
SearchResponse.new(params.search(blacklight_config.document_model), params) | ||
end | ||
end | ||
|
||
class SearchBuilder < Blacklight::SearchBuilder | ||
self.default_processor_chain = [] | ||
|
||
attr_accessor :scopes | ||
|
||
def initialize *args | ||
super | ||
self.scopes = [] | ||
end | ||
|
||
def query *args | ||
self | ||
end | ||
|
||
def search model | ||
scope = model.page(page).per(per).padding(start % per) | ||
|
||
if sort | ||
scope = scope.order(sort) | ||
end | ||
|
||
(blacklight_params[:f] || {}).each do |field, values| | ||
scope = scope.where(field => Array(values)) | ||
end | ||
|
||
scope.all | ||
end | ||
|
||
|
||
end | ||
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