Class: ActiveFedora::SolrService
- Inherits:
-
Object
- Object
- ActiveFedora::SolrService
- Extended by:
- Deprecation
- Defined in:
- lib/active_fedora/solr_service.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Class Method Summary collapse
- .add(doc, params = {}) ⇒ Object
-
.class_from_solr_document(hit, opts = {}) ⇒ Object
Returns the best singular class for the solr object.
-
.classes_from_solr_document(hit, opts = {}) ⇒ Object
Returns all possible classes for the solr object.
- .commit ⇒ Object
-
.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.
- .construct_query_for_pids(id_array) ⇒ Object
-
.construct_query_for_rel(field_pairs, join_with = 'AND') ⇒ Object
Create a query with a clause for each key, value.
-
.count(query, args = {}) ⇒ Integer
Get the count of records that match the query.
- .delete(id) ⇒ Object
- .get(query, args = {}) ⇒ Object
- .instance ⇒ Object
- .lazy_reify_solr_results(solr_results, opts = {}) ⇒ Object
- .query(query, args = {}) ⇒ Object
-
.raw_query(key, value) ⇒ Object
Create a raw query clause suitable for sending to solr as an fq element.
- .register(host = nil, args = {}) ⇒ Object
- .reify_solr_result(hit, opts = {}) ⇒ Object
- .reify_solr_results(solr_results, opts = {}) ⇒ Object
- .reset! ⇒ Object
- .select_path ⇒ Object
- .solr_name(*args) ⇒ Object
Instance Method Summary collapse
-
#initialize(host, args) ⇒ SolrService
constructor
A new instance of SolrService.
Constructor Details
#initialize(host, args) ⇒ SolrService
Returns a new instance of SolrService.
10 11 12 13 14 15 |
# File 'lib/active_fedora/solr_service.rb', line 10 def initialize(host, args) host = 'http://localhost:8080/solr' unless host args = { read_timeout: 120, open_timeout: 120 }.merge(args.dup) args[:url] = host @conn = RSolr.connect args end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
8 9 10 |
# File 'lib/active_fedora/solr_service.rb', line 8 def conn @conn end |
Class Method Details
.add(doc, params = {}) ⇒ Object
144 145 146 |
# File 'lib/active_fedora/solr_service.rb', line 144 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
63 64 65 66 |
# File 'lib/active_fedora/solr_service.rb', line 63 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
57 58 59 60 |
# File 'lib/active_fedora/solr_service.rb', line 57 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 |
.commit ⇒ Object
148 149 150 |
# File 'lib/active_fedora/solr_service.rb', line 148 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
72 73 74 75 |
# File 'lib/active_fedora/solr_service.rb', line 72 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
77 78 79 80 |
# File 'lib/active_fedora/solr_service.rb', line 77 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
103 104 105 106 |
# File 'lib/active_fedora/solr_service.rb', line 103 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
135 136 137 138 |
# File 'lib/active_fedora/solr_service.rb', line 135 def count(query, args = {}) args = args.merge(rows: 0) SolrService.get(query, args)['response']['numFound'].to_i end |
.delete(id) ⇒ Object
127 128 129 |
# File 'lib/active_fedora/solr_service.rb', line 127 def delete(id) SolrService.instance.conn.delete_by_id(id, params: { 'softCommit' => true }) end |
.get(query, args = {}) ⇒ Object
108 109 110 111 |
# File 'lib/active_fedora/solr_service.rb', line 108 def get(query, args = {}) args = args.merge(q: query, qt: 'standard') SolrService.instance.conn.get(select_path, params: args) end |
.instance ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_fedora/solr_service.rb', line 30 def instance # Register Solr unless Thread.current[:solr_service] register(ActiveFedora.solr_config[:url], ActiveFedora.solr_config) end raise SolrNotInitialized unless Thread.current[:solr_service] Thread.current[:solr_service] end |
.lazy_reify_solr_results(solr_results, opts = {}) ⇒ Object
41 42 43 44 |
# File 'lib/active_fedora/solr_service.rb', line 41 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
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/active_fedora/solr_service.rb', line 113 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
85 86 87 88 |
# File 'lib/active_fedora/solr_service.rb', line 85 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(host = nil, args = {}) ⇒ Object
18 19 20 |
# File 'lib/active_fedora/solr_service.rb', line 18 def register(host = nil, args = {}) Thread.current[:solr_service] = new(host, args) end |
.reify_solr_result(hit, opts = {}) ⇒ Object
51 52 53 54 |
# File 'lib/active_fedora/solr_service.rb', line 51 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
46 47 48 49 |
# File 'lib/active_fedora/solr_service.rb', line 46 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
22 23 24 |
# File 'lib/active_fedora/solr_service.rb', line 22 def reset! Thread.current[:solr_service] = nil end |
.select_path ⇒ Object
26 27 28 |
# File 'lib/active_fedora/solr_service.rb', line 26 def select_path ActiveFedora.solr_config.fetch(:select_path, 'select') end |
.solr_name(*args) ⇒ Object
90 91 92 93 |
# File 'lib/active_fedora/solr_service.rb', line 90 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 |