Skip to content

Commit

Permalink
Find MVW from children.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Apr 22, 2016
1 parent dba6857 commit b152166
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Simplified catalog controller
class CatalogController < ApplicationController
include Blacklight::Catalog
self.search_params_logic += [:hide_parented_resources, :join_from_parent]

configure_blacklight do |config|
config.show.oembed_field = :oembed_url_ssm
Expand Down
9 changes: 9 additions & 0 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ class SearchBuilder < Blacklight::SearchBuilder
include Blacklight::Solr::SearchBuilderBehavior

include Spotlight::Catalog::AccessControlsEnforcement::SearchBuilder

def hide_parented_resources(solr_params)
solr_params[:fq] ||= []
solr_params[:fq] << "!#{Spotlight::Resources::Iiif::Engine.config.collection_id_field}:['' TO *]"
end

def join_from_parent(solr_params)
solr_params[:q] = JoinChildrenQuery.new(solr_params[:q]).to_s
end
end
35 changes: 35 additions & 0 deletions app/models/search_builder/join_children_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class SearchBuilder
class JoinChildrenQuery
attr_reader :parent_query
def initialize(parent_query)
@parent_query = parent_query
end

def to_s
queries.map do |query|
"(#{dismax_join(send(query))})"
end.join(" OR ")
end

private

def queries
[
:main_query,
:query_children
]
end

def dismax_join(query)
"#{query}{!dismax}#{parent_query}"
end

def main_query
""
end

def query_children
"{!join from=collection_id_ssim to=id}"
end
end
end
31 changes: 31 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'rails_helper'

RSpec.describe CatalogController do
context "with mvw", vcr: { cassette_name: 'mvw' } do
let(:url) { "https://hydra-dev.princeton.edu/concern/multi_volume_works/f4752g76q/manifest" }
it "hides scanned resources with parents" do
exhibit = Spotlight::Exhibit.create title: 'Exhibit A'
resource = IIIFResource.new manifest_url: url, exhibit: exhibit
expect(resource.save_and_index).to be_truthy

get :index, q: "", exhibit_id: exhibit.id

expect(document_ids).to eq [resource.to_solr.to_a.first[:id]]
end
it "returns MVW from metadata found in volume" do
exhibit = Spotlight::Exhibit.create title: 'Exhibit A'
resource = IIIFResource.new manifest_url: url, exhibit: exhibit
expect(resource.save_and_index).to be_truthy

get :index, q: "SR1", exhibit_id: exhibit.id

expect(document_ids).to eq [resource.to_solr.to_a.first[:id]]
end
end

def document_ids
assigns[:document_list].map do |x|
x["id"]
end
end
end

0 comments on commit b152166

Please sign in to comment.