Class: ActiveFedora::SolrService

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/active_fedora/solr_service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SolrService

Returns a new instance of SolrService.



10
11
12
# File 'lib/active_fedora/solr_service.rb', line 10

def initialize(options = {})
  @options = { read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge(options)
end

Instance Attribute Details

#connObject



14
15
16
# File 'lib/active_fedora/solr_service.rb', line 14

def conn
  @conn ||= RSolr.connect @options
end

Class Method Details

.add(doc, params = {}) ⇒ Object

Parameters:

  • doc (Hash)

    the document to index

  • params (Hash) (defaults to: {})

    :commit => commits immediately :softCommit => commit to memory, but don’t flush to disk



155
156
157
# File 'lib/active_fedora/solr_service.rb', line 155

def add(doc, params = {})
  SolrService.instance.conn.add(doc, params: params)
end

.class_from_solr_document(hit, opts = {}) ⇒ Object

Returns the best singular class for the solr object



74
75
76
77
# File 'lib/active_fedora/solr_service.rb', line 74

def class_from_solr_document(hit, opts = {})
  Deprecation.warn SolrService, "SolrService.class_from_solr_document is deprecated. Use SolrHit#model instead. This will be removed in active-fedora 10.0"
  QueryResultBuilder.class_from_solr_document(hit, opts)
end

.classes_from_solr_document(hit, opts = {}) ⇒ Object

Returns all possible classes for the solr object



68
69
70
71
# File 'lib/active_fedora/solr_service.rb', line 68

def classes_from_solr_document(hit, opts = {})
  Deprecation.warn SolrService, "SolrService.classes_from_solr_document is deprecated. Use SolrHit#models instead. This will be removed in active-fedora 10.0"
  QueryResultBuilder.classes_from_solr_document(hit, opts)
end

.commitObject



159
160
161
# File 'lib/active_fedora/solr_service.rb', line 159

def commit
  SolrService.instance.conn.commit
end

.construct_query_for_ids(id_array) ⇒ Object

Construct a solr query for a list of ids This is used to get a solr response based on the list of ids in an object’s RELS-EXT relationhsips If the id_array is empty, defaults to a query of “id:NEVER_USE_THIS_ID”, which will return an empty solr response

Parameters:

  • id_array (Array)

    the ids that you want included in the query



83
84
85
86
# File 'lib/active_fedora/solr_service.rb', line 83

def construct_query_for_ids(id_array)
  Deprecation.warn SolrService, "SolrService.construct_query_for_ids is deprecated. Use SolrQueryBuilder.construct_query_for_ids instead. This will be removed in active-fedora 10.0"
  SolrQueryBuilder.construct_query_for_ids(id_array)
end

.construct_query_for_pids(id_array) ⇒ Object



88
89
90
91
# File 'lib/active_fedora/solr_service.rb', line 88

def construct_query_for_pids(id_array)
  Deprecation.warn SolrService, "SolrService.construct_query_for_pids is deprecated. Use SolrQueryBuilder.construct_query_for_ids instead. This will be removed in active-fedora 10.0"
  SolrQueryBuilder.construct_query_for_ids(id_array)
end

.construct_query_for_rel(field_pairs, join_with = 'AND') ⇒ Object

Create a query with a clause for each key, value

Examples:

construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
# => _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"

construct_query_for_rel [[Book._reflect_on_association(:library), "foo/bar/baz"]]

Parameters:

  • field_pairs (Hash, Array<Array<String>>)

    key is the predicate, value is the target_uri

  • join_with (String) (defaults to: 'AND')

    (‘AND’) the value we’re joining the clauses with



114
115
116
117
# File 'lib/active_fedora/solr_service.rb', line 114

def construct_query_for_rel(field_pairs, join_with = 'AND')
  Deprecation.warn SolrService, "SolrService.construct_query_for_rel is deprecated. Use SolrQueryBuilder.construct_query_for_rel instead. This will be removed in active-fedora 10.0"
  SolrQueryBuilder.construct_query_for_rel(field_pairs, join_with)
end

.count(query, args = {}) ⇒ Integer

Get the count of records that match the query

Parameters:

  • query (String)

    a solr query

  • args (Hash) (defaults to: {})

    arguments to pass through to ‘args’ param of SolrService.query (note that :rows will be overwritten to 0)

Returns:

  • (Integer)

    number of records matching



146
147
148
149
# File 'lib/active_fedora/solr_service.rb', line 146

def count(query, args = {})
  args = args.merge(rows: 0)
  SolrService.get(query, args)['response']['numFound'].to_i
end

.delete(id) ⇒ Object



138
139
140
# File 'lib/active_fedora/solr_service.rb', line 138

def delete(id)
  SolrService.instance.conn.delete_by_id(id, params: { 'softCommit' => true })
end

.get(query, args = {}) ⇒ Object



119
120
121
122
# File 'lib/active_fedora/solr_service.rb', line 119

def get(query, args = {})
  args = args.merge(q: query, qt: 'standard')
  SolrService.instance.conn.get(select_path, params: args)
end

.instanceObject



42
43
44
45
46
47
48
49
50
# File 'lib/active_fedora/solr_service.rb', line 42

def instance
  # Register Solr

  unless ActiveFedora::RuntimeRegistry.solr_service
    register(ActiveFedora.solr_config)
  end

  ActiveFedora::RuntimeRegistry.solr_service
end

.lazy_reify_solr_results(solr_results, opts = {}) ⇒ Object



52
53
54
55
# File 'lib/active_fedora/solr_service.rb', line 52

def lazy_reify_solr_results(solr_results, opts = {})
  Deprecation.warn SolrService, "SolrService.lazy_reify_solr_results is deprecated. Use QueryResultBuilder.lazy_reify_solr_results instead. This will be removed in active-fedora 10.0"
  QueryResultBuilder.lazy_reify_solr_results(solr_results, opts)
end

.query(query, args = {}) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/active_fedora/solr_service.rb', line 124

def query(query, args = {})
  raw = args.delete(:raw)
  result = get(query, args)

  if raw
    Deprecation.warn SolrService, "SolrService.query with raw: true is deprecated. Use SolrService.get instead. This will be removed in active-fedora 10.0"
    return result
  end

  result['response']['docs'].map do |doc|
    ActiveFedora::SolrHit.new(doc)
  end
end

.raw_query(key, value) ⇒ Object

Create a raw query clause suitable for sending to solr as an fq element

Parameters:

  • key (String)
  • value (String)


96
97
98
99
# File 'lib/active_fedora/solr_service.rb', line 96

def raw_query(key, value)
  Deprecation.warn SolrService, "SolrService.raw_query is deprecated. Use SolrQueryBuilder.construct_query instead. This will be removed in active-fedora 10.0"
  SolrQueryBuilder.construct_query(key, value)
end

.register(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_fedora/solr_service.rb', line 19

def register(*args)
  options = args.extract_options!

  if args.length == 1
    Deprecation.warn(SolrService, "SolrService.register with a host argument is deprecated. Use `SolrService.register(url: host)` instead. This will be removed in active-fedora 10.0")

    host = args.first
    options[:url] = host if host
  elsif args.length > 1
    raise ArgumentError, "wrong number of arguments (#{args.length} for 0..2)"
  end

  ActiveFedora::RuntimeRegistry.solr_service = new(options)
end

.reify_solr_result(hit, opts = {}) ⇒ Object



62
63
64
65
# File 'lib/active_fedora/solr_service.rb', line 62

def reify_solr_result(hit, opts = {})
  Deprecation.warn SolrService, "SolrService.reify_solr_result is deprecated. Use SolrHit#reify instead. This will be removed in active-fedora 10.0"
  QueryResultBuilder.reify_solr_result(hit, opts)
end

.reify_solr_results(solr_results, opts = {}) ⇒ Object



57
58
59
60
# File 'lib/active_fedora/solr_service.rb', line 57

def reify_solr_results(solr_results, opts = {})
  Deprecation.warn SolrService, "SolrService.reify_solr_results is deprecated. Use QueryResultBuilder.reify_solr_results instead. This will be removed in active-fedora 10.0"
  QueryResultBuilder.reify_solr_results(solr_results, opts)
end

.reset!Object



34
35
36
# File 'lib/active_fedora/solr_service.rb', line 34

def reset!
  ActiveFedora::RuntimeRegistry.solr_service = nil
end

.select_pathObject



38
39
40
# File 'lib/active_fedora/solr_service.rb', line 38

def select_path
  ActiveFedora.solr_config.fetch(:select_path, 'select')
end

.solr_name(*args) ⇒ Object



101
102
103
104
# File 'lib/active_fedora/solr_service.rb', line 101

def solr_name(*args)
  Deprecation.warn SolrService, "SolrService.solr_name is deprecated. Use SolrQueryBuilder.solr_name instead. This will be removed in active-fedora 10.0"
  SolrQueryBuilder.solr_name(*args)
end