Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
HCSVLAB-1165: Updates Sesame mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Anisimoff committed Dec 16, 2015
1 parent d956ee3 commit 46bd77b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
39 changes: 29 additions & 10 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,13 @@ def advanced_search_syntax
# override default show method to allow for json response
#
def show
if Item.where(id: params[:id]).count != 0
@item = Item.find_by_handle("#{params[:collection]}:#{params[:itemId]}")
#require 'pry'
#binding.pry
@item = Item.find_by_handle("#{params[:collection]}:#{params[:itemId]}")
unless @item.nil?
render 'catalog/processing_show' and return if @processing_index


@response, @document = get_solr_response_for_doc_id

# For some reason blacklight stopped to fullfill the counter value in the session since we changed
Expand Down Expand Up @@ -916,6 +919,8 @@ def add_unlimited_rows(solr_parameters, user_params)
# sequential identifier.
#
def retrieve_and_set_item_id
# require 'pry'
# binding.pry
handle = nil
handle = "#{params[:collection]}:#{params[:itemId]}" if params[:collection].present? and params[:itemId].present?

Expand All @@ -927,7 +932,8 @@ def retrieve_and_set_item_id
format.any { render :json => {:error => "not-found"}.to_json, :status => 404 and return }
end
end
params[:id] = item.id
# params[:id] = item.id
params[:id] = handle
end
end

Expand All @@ -950,6 +956,8 @@ def check_item_indexed
#
#
def wrapped_enforce_show_permissions(opts={})
# require 'pry'
# binding.pry
begin
enforce_show_permissions(opts) unless @processing_index
rescue Hydra::AccessDenied => e
Expand Down Expand Up @@ -1159,8 +1167,11 @@ def query_annotation_properties(item)
# Get the display document for an item as a hash with id, type and source
#
def get_display_document(document)
item = Item.find(document[:id])

# TODO: this is a really silly, it uses a solr document to locate and item in postgres, then
# uses that result to finally query sesame. We'd be better off just putting it in postgress
# item = Item.find(document[:id])
item = Item.find_by_handle(document[:handle])
display_document = nil
begin
server = RDF::Sesame::HcsvlabServer.new(SESAME_CONFIG["url"].to_s)
repository = server.repository(item.collection.name)
Expand All @@ -1171,18 +1182,26 @@ def get_display_document(document)
pattern [:display_doc, MetadataHelper::SOURCE, :source]
pattern [:display_doc, MetadataHelper::IDENTIFIER, :id]
end

results = repository.query(query)

results.each do |res|
return {:id => res[:id].value, :type => res[:type].value, :source => res[:source].value}
end
# require 'pry'
# binding.pry

display_document = results.first.to_hash
display_document.each { |k,v|
display_document[k] = v.value
}

# results.each do |res|
# return {:id => res[:id].value, :type => res[:type].value, :source => res[:source].value}
# end

rescue => e
Rails.logger.error e.inspect
Rails.logger.error "Could not connect to triplestore - #{SESAME_CONFIG["url"].to_s}"
end
return nil
display_document
end

def user_params
Expand Down
1 change: 1 addition & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SolrDocument
include Blacklight::Solr::Document

# self.unique_key = 'id'
self.unique_key = 'handle'

# The following shows how to setup this blacklight document to display marc documents
extension_parameters[:marc_source_field] = :marc_display
Expand Down
5 changes: 3 additions & 2 deletions solr_conf/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from this file. Please refer to http://wiki.apache.org/solr/SchemaXml,
as well as the default schema file included with Solr -->

<uniqueKey>id</uniqueKey>
<!-- <uniqueKey>id</uniqueKey> -->
<uniqueKey>handle</uniqueKey>

<fields>

Expand All @@ -24,7 +25,7 @@
<field name="AUSNC_communication_medium_facet" type="string" stored="true" indexed="true" multiValued="true" required="false"/>

<field name="handle" type="string" stored="true" indexed="true" multiValued="false" required="false"/>
<field name="id" type="string" stored="true" indexed="true" multiValued="false" required="true"/>
<!-- <field name="id" type="string" stored="true" indexed="true" multiValued="false" required="true"/> -->
<field name="timestamp" type="date" stored="true" indexed="true" default="NOW" multiValued="false"/>
<field name="full_text" type="full_text" stored="true" indexed="true" multiValued="false" termVectors="true" termPositions="true" termOffsets="true"/>
<field name="all_metadata" type="text_ws" stored="true" indexed="true" multiValued="true"/>
Expand Down

0 comments on commit 46bd77b

Please sign in to comment.