Class: Qa::LDF::NamespacedSearchService

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/ldf/namespaced_search_service.rb

Overview

A search service that wraps another SearchService and casts its ids to a namespace.

Examples:

nsify = Qa::LDF::NamespacedSearchService.new do |service|
  service.namespace      = 'http://example.com/ns/'
  service.parent_service = a_search_service_instance
end

# when
a_search_service_endpoint.search('moomin') # => { 'id' => 'blah' }

# then
nsify.search('moomin') # => { 'id' => 'http://example.com/ns/blah' }

Direct Known Subclasses

FAST::SearchService, LCNames::SearchService

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|service| ... } ⇒ NamespacedSearchService

Returns a new instance of NamespacedSearchService.

Yield Parameters:



30
31
32
# File 'lib/qa/ldf/namespaced_search_service.rb', line 30

def initialize
  yield self
end

Instance Attribute Details

#namespaceString

Returns:

  • (String)


26
27
28
# File 'lib/qa/ldf/namespaced_search_service.rb', line 26

def namespace
  @namespace
end

#parent_service#search

Returns:



26
# File 'lib/qa/ldf/namespaced_search_service.rb', line 26

attr_accessor :namespace, :parent_service

Instance Method Details

#apply_namespace(id) ⇒ Object



50
51
52
53
# File 'lib/qa/ldf/namespaced_search_service.rb', line 50

def apply_namespace(id)
  return id if RDF::URI(id).valid?
  (RDF::URI(namespace) / id).to_s
end

#search(query) ⇒ Object

See Also:

  • Authority::Base#search


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/qa/ldf/namespaced_search_service.rb', line 36

def search(query)
  responses = parent_service.search(query)

  responses.map do |result|
    if result.keys.first.is_a?(Symbol)
      result[:id] = apply_namespace(result[:id])
    else
      result['id'] = apply_namespace(result['id'])
    end

    result
  end
end