Class: ActiveFedora::SolrService
- Inherits:
-
Object
- Object
- ActiveFedora::SolrService
- Extended by:
- Deprecation
- Defined in:
- lib/active_fedora/solr_service.rb
Instance Attribute Summary collapse
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(*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(options = {}) ⇒ SolrService
constructor
A new instance of SolrService.
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 = { read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge() end |
Instance Attribute Details
#conn ⇒ Object
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
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 |
.commit ⇒ Object
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
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
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
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 |
.instance ⇒ Object
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
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) = args. 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 [: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() 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_path ⇒ Object
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 |