Skip to content

Commit

Permalink
Merge cc523ef into 8e9b2dd
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Mar 8, 2019
2 parents 8e9b2dd + cc523ef commit dd9abbf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/qa/authorities/linked_data/search_query.rb
Expand Up @@ -68,11 +68,15 @@ def preds_for_search
preds = { label: label_pred_uri }
preds[:uri] = :subject_uri
preds[:altlabel] = search_config.results_altlabel_predicate unless search_config.results_altlabel_predicate.nil?
preds[:id] = search_config.results_id_predicate unless search_config.results_id_predicate.nil?
preds[:id] = id_predicate.present? ? id_predicate : :subject_uri
preds[:sort] = sort_predicate.present? ? sort_predicate : preds[:label]
preds
end

def id_predicate
@id_predicate ||= search_config.results_id_predicate
end

def sort_predicate
@sort_predicate ||= search_config.results_sort_predicate
end
Expand All @@ -86,7 +90,7 @@ def convert_results_to_json(results)
def convert_result_to_json(result)
json_result = {}
json_result[:uri] = result[:uri].first.to_s
json_result[:id] = result[:id].first.to_s
json_result[:id] = result[:id].any? ? result[:id].first.to_s : ""
json_result[:label] = full_label(result[:label], result[:altlabel])
json_result[:context] = result[:context] if context?
json_result
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/authorities/linked_data/lod_min_config.json
Expand Up @@ -43,7 +43,6 @@
"query": "query"
},
"results": {
"id_predicate": "http://purl.org/dc/terms/identifier",
"label_predicate": "http://www.w3.org/2004/02/skos/core#prefLabel"
}
}
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/authorities/linked_data/generic_authority_spec.rb
Expand Up @@ -58,6 +58,21 @@
end
end

context 'when id predicate is not specified' do
let(:min_authority) { described_class.new(:LOD_MIN_CONFIG) }
let :results do
stub_request(:get, 'http://localhost/test_default/search?query=peanuts')
.to_return(status: 200, body: webmock_fixture('lod_oclc_personalName_query_3_results.rdf.xml'), headers: { 'Content-Type' => 'application/rdf+xml' })
min_authority.search('peanuts')
end
it 'uses subject uri for id' do
expect(results.count).to eq(3)
expect(results.first).to eq(uri: 'http://id.worldcat.org/fast/409667', id: 'http://id.worldcat.org/fast/409667', label: 'Cornell, Ezra, 1807-1874')
expect(results.second).to eq(uri: 'http://id.worldcat.org/fast/5140', id: 'http://id.worldcat.org/fast/5140', label: 'Cornell, Joseph')
expect(results.third).to eq(uri: 'http://id.worldcat.org/fast/72456', id: 'http://id.worldcat.org/fast/72456', label: 'Cornell, Sarah Maria, 1802-1832')
end
end

# context 'in LOC authority' do
# ###################################
# ### SEARCH NOT SUPPORTED BY LOC ###
Expand Down

0 comments on commit dd9abbf

Please sign in to comment.