active-fedora 9.9.1 → 9.10.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -2
  3. data/.travis.yml +2 -6
  4. data/active-fedora.gemspec +9 -6
  5. data/lib/active_fedora.rb +31 -15
  6. data/lib/active_fedora/associations.rb +1 -1
  7. data/lib/active_fedora/associations/association.rb +6 -2
  8. data/lib/active_fedora/associations/belongs_to_association.rb +0 -10
  9. data/lib/active_fedora/associations/builder/association.rb +85 -12
  10. data/lib/active_fedora/associations/builder/belongs_to.rb +3 -1
  11. data/lib/active_fedora/associations/builder/collection_association.rb +4 -3
  12. data/lib/active_fedora/associations/builder/contains.rb +7 -2
  13. data/lib/active_fedora/associations/builder/directly_contains.rb +7 -3
  14. data/lib/active_fedora/associations/builder/directly_contains_one.rb +8 -4
  15. data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +6 -2
  16. data/lib/active_fedora/associations/builder/has_many.rb +6 -2
  17. data/lib/active_fedora/associations/builder/indirectly_contains.rb +7 -3
  18. data/lib/active_fedora/associations/builder/property.rb +7 -2
  19. data/lib/active_fedora/associations/builder/singular_association.rb +3 -1
  20. data/lib/active_fedora/associations/builder/singular_property.rb +3 -1
  21. data/lib/active_fedora/associations/collection_association.rb +9 -5
  22. data/lib/active_fedora/associations/collection_proxy.rb +1 -1
  23. data/lib/active_fedora/associations/contained_finder.rb +1 -2
  24. data/lib/active_fedora/associations/directly_contains_one_association.rb +1 -1
  25. data/lib/active_fedora/associations/has_many_association.rb +1 -5
  26. data/lib/active_fedora/associations/rdf.rb +1 -20
  27. data/lib/active_fedora/attached_files.rb +1 -1
  28. data/lib/active_fedora/attribute_methods.rb +18 -0
  29. data/lib/active_fedora/attributes.rb +1 -1
  30. data/lib/active_fedora/autosave_association.rb +8 -12
  31. data/lib/active_fedora/base.rb +0 -2
  32. data/lib/active_fedora/caching_connection.rb +1 -1
  33. data/lib/active_fedora/default_model_mapper.rb +24 -0
  34. data/lib/active_fedora/fedora.rb +1 -1
  35. data/lib/active_fedora/file/attributes.rb +4 -5
  36. data/lib/active_fedora/identifiable.rb +5 -0
  37. data/lib/active_fedora/indexing.rb +13 -7
  38. data/lib/active_fedora/indexing_service.rb +4 -4
  39. data/lib/active_fedora/ldp_resource.rb +1 -0
  40. data/lib/active_fedora/model.rb +18 -16
  41. data/lib/active_fedora/model_classifier.rb +77 -0
  42. data/lib/active_fedora/nested_attributes.rb +145 -18
  43. data/lib/active_fedora/persistence.rb +1 -1
  44. data/lib/active_fedora/predicates.rb +3 -0
  45. data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -1
  46. data/lib/active_fedora/query_result_builder.rb +12 -28
  47. data/lib/active_fedora/querying.rb +1 -1
  48. data/lib/active_fedora/rdf/datastream_indexing.rb +1 -1
  49. data/lib/active_fedora/reflection.rb +15 -7
  50. data/lib/active_fedora/relation.rb +17 -0
  51. data/lib/active_fedora/relation/calculations.rb +1 -5
  52. data/lib/active_fedora/relation/finder_methods.rb +39 -26
  53. data/lib/active_fedora/scoping.rb +5 -0
  54. data/lib/active_fedora/scoping/default.rb +113 -0
  55. data/lib/active_fedora/scoping/named.rb +11 -3
  56. data/lib/active_fedora/simple_datastream.rb +1 -1
  57. data/lib/active_fedora/solr_hit.rb +71 -0
  58. data/lib/active_fedora/solr_instance_loader.rb +12 -36
  59. data/lib/active_fedora/solr_query_builder.rb +20 -25
  60. data/lib/active_fedora/solr_service.rb +24 -13
  61. data/lib/active_fedora/type.rb +8 -0
  62. data/lib/active_fedora/type/boolean.rb +23 -0
  63. data/lib/active_fedora/type/value.rb +118 -0
  64. data/lib/active_fedora/validations.rb +14 -5
  65. data/lib/active_fedora/version.rb +1 -1
  66. data/lib/active_fedora/versionable.rb +8 -7
  67. data/spec/config_helper.rb +0 -5
  68. data/spec/integration/associations_spec.rb +5 -5
  69. data/spec/integration/base_spec.rb +4 -4
  70. data/spec/integration/bug_spec.rb +0 -1
  71. data/spec/integration/full_featured_model_spec.rb +4 -4
  72. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +1 -1
  73. data/spec/integration/has_many_associations_spec.rb +30 -1
  74. data/spec/integration/indirect_container_spec.rb +1 -1
  75. data/spec/integration/nested_attribute_spec.rb +6 -0
  76. data/spec/integration/ntriples_datastream_spec.rb +4 -4
  77. data/spec/integration/om_datastream_spec.rb +1 -1
  78. data/spec/integration/relation_delegation_spec.rb +1 -1
  79. data/spec/integration/scoped_query_spec.rb +12 -12
  80. data/spec/integration/solr_hit_spec.rb +52 -0
  81. data/spec/samples/hydra-mods_article_datastream.rb +2 -2
  82. data/spec/spec_helper.rb +5 -9
  83. data/spec/unit/active_fedora_spec.rb +0 -26
  84. data/spec/unit/base_spec.rb +20 -0
  85. data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -3
  86. data/spec/unit/callback_spec.rb +3 -8
  87. data/spec/unit/default_model_mapper_spec.rb +39 -0
  88. data/spec/unit/finder_methods_spec.rb +30 -6
  89. data/spec/unit/has_many_association_spec.rb +23 -1
  90. data/spec/unit/indexing_spec.rb +17 -3
  91. data/spec/unit/model_classifier_spec.rb +49 -0
  92. data/spec/unit/model_spec.rb +0 -9
  93. data/spec/unit/ntriples_datastream_spec.rb +16 -16
  94. data/spec/unit/om_datastream_spec.rb +7 -7
  95. data/spec/unit/qualified_dublin_core_datastream_spec.rb +1 -1
  96. data/spec/unit/query_result_builder_spec.rb +4 -10
  97. data/spec/unit/query_spec.rb +28 -28
  98. data/spec/unit/rdf/indexing_service_spec.rb +16 -16
  99. data/spec/unit/scoping_spec.rb +67 -0
  100. data/spec/unit/simple_datastream_spec.rb +2 -2
  101. data/spec/unit/solr_config_options_spec.rb +29 -32
  102. data/spec/unit/solr_hit_spec.rb +58 -0
  103. data/spec/unit/solr_query_builder_spec.rb +9 -1
  104. data/spec/unit/solr_service_spec.rb +19 -3
  105. metadata +73 -17
  106. data/spec/support/freeze_mocks.rb +0 -12
@@ -21,9 +21,17 @@ module ActiveFedora
21
21
  if current_scope
22
22
  current_scope.clone
23
23
  else
24
- scope = relation
25
- scope.default_scoped = true
26
- scope
24
+ default_scoped
25
+ end
26
+ end
27
+
28
+ def default_scoped
29
+ scope = build_default_scope
30
+
31
+ if scope
32
+ relation.spawn.merge!(scope)
33
+ else
34
+ relation
27
35
  end
28
36
  end
29
37
  end
@@ -79,7 +79,7 @@ module ActiveFedora
79
79
  next if field_key == :location ## FIXME HYDRA-825
80
80
  things = send(field_key)
81
81
  next unless things
82
- field_symbol = ActiveFedora::SolrQueryBuilder.solr_name(field_key, type: field_info[:type])
82
+ field_symbol = ActiveFedora.index_field_mapper.solr_name(field_key, type: field_info[:type])
83
83
  things.val.each do |val|
84
84
  ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val.to_s)
85
85
  end
@@ -0,0 +1,71 @@
1
+ module ActiveFedora
2
+ class SolrHit < Delegator
3
+ def self.for(hit)
4
+ return hit if hit.is_a? ActiveFedora::SolrHit
5
+
6
+ SolrHit.new(hit)
7
+ end
8
+
9
+ delegate :models, to: :classifier
10
+
11
+ def __getobj__
12
+ @document # return object we are delegating to, required
13
+ end
14
+
15
+ alias static_config __getobj__
16
+
17
+ def __setobj__(obj)
18
+ @document = obj
19
+ end
20
+
21
+ attr_reader :document
22
+
23
+ def initialize(document)
24
+ super
25
+ @document = document
26
+ end
27
+
28
+ def id
29
+ document[ActiveFedora.id_field]
30
+ end
31
+
32
+ def rdf_uri
33
+ ::RDF::URI.new(ActiveFedora::Base.id_to_uri(id))
34
+ end
35
+
36
+ def model(opts = {})
37
+ best_model_match = classifier.best_model(opts)
38
+ ActiveFedora::Base.logger.warn "Could not find a model for #{id}, defaulting to ActiveFedora::Base" if ActiveFedora::Base.logger && best_model_match == ActiveFedora::Base
39
+ best_model_match
40
+ end
41
+
42
+ def model?(model_to_check)
43
+ models.any? do |model|
44
+ model_to_check >= model
45
+ end
46
+ end
47
+
48
+ def instantiate_with_json
49
+ model.allocate.init_with_json(profile_json) do |allocated_object|
50
+ create_key = allocated_object.indexing_service.class.create_time_solr_name
51
+ modified_key = allocated_object.indexing_service.class.modified_time_solr_name
52
+ allocated_object.resource.set_value(:create_date, DateTime.parse(document[create_key])) if document[create_key]
53
+ allocated_object.resource.set_value(:modified_date, DateTime.parse(document[modified_key])) if document[modified_key]
54
+ end
55
+ end
56
+
57
+ def reify(opts = {})
58
+ model(opts).find(id, cast: true)
59
+ end
60
+
61
+ private
62
+
63
+ def classifier
64
+ ActiveFedora.model_mapper.classifier(document)
65
+ end
66
+
67
+ def profile_json
68
+ Array(document[ActiveFedora::IndexingService.profile_solr_name]).first
69
+ end
70
+ end
71
+ end
@@ -12,13 +12,12 @@ module ActiveFedora
12
12
  def initialize(context, id, solr_doc = nil)
13
13
  @context = context
14
14
  @id = id
15
- @solr_doc = solr_doc
16
- validate_solr_doc_and_id!(@solr_doc)
15
+ self.solr_doc = solr_doc
17
16
  end
18
17
 
19
18
  def object
20
19
  return @object if @object
21
- @object = allocate_object
20
+ @object = solr_doc.instantiate_with_json
22
21
  @object.readonly!
23
22
  @object.freeze
24
23
  @object
@@ -26,46 +25,23 @@ module ActiveFedora
26
25
 
27
26
  private
28
27
 
29
- def allocate_object
30
- active_fedora_class.allocate.init_with_json(profile_json) do |allocated_object|
31
- create_key = allocated_object.indexing_service.class.create_time_solr_name
32
- modified_key = allocated_object.indexing_service.class.modified_time_solr_name
33
- allocated_object.resource.set_value(:create_date, DateTime.parse(solr_doc[create_key])) if solr_doc[create_key]
34
- allocated_object.resource.set_value(:modified_date, DateTime.parse(solr_doc[modified_key])) if solr_doc[modified_key]
35
- end
36
- end
37
-
38
28
  def solr_doc
39
29
  @solr_doc ||= begin
40
- result = context.find_with_conditions(id: id)
41
- if result.empty?
42
- raise ActiveFedora::ObjectNotFoundError, "Object #{id} not found in solr"
43
- end
44
- @solr_doc = result.first
45
- validate_solr_doc_and_id!(@solr_doc)
46
- @solr_doc
30
+ self.solr_doc = context.search_by_id(id)
47
31
  end
48
32
  end
49
33
 
50
- def validate_solr_doc_and_id!(document)
51
- return true if document.nil?
52
- solr_id = document[SOLR_DOCUMENT_ID]
53
- return if id == solr_id
54
- raise ActiveFedora::FedoraSolrMismatchError, id, solr_id
55
- end
56
-
57
- def active_fedora_class
58
- @active_fedora_class ||= ActiveFedora::QueryResultBuilder.class_from_solr_document(solr_doc)
34
+ def solr_doc=(solr_doc)
35
+ unless solr_doc.nil?
36
+ solr_doc = ActiveFedora::SolrHit.for(solr_doc)
37
+ validate_solr_doc_and_id!(solr_doc)
38
+ @solr_doc = solr_doc
39
+ end
59
40
  end
60
41
 
61
- def profile_json
62
- @profile_json ||= begin
63
- profile_json = Array(solr_doc[ActiveFedora::IndexingService.profile_solr_name]).first
64
- unless profile_json.present?
65
- raise ActiveFedora::ObjectNotFoundError, "Object #{id} does not contain a solrized profile"
66
- end
67
- profile_json
68
- end
42
+ def validate_solr_doc_and_id!(document)
43
+ return if id == document.id
44
+ raise ActiveFedora::FedoraSolrMismatchError, id, document.id
69
45
  end
70
46
  end
71
47
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveFedora
2
2
  module SolrQueryBuilder
3
- PARSED_SUFFIX = '_tesim'.freeze
3
+ extend Deprecation
4
4
 
5
5
  class << self
6
6
  # Construct a solr query for a list of ids
@@ -10,18 +10,21 @@ module ActiveFedora
10
10
  def construct_query_for_ids(id_array)
11
11
  ids = id_array.reject(&:blank?)
12
12
  return "id:NEVER_USE_THIS_ID" if ids.empty?
13
- "{!terms f=#{SOLR_DOCUMENT_ID}}#{ids.join(',')}"
13
+ "{!terms f=#{ActiveFedora.id_field}}#{ids.join(',')}"
14
14
  end
15
15
 
16
16
  # Create a raw query clause suitable for sending to solr as an fq element
17
17
  # @param [String] key
18
18
  # @param [String] value
19
19
  def raw_query(key, value)
20
+ Deprecation.warn(ActiveFedora::SolrQueryBuilder, 'ActiveFedora::SolrQueryBuilder.raw_query is deprecated and will be removed in ActiveFedora 10.0. Use .construct_query instead.')
20
21
  "_query_:\"{!raw f=#{key}}#{value.gsub('"', '\"')}\""
21
22
  end
22
23
 
24
+ # @deprecated
23
25
  def solr_name(*args)
24
- Solrizer.default_field_mapper.solr_name(*args)
26
+ Deprecation.warn(ActiveFedora::SolrQueryBuilder, 'ActiveFedora::SolrQueryBuilder.solr_name is deprecated and will be removed in ActiveFedora 10.0. Use ActiveFedora.index_field_mapper.solr_name instead.')
27
+ ActiveFedora.index_field_mapper.solr_name(*args)
25
28
  end
26
29
 
27
30
  # Create a query with a clause for each key, value
@@ -29,9 +32,9 @@ module ActiveFedora
29
32
  # @param [String] join_with ('AND') the value we're joining the clauses with
30
33
  # @example
31
34
  # construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
32
- # # => _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
35
+ # # => _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
33
36
  #
34
- # construct_query_for_rel [[Book.reflect_on_association(:library), "foo/bar/baz"]]
37
+ # construct_query_for_rel [[Book._reflect_on_association(:library), "foo/bar/baz"]]
35
38
  def construct_query_for_rel(field_pairs, join_with = ' AND ')
36
39
  field_pairs = field_pairs.to_a if field_pairs.is_a? Hash
37
40
  construct_query(property_values_to_solr(field_pairs), join_with)
@@ -43,7 +46,7 @@ module ActiveFedora
43
46
  # @return [String] a solr query
44
47
  # @example
45
48
  # construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
46
- # # => "_query_:\"{!raw f=library_id_ssim}123\" AND _query_:\"{!raw f=owner_ssim}Fred\""
49
+ # # => "_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\""
47
50
  def construct_query(field_pairs, join_with = ' AND ')
48
51
  pairs_to_clauses(field_pairs).join(join_with)
49
52
  end
@@ -66,12 +69,7 @@ module ActiveFedora
66
69
  values << nil if values.empty?
67
70
  values.map do |value|
68
71
  if value.present?
69
- if parsed?(field)
70
- # If you do a raw query on a parsed field you won't get the matches you expect.
71
- "#{field}:#{solr_escape(value)}"
72
- else
73
- raw_query(field, value)
74
- end
72
+ field_query(field, value)
75
73
  else
76
74
  # Check that the field is not present. In SQL: "WHERE field IS NULL"
77
75
  "-#{field}:[* TO *]"
@@ -79,16 +77,6 @@ module ActiveFedora
79
77
  end
80
78
  end
81
79
 
82
- def parsed?(field)
83
- field.end_with?(PARSED_SUFFIX)
84
- end
85
-
86
- # Adds esaping for spaces which are not handled by RSolr.solr_escape
87
- # See rsolr/rsolr#101
88
- def solr_escape(terms)
89
- RSolr.solr_escape(terms).gsub(/\s+/, "\\ ")
90
- end
91
-
92
80
  # Given a list of pairs (e.g. [field name, values]), convert the field names
93
81
  # to solr names
94
82
  # @param [Array<Array>] pairs a list of pairs of property name and values
@@ -97,8 +85,8 @@ module ActiveFedora
97
85
  # property_values_to_solr([['library_id', '123'], ['owner', 'Fred']])
98
86
  # # => [['library_id_ssim', '123'], ['owner_ssim', 'Fred']]
99
87
  def property_values_to_solr(pairs)
100
- pairs.each_with_object([]) do |(property, value), list|
101
- list << [solr_field(property), value]
88
+ pairs.map do |(property, value)|
89
+ [solr_field(property), value]
102
90
  end
103
91
  end
104
92
 
@@ -109,9 +97,16 @@ module ActiveFedora
109
97
  when ActiveFedora::Reflection::AssociationReflection
110
98
  field.solr_key
111
99
  else
112
- solr_name(field, :symbol)
100
+ ActiveFedora.index_field_mapper.solr_name(field, :symbol)
113
101
  end
114
102
  end
103
+
104
+ # Create a raw query clause suitable for sending to solr as an fq element
105
+ # @param [String] key
106
+ # @param [String] value
107
+ def field_query(key, value)
108
+ "_query_:\"{!field f=#{key}}#{value.gsub('"', '\"')}\""
109
+ end
115
110
  end
116
111
  end
117
112
  end
@@ -49,19 +49,19 @@ module ActiveFedora
49
49
  end
50
50
 
51
51
  def reify_solr_result(hit, opts = {})
52
- Deprecation.warn SolrService, "SolrService.reify_solr_result is deprecated. Use QueryResultBuilder.reify_solr_result instead. This will be removed in active-fedora 10.0"
52
+ Deprecation.warn SolrService, "SolrService.reify_solr_result is deprecated. Use SolrHit#reify instead. This will be removed in active-fedora 10.0"
53
53
  QueryResultBuilder.reify_solr_result(hit, opts)
54
54
  end
55
55
 
56
56
  # Returns all possible classes for the solr object
57
57
  def classes_from_solr_document(hit, opts = {})
58
- Deprecation.warn SolrService, "SolrService.classes_from_solr_document is deprecated. Use QueryResultBuilder.classes_from_solr_document instead. This will be removed in active-fedora 10.0"
58
+ Deprecation.warn SolrService, "SolrService.classes_from_solr_document is deprecated. Use SolrHit#models instead. This will be removed in active-fedora 10.0"
59
59
  QueryResultBuilder.classes_from_solr_document(hit, opts)
60
60
  end
61
61
 
62
62
  # Returns the best singular class for the solr object
63
63
  def class_from_solr_document(hit, opts = {})
64
- Deprecation.warn SolrService, "SolrService.class_from_solr_document is deprecated. Use QueryResultBuilder.class_from_solr_document instead. This will be removed in active-fedora 10.0"
64
+ Deprecation.warn SolrService, "SolrService.class_from_solr_document is deprecated. Use SolrHit#model instead. This will be removed in active-fedora 10.0"
65
65
  QueryResultBuilder.class_from_solr_document(hit, opts)
66
66
  end
67
67
 
@@ -83,8 +83,8 @@ module ActiveFedora
83
83
  # @param [String] key
84
84
  # @param [String] value
85
85
  def raw_query(key, value)
86
- Deprecation.warn SolrService, "SolrService.raw_query is deprecated. Use SolrQueryBuilder.raw_query instead. This will be removed in active-fedora 10.0"
87
- SolrQueryBuilder.raw_query(key, value)
86
+ Deprecation.warn SolrService, "SolrService.raw_query is deprecated. Use SolrQueryBuilder.construct_query instead. This will be removed in active-fedora 10.0"
87
+ SolrQueryBuilder.construct_query(key, value)
88
88
  end
89
89
 
90
90
  def solr_name(*args)
@@ -97,20 +97,31 @@ module ActiveFedora
97
97
  # @param [String] join_with ('AND') the value we're joining the clauses with
98
98
  # @example
99
99
  # construct_query_for_rel [[:has_model, "info:fedora/afmodel:ComplexCollection"], [:has_model, "info:fedora/afmodel:ActiveFedora_Base"]], 'OR'
100
- # # => _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!raw f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
100
+ # # => _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ComplexCollection" OR _query_:"{!field f=has_model_ssim}info:fedora/afmodel:ActiveFedora_Base"
101
101
  #
102
- # construct_query_for_rel [[Book.reflect_on_association(:library), "foo/bar/baz"]]
102
+ # construct_query_for_rel [[Book._reflect_on_association(:library), "foo/bar/baz"]]
103
103
  def construct_query_for_rel(field_pairs, join_with = 'AND')
104
104
  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"
105
105
  SolrQueryBuilder.construct_query_for_rel(field_pairs, join_with)
106
106
  end
107
107
 
108
+ def get(query, args = {})
109
+ args = args.merge(q: query, qt: 'standard')
110
+ SolrService.instance.conn.get(select_path, params: args)
111
+ end
112
+
108
113
  def query(query, args = {})
109
114
  raw = args.delete(:raw)
110
- args = args.merge(q: query, qt: 'standard')
111
- result = SolrService.instance.conn.get(select_path, params: args)
112
- return result if raw
113
- result['response']['docs']
115
+ result = get(query, args)
116
+
117
+ if raw
118
+ Deprecation.warn SolrService, "SolrService.query with raw: true is deprecated. Use SolrService.get instead. This will be removed in active-fedora 10.0"
119
+ return result
120
+ end
121
+
122
+ result['response']['docs'].map do |doc|
123
+ ActiveFedora::SolrHit.new(doc)
124
+ end
114
125
  end
115
126
 
116
127
  def delete(id)
@@ -122,8 +133,8 @@ module ActiveFedora
122
133
  # @param [Hash] args arguments to pass through to `args' param of SolrService.query (note that :rows will be overwritten to 0)
123
134
  # @return [Integer] number of records matching
124
135
  def count(query, args = {})
125
- args = args.merge(raw: true, rows: 0)
126
- SolrService.query(query, args)['response']['numFound'].to_i
136
+ args = args.merge(rows: 0)
137
+ SolrService.get(query, args)['response']['numFound'].to_i
127
138
  end
128
139
 
129
140
  # @param [Hash] doc the document to index
@@ -0,0 +1,8 @@
1
+
2
+ require 'active_fedora/type/value'
3
+ require 'active_fedora/type/boolean'
4
+
5
+ module ActiveFedora
6
+ module Type
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # DO NOT EDIT THIS FILE
2
+ # Plucked from ActiveModel::Type::Boolean in Rails 5
3
+ module ActiveFedora
4
+ module Type
5
+ class Boolean < Value # :nodoc:
6
+ FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
7
+
8
+ def type
9
+ :boolean
10
+ end
11
+
12
+ private
13
+
14
+ def cast_value(value)
15
+ if value == ''
16
+ nil
17
+ else
18
+ !FALSE_VALUES.include?(value)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,118 @@
1
+ # DO NOT EDIT THIS FILE
2
+ # Plucked from ActiveModel::Type::Boolean in Rails 5
3
+ module ActiveFedora
4
+ module Type
5
+ class Value
6
+ attr_reader :precision, :scale, :limit
7
+
8
+ def initialize(precision: nil, limit: nil, scale: nil)
9
+ @precision = precision
10
+ @scale = scale
11
+ @limit = limit
12
+ end
13
+
14
+ def type # :nodoc:
15
+ end
16
+
17
+ # Converts a value from database input to the appropriate ruby type. The
18
+ # return value of this method will be returned from
19
+ # ActiveRecord::AttributeMethods::Read#read_attribute. The default
20
+ # implementation just calls Value#cast.
21
+ #
22
+ # +value+ The raw input, as provided from the database.
23
+ def deserialize(value)
24
+ cast(value)
25
+ end
26
+
27
+ # Type casts a value from user input (e.g. from a setter). This value may
28
+ # be a string from the form builder, or a ruby object passed to a setter.
29
+ # There is currently no way to differentiate between which source it came
30
+ # from.
31
+ #
32
+ # The return value of this method will be returned from
33
+ # ActiveRecord::AttributeMethods::Read#read_attribute. See also:
34
+ # Value#cast_value.
35
+ #
36
+ # +value+ The raw input, as provided to the attribute setter.
37
+ def cast(value)
38
+ cast_value(value) unless value.nil?
39
+ end
40
+
41
+ # Casts a value from the ruby type to a type that the database knows how
42
+ # to understand. The returned value from this method should be a
43
+ # +String+, +Numeric+, +Date+, +Time+, +Symbol+, +true+, +false+, or
44
+ # +nil+.
45
+ def serialize(value)
46
+ value
47
+ end
48
+
49
+ # Type casts a value for schema dumping. This method is private, as we are
50
+ # hoping to remove it entirely.
51
+ def type_cast_for_schema(value) # :nodoc:
52
+ value.inspect
53
+ end
54
+
55
+ # These predicates are not documented, as I need to look further into
56
+ # their use, and see if they can be removed entirely.
57
+ def binary? # :nodoc:
58
+ false
59
+ end
60
+
61
+ # Determines whether a value has changed for dirty checking. +old_value+
62
+ # and +new_value+ will always be type-cast. Types should not need to
63
+ # override this method.
64
+ def changed?(old_value, new_value, _new_value_before_type_cast)
65
+ old_value != new_value
66
+ end
67
+
68
+ # Determines whether the mutable value has been modified since it was
69
+ # read. Returns +false+ by default. If your type returns an object
70
+ # which could be mutated, you should override this method. You will need
71
+ # to either:
72
+ #
73
+ # - pass +new_value+ to Value#serialize and compare it to
74
+ # +raw_old_value+
75
+ #
76
+ # or
77
+ #
78
+ # - pass +raw_old_value+ to Value#deserialize and compare it to
79
+ # +new_value+
80
+ #
81
+ # +raw_old_value+ The original value, before being passed to
82
+ # +deserialize+.
83
+ #
84
+ # +new_value+ The current value, after type casting.
85
+ def changed_in_place?(_raw_old_value, _new_value)
86
+ false
87
+ end
88
+
89
+ def map(value) # :nodoc:
90
+ yield value
91
+ end
92
+
93
+ def ==(other)
94
+ self.class == other.class &&
95
+ precision == other.precision &&
96
+ scale == other.scale &&
97
+ limit == other.limit
98
+ end
99
+ alias eql? ==
100
+
101
+ def hash
102
+ [self.class, precision, scale, limit].hash
103
+ end
104
+
105
+ def assert_valid_value(*)
106
+ end
107
+
108
+ private
109
+
110
+ # Convenience method for types which do not need separate type casting
111
+ # behavior for user and database inputs. Called by Value#cast for
112
+ # values except +nil+.
113
+ def cast_value(value) # :doc:
114
+ value
115
+ end
116
+ end
117
+ end
118
+ end