ddr-models 2.11.0 → 3.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +7 -6
- data/Gemfile +2 -3
- data/Rakefile +5 -5
- data/app/controllers/users/sessions_controller.rb +5 -0
- data/app/helpers/models_helper.rb +7 -0
- data/app/models/attachment.rb +3 -5
- data/app/models/collection.rb +12 -79
- data/app/models/component.rb +8 -67
- data/app/models/item.rb +8 -73
- data/app/models/target.rb +6 -5
- data/config/initializers/active_fedora_base.rb +11 -30
- data/config/initializers/{active_fedora_datastream.rb → active_fedora_file.rb} +1 -1
- data/config/initializers/devise.rb +2 -3
- data/config/initializers/subscriptions.rb +2 -19
- data/ddr-models.gemspec +10 -14
- data/lib/ddr/actions/fixity_check.rb +1 -1
- data/lib/ddr/actions/virus_check.rb +17 -10
- data/lib/ddr/auth.rb +6 -38
- data/lib/ddr/auth/ability.rb +1 -5
- data/lib/ddr/auth/ability_definitions/collection_ability_definitions.rb +0 -16
- data/lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb +10 -4
- data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +16 -9
- data/lib/ddr/auth/ability_factory.rb +25 -2
- data/lib/ddr/auth/abstract_ability.rb +1 -2
- data/lib/ddr/auth/auth_context.rb +0 -18
- data/lib/ddr/auth/auth_context_factory.rb +2 -0
- data/lib/ddr/auth/group.rb +0 -6
- data/lib/ddr/auth/grouper_gateway.rb +0 -24
- data/lib/ddr/auth/permissions.rb +1 -12
- data/lib/ddr/auth/role_based_access_controls_enforcement.rb +5 -5
- data/lib/ddr/auth/roles.rb +1 -11
- data/lib/ddr/auth/roles/role_set.rb +0 -7
- data/lib/ddr/auth/roles/roles_datastream.rb +9 -0
- data/lib/ddr/contacts.rb +25 -0
- data/lib/ddr/datastreams.rb +10 -28
- data/lib/ddr/datastreams/datastream_behavior.rb +30 -100
- data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +28 -31
- data/lib/ddr/datastreams/fits_datastream.rb +9 -22
- data/lib/ddr/datastreams/metadata_datastream.rb +17 -31
- data/lib/ddr/derivatives.rb +13 -16
- data/lib/ddr/derivatives/derivative.rb +68 -0
- data/lib/ddr/derivatives/{generator.rb → generators/generator.rb} +11 -7
- data/lib/ddr/derivatives/generators/png_generator.rb +23 -0
- data/lib/ddr/derivatives/generators/ptif_generator.rb +56 -0
- data/lib/ddr/derivatives/multires_image.rb +59 -0
- data/lib/ddr/derivatives/thumbnail.rb +36 -0
- data/lib/ddr/events.rb +0 -1
- data/lib/ddr/events/deletion_event.rb +9 -5
- data/lib/ddr/events/event.rb +8 -13
- data/lib/ddr/events/fixity_check_event.rb +0 -6
- data/lib/ddr/events/ingestion_event.rb +9 -5
- data/lib/ddr/events/update_event.rb +4 -17
- data/lib/ddr/index.rb +4 -4
- data/lib/ddr/index/abstract_query_result.rb +4 -3
- data/lib/ddr/index/connection.rb +9 -28
- data/lib/ddr/index/csv_query_result.rb +32 -47
- data/lib/ddr/index/field.rb +1 -11
- data/lib/ddr/index/fields.rb +16 -99
- data/lib/ddr/index/filter.rb +30 -103
- data/lib/ddr/index/filters.rb +19 -0
- data/lib/ddr/index/query.rb +11 -58
- data/lib/ddr/index/query_builder.rb +36 -147
- data/lib/ddr/index/query_clause.rb +19 -79
- data/lib/ddr/index/query_result.rb +4 -36
- data/lib/ddr/index/query_value.rb +18 -0
- data/lib/ddr/index/response.rb +2 -19
- data/lib/ddr/jobs.rb +12 -0
- data/lib/ddr/jobs/fits_file_characterization.rb +51 -0
- data/lib/ddr/jobs/permanent_id.rb +23 -0
- data/lib/ddr/managers.rb +1 -0
- data/lib/ddr/managers/derivatives_manager.rb +53 -93
- data/lib/ddr/managers/permanent_id_manager.rb +91 -0
- data/lib/ddr/managers/technical_metadata_manager.rb +10 -24
- data/lib/ddr/managers/workflow_manager.rb +10 -29
- data/lib/ddr/models.rb +50 -101
- data/lib/ddr/models/access_controllable.rb +12 -0
- data/lib/ddr/models/admin_set.rb +5 -16
- data/lib/ddr/models/base.rb +45 -165
- data/lib/ddr/models/describable.rb +19 -21
- data/lib/ddr/models/engine.rb +11 -39
- data/lib/ddr/models/error.rb +0 -3
- data/lib/ddr/models/file_management.rb +36 -72
- data/lib/ddr/models/finding_aid.rb +2 -35
- data/lib/ddr/models/fixity_checkable.rb +4 -0
- data/lib/ddr/models/governable.rb +3 -1
- data/lib/ddr/models/has_admin_metadata.rb +82 -56
- data/lib/ddr/models/has_attachments.rb +3 -1
- data/lib/ddr/models/has_children.rb +3 -7
- data/lib/ddr/models/has_content.rb +35 -32
- data/lib/ddr/models/has_multires_image.rb +7 -12
- data/lib/ddr/models/has_struct_metadata.rb +44 -6
- data/lib/ddr/models/has_thumbnail.rb +1 -4
- data/lib/ddr/models/indexing.rb +97 -186
- data/lib/ddr/models/licenses/admin_policy_license.rb +11 -0
- data/lib/ddr/models/licenses/effective_license.rb +9 -0
- data/lib/ddr/models/licenses/inherited_license.rb +9 -0
- data/lib/ddr/models/licenses/license.rb +21 -0
- data/lib/ddr/models/licenses/parent_license.rb +11 -0
- data/lib/ddr/models/metadata/descriptive_metadata.rb +50 -0
- data/lib/ddr/models/metadata/metadata.rb +37 -0
- data/lib/ddr/models/metadata/metadata_mapper.rb +32 -0
- data/lib/ddr/models/metadata/metadata_mappers.rb +18 -0
- data/lib/ddr/models/metadata/metadata_term.rb +24 -0
- data/lib/ddr/models/metadata/metadata_vocabularies.rb +18 -0
- data/lib/ddr/models/metadata/metadata_vocabulary.rb +34 -0
- data/lib/ddr/models/solr_document.rb +24 -156
- data/lib/ddr/models/struct_div.rb +63 -0
- data/lib/ddr/models/structure.rb +39 -175
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/models/year_facet.rb +118 -60
- data/lib/ddr/notifications.rb +12 -10
- data/lib/ddr/utils.rb +15 -28
- data/lib/ddr/vocab.rb +17 -15
- data/lib/ddr/vocab/asset.rb +17 -42
- data/lib/ddr/vocab/contact.rb +7 -5
- data/lib/ddr/vocab/display.rb +8 -6
- data/lib/ddr/vocab/duke_terms.rb +10 -8
- data/lib/ddr/vocab/rdf_vocabulary_parser.rb +39 -37
- data/lib/ddr/vocab/roles.rb +19 -17
- data/lib/ddr/vocab/sources/duketerms.rdf +8 -22
- data/lib/ddr/vocab/vocabulary.rb +26 -26
- data/spec/auth/ability_factory_spec.rb +1 -18
- data/spec/auth/ability_spec.rb +15 -119
- data/spec/auth/effective_permissions_spec.rb +1 -1
- data/spec/auth/effective_roles_spec.rb +1 -1
- data/spec/auth/ldap_gateway_spec.rb +9 -0
- data/spec/contacts/contacts_spec.rb +26 -0
- data/spec/controllers/including_role_based_access_controls_enforcement_spec.rb +5 -5
- data/spec/derivatives/multires_image_spec.rb +48 -0
- data/spec/derivatives/png_generator_spec.rb +8 -13
- data/spec/derivatives/ptif_generator_spec.rb +11 -9
- data/spec/derivatives/thumbnail_spec.rb +48 -0
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/schema.rb +23 -25
- data/spec/factories/attachment_factories.rb +2 -2
- data/spec/factories/collection_factories.rb +2 -3
- data/spec/factories/component_factories.rb +2 -2
- data/spec/factories/item_factories.rb +2 -2
- data/spec/factories/structure_factories.rb +2 -8
- data/spec/factories/test_model_factories.rb +12 -4
- data/spec/fixtures/fits/document.xml +44 -42
- data/spec/fixtures/fits/image.xml +41 -42
- data/spec/helpers/models_helper_spec.rb +11 -0
- data/spec/index/filter_spec.rb +30 -208
- data/spec/index/filters_spec.rb +17 -0
- data/spec/index/query_spec.rb +10 -82
- data/spec/jobs/fits_file_characterization_spec.rb +52 -0
- data/spec/managers/derivatives_manager_spec.rb +105 -107
- data/spec/managers/technical_metadata_manager_spec.rb +27 -34
- data/spec/models/active_fedora_base_spec.rb +105 -5
- data/spec/models/active_fedora_datastream_spec.rb +39 -106
- data/spec/models/admin_set_spec.rb +10 -43
- data/spec/models/attachment_spec.rb +2 -3
- data/spec/models/collection_spec.rb +11 -225
- data/spec/models/component_spec.rb +4 -106
- data/spec/models/descriptive_metadata_spec.rb +38 -0
- data/spec/models/effective_license_spec.rb +64 -0
- data/spec/models/events_spec.rb +59 -52
- data/spec/models/file_management_spec.rb +13 -113
- data/spec/models/finding_aid_spec.rb +8 -31
- data/spec/models/has_admin_metadata_spec.rb +122 -131
- data/spec/models/has_children_spec.rb +3 -3
- data/spec/models/has_struct_metadata_spec.rb +37 -50
- data/spec/models/indexing_spec.rb +23 -160
- data/spec/models/item_spec.rb +2 -133
- data/spec/models/license_spec.rb +24 -0
- data/spec/models/solr_document_spec.rb +47 -236
- data/spec/models/struct_div_spec.rb +70 -0
- data/spec/models/structure_spec.rb +11 -89
- data/spec/models/target_spec.rb +2 -4
- data/spec/models/year_facet_spec.rb +23 -50
- data/spec/spec_helper.rb +13 -17
- data/spec/support/ezid_mock_identifier.rb +2 -2
- data/spec/support/shared_examples_for_auth_contexts.rb +0 -33
- data/spec/support/shared_examples_for_ddr_models.rb +94 -142
- data/spec/support/shared_examples_for_describables.rb +36 -31
- data/spec/support/shared_examples_for_governables.rb +2 -3
- data/spec/support/shared_examples_for_has_content.rb +46 -101
- data/spec/support/shared_examples_for_indexing.rb +6 -6
- data/spec/support/shared_examples_for_non_collection_models.rb +1 -32
- data/spec/support/structural_metadata_helper.rb +59 -230
- data/spec/utils_spec.rb +2 -0
- metadata +96 -229
- data/.ruby-version +0 -1
- data/config/initializers/rsolr_monkey_patches.rb +0 -7
- data/config/initializers/rubydora_monkey_patch.rb +0 -11
- data/config/locales/ddr-models.en.yml +0 -81
- data/db/migrate/20161021201011_add_permanent_id_to_events.rb +0 -8
- data/lib/ddr/auth/ability_definitions/admin_set_ability_definitions.rb +0 -9
- data/lib/ddr/auth/ability_definitions/lock_ability_definitions.rb +0 -13
- data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +0 -16
- data/lib/ddr/datastreams/administrative_metadata_datastream.rb +0 -75
- data/lib/ddr/datastreams/caption_datastream.rb +0 -5
- data/lib/ddr/datastreams/content_datastream.rb +0 -17
- data/lib/ddr/datastreams/delete_external_files.rb +0 -29
- data/lib/ddr/datastreams/external_file_datastream.rb +0 -80
- data/lib/ddr/datastreams/intermediate_file_datastream.rb +0 -5
- data/lib/ddr/datastreams/multires_image_datastream.rb +0 -5
- data/lib/ddr/datastreams/streamable_media_datastream.rb +0 -5
- data/lib/ddr/derivatives/png_generator.rb +0 -17
- data/lib/ddr/derivatives/ptif_generator.rb +0 -55
- data/lib/ddr/derivatives/update_derivatives.rb +0 -25
- data/lib/ddr/events/deaccession_event.rb +0 -8
- data/lib/ddr/index/field_attribute.rb +0 -22
- data/lib/ddr/index/query_params.rb +0 -40
- data/lib/ddr/index/sort_order.rb +0 -28
- data/lib/ddr/models/cache.rb +0 -20
- data/lib/ddr/models/captionable.rb +0 -37
- data/lib/ddr/models/contact.rb +0 -23
- data/lib/ddr/models/file_characterization.rb +0 -37
- data/lib/ddr/models/has_intermediate_file.rb +0 -41
- data/lib/ddr/models/language.rb +0 -31
- data/lib/ddr/models/media_type.rb +0 -22
- data/lib/ddr/models/permanent_id.rb +0 -240
- data/lib/ddr/models/rights_statement.rb +0 -25
- data/lib/ddr/models/streamable.rb +0 -37
- data/lib/ddr/models/structures/agent.rb +0 -49
- data/lib/ddr/models/structures/component_type_term.rb +0 -29
- data/lib/ddr/models/structures/div.rb +0 -64
- data/lib/ddr/models/structures/f_locat.rb +0 -54
- data/lib/ddr/models/structures/file.rb +0 -52
- data/lib/ddr/models/structures/file_grp.rb +0 -35
- data/lib/ddr/models/structures/file_sec.rb +0 -22
- data/lib/ddr/models/structures/fptr.rb +0 -31
- data/lib/ddr/models/structures/mets_hdr.rb +0 -37
- data/lib/ddr/models/structures/mptr.rb +0 -49
- data/lib/ddr/models/structures/struct_map.rb +0 -40
- data/lib/ddr/models/with_content_file.rb +0 -37
- data/spec/datastreams/external_file_datastream_spec.rb +0 -48
- data/spec/dummy/config/structure_component_type.yml +0 -18
- data/spec/fixtures/abcd1234.vtt +0 -38
- data/spec/fixtures/arrow1rightred_e0.gif +0 -0
- data/spec/fixtures/extractedText1.txt +0 -1
- data/spec/fixtures/extractedText2.txt +0 -1
- data/spec/fixtures/extractedText3.txt +0 -3
- data/spec/fixtures/imageA.jpg +0 -0
- data/spec/fixtures/imageB.jpg +0 -0
- data/spec/index/csv_query_result_spec.rb +0 -44
- data/spec/index/fields_spec.rb +0 -380
- data/spec/index/query_builder_spec.rb +0 -140
- data/spec/index/query_clause_spec.rb +0 -68
- data/spec/models/cache_spec.rb +0 -32
- data/spec/models/contact_spec.rb +0 -56
- data/spec/models/descriptive_metadata_datastream_spec.rb +0 -139
- data/spec/models/file_characterization_spec.rb +0 -39
- data/spec/models/language_spec.rb +0 -59
- data/spec/models/media_type_spec.rb +0 -46
- data/spec/models/permanent_id_spec.rb +0 -432
- data/spec/models/rights_statement_spec.rb +0 -55
- data/spec/models/structures/agent_spec.rb +0 -30
- data/spec/models/structures/component_type_term_spec.rb +0 -14
- data/spec/models/structures/div_spec.rb +0 -26
- data/spec/models/structures/f_locat_spec.rb +0 -78
- data/spec/models/structures/file_grp_spec.rb +0 -23
- data/spec/models/structures/file_sec_spec.rb +0 -22
- data/spec/models/structures/file_spec.rb +0 -60
- data/spec/models/structures/fptr_spec.rb +0 -23
- data/spec/models/structures/mets_hdr_spec.rb +0 -26
- data/spec/models/structures/mptr_spec.rb +0 -25
- data/spec/models/structures/struct_map_spec.rb +0 -24
- data/spec/models/with_content_file_spec.rb +0 -37
- data/spec/support/shared_examples_for_associations.rb +0 -8
- data/spec/support/shared_examples_for_captionable.rb +0 -23
- data/spec/support/shared_examples_for_has_intermediate_file.rb +0 -28
- data/spec/support/shared_examples_for_publication.rb +0 -43
- data/spec/support/shared_examples_for_streamable_media.rb +0 -23
data/lib/ddr/index/filter.rb
CHANGED
@@ -1,121 +1,48 @@
|
|
1
|
-
require "forwardable"
|
2
|
-
require "virtus"
|
3
|
-
|
4
1
|
module Ddr::Index
|
5
2
|
class Filter
|
6
|
-
include Virtus.model
|
7
|
-
|
8
|
-
attribute :clauses, Array, default: [ ]
|
9
3
|
|
10
|
-
|
11
|
-
|
4
|
+
class << self
|
5
|
+
delegate :where, :raw, :before_days, :before, :present, :absent, to: :new
|
12
6
|
end
|
13
7
|
|
14
|
-
|
15
|
-
def raw(*clauses)
|
16
|
-
self.clauses += clauses
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
def term(conditions)
|
21
|
-
self.clauses += conditions.map { |f, v| QueryClause.term(f, v) }
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def where(conditions)
|
26
|
-
self.clauses += conditions.map { |f, v| QueryClause.where(f, v) }
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def where_not(conditions)
|
31
|
-
self.clauses += conditions.map do |field, v|
|
32
|
-
Array(v).map { |value| QueryClause.negative(field, value) }
|
33
|
-
end.flatten
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
def absent(field)
|
38
|
-
self.clauses << QueryClause.absent(field)
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def present(field)
|
43
|
-
self.clauses << QueryClause.present(field)
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
def negative(field, value)
|
48
|
-
self.clauses << QueryClause.negative(field, value)
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
|
-
def before(field, value)
|
53
|
-
self.clauses << QueryClause.before(field, value)
|
54
|
-
self
|
55
|
-
end
|
8
|
+
attr_accessor :clauses
|
56
9
|
|
57
|
-
|
58
|
-
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
def join(**args)
|
63
|
-
self.clauses << QueryClause.join(**args)
|
64
|
-
self
|
65
|
-
end
|
66
|
-
|
67
|
-
def regexp(field, value)
|
68
|
-
self.clauses << QueryClause.regexp(field, value)
|
69
|
-
self
|
70
|
-
end
|
10
|
+
def initialize
|
11
|
+
@clauses = [ ]
|
71
12
|
end
|
72
13
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
def has_content
|
79
|
-
model "Component", "Attachment", "Target"
|
80
|
-
end
|
81
|
-
|
82
|
-
def is_governed_by(arg)
|
83
|
-
term is_governed_by: get_uri(arg)
|
84
|
-
end
|
85
|
-
|
86
|
-
def is_member_of_collection(arg)
|
87
|
-
term is_member_of_collection: get_uri(arg)
|
88
|
-
end
|
89
|
-
|
90
|
-
def is_part_of(arg)
|
91
|
-
term is_part_of: get_uri(arg)
|
92
|
-
end
|
93
|
-
|
94
|
-
def model(*models)
|
95
|
-
where active_fedora_model: models
|
96
|
-
end
|
97
|
-
|
98
|
-
private
|
99
|
-
|
100
|
-
def get_uri(arg)
|
101
|
-
case arg
|
102
|
-
when ActiveFedora::Base
|
103
|
-
arg.internal_uri
|
104
|
-
when String
|
105
|
-
arg.start_with?("info:fedora/") ? arg : "info:fedora/#{arg}"
|
14
|
+
def where(conditions)
|
15
|
+
clauses = conditions.map do |field, value|
|
16
|
+
if value.respond_to?(:each)
|
17
|
+
QueryClause.or_values(field, *value)
|
106
18
|
else
|
107
|
-
|
19
|
+
QueryClause.term(field, value)
|
108
20
|
end
|
109
21
|
end
|
22
|
+
raw *clauses
|
23
|
+
end
|
110
24
|
|
111
|
-
|
112
|
-
|
113
|
-
|
25
|
+
# Adds clause (String) w/o escaping
|
26
|
+
def raw(*clauses)
|
27
|
+
self.clauses += clauses
|
28
|
+
self
|
29
|
+
end
|
114
30
|
|
31
|
+
def present(field)
|
32
|
+
raw QueryClause.present(field)
|
115
33
|
end
|
116
34
|
|
117
|
-
|
118
|
-
|
35
|
+
def absent(field)
|
36
|
+
raw QueryClause.absent(field)
|
37
|
+
end
|
38
|
+
|
39
|
+
def before(field, date_time)
|
40
|
+
raw QueryClause.before(field, date_time)
|
41
|
+
end
|
42
|
+
|
43
|
+
def before_days(field, days)
|
44
|
+
raw QueryClause.before_days(field, days)
|
45
|
+
end
|
119
46
|
|
120
47
|
end
|
121
48
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Ddr::Index
|
2
|
+
module Filters
|
3
|
+
|
4
|
+
HAS_CONTENT = Filter.where(Fields::ACTIVE_FEDORA_MODEL => ["Component", "Attachment", "Target"])
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def is_governed_by(pid)
|
8
|
+
Filter.where(Fields::IS_GOVERNED_BY => pid)
|
9
|
+
end
|
10
|
+
|
11
|
+
def internal_uri(pid)
|
12
|
+
ActiveFedora::Base.internal_uri(pid)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private_class_method :internal_uri
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/ddr/index/query.rb
CHANGED
@@ -1,33 +1,9 @@
|
|
1
|
-
require "virtus"
|
2
|
-
require "forwardable"
|
3
|
-
|
4
1
|
module Ddr::Index
|
5
2
|
class Query
|
6
|
-
include Virtus.model
|
7
|
-
extend Forwardable
|
8
|
-
extend Deprecation
|
9
|
-
|
10
|
-
attribute :q, String
|
11
|
-
attribute :fields, Array[FieldAttribute], default: [ ]
|
12
|
-
attribute :filters, Array[Filter], default: [ ]
|
13
|
-
attribute :sort, Array[String], default: [ ]
|
14
|
-
attribute :rows, Integer
|
15
3
|
|
16
|
-
|
17
|
-
delegate :params => :query_params
|
18
|
-
|
19
|
-
def self.build(*args, &block)
|
20
|
-
new.tap do |query|
|
21
|
-
query.build(*args, &block)
|
22
|
-
end
|
23
|
-
end
|
4
|
+
attr_reader :q, :fields, :filters, :sort, :rows
|
24
5
|
|
25
|
-
|
26
|
-
super(**args)
|
27
|
-
if block_given?
|
28
|
-
build(&block)
|
29
|
-
end
|
30
|
-
end
|
6
|
+
delegate :count, :docs, :pids, :each_pid, :all, to: :result
|
31
7
|
|
32
8
|
def inspect
|
33
9
|
"#<#{self.class.name} q=#{q.inspect}, filters=#{filters.inspect}," \
|
@@ -38,44 +14,21 @@ module Ddr::Index
|
|
38
14
|
URI.encode_www_form(params)
|
39
15
|
end
|
40
16
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
each_id(&block)
|
17
|
+
def params
|
18
|
+
{ q: q,
|
19
|
+
fq: filters.map(&:clauses).flatten,
|
20
|
+
fl: fields.join(","),
|
21
|
+
sort: sort.join(","),
|
22
|
+
rows: rows,
|
23
|
+
}.select { |k, v| v.present? }
|
49
24
|
end
|
50
25
|
|
51
26
|
def result
|
52
27
|
QueryResult.new(self)
|
53
28
|
end
|
54
29
|
|
55
|
-
def csv
|
56
|
-
CSVQueryResult.new(self)
|
57
|
-
end
|
58
|
-
|
59
|
-
def filter_clauses
|
60
|
-
filters.map(&:clauses).flatten
|
61
|
-
end
|
62
|
-
|
63
|
-
def query_params
|
64
|
-
QueryParams.new(self)
|
65
|
-
end
|
66
|
-
|
67
|
-
def build(*args, &block)
|
68
|
-
QueryBuilder.new(self, *args, &block)
|
69
|
-
self
|
70
|
-
end
|
71
|
-
|
72
|
-
def ==(other)
|
73
|
-
other.instance_of?(self.class) &&
|
74
|
-
other.q == self.q &&
|
75
|
-
other.fields == self.fields &&
|
76
|
-
other.filters == self.filters &&
|
77
|
-
other.rows == self.rows &&
|
78
|
-
other.sort == self.sort
|
30
|
+
def csv(**opts)
|
31
|
+
CSVQueryResult.new(self, **opts)
|
79
32
|
end
|
80
33
|
|
81
34
|
end
|
@@ -1,184 +1,73 @@
|
|
1
1
|
module Ddr::Index
|
2
|
-
#
|
3
|
-
# QueryBuilder - Provides a DSL for building a Query.
|
4
|
-
#
|
5
|
-
# Note: Where a method receives a [field] parameter, the parameter value is
|
6
|
-
# coerced to a Field instance. See FieldAttribute#coerce for details.
|
7
|
-
#
|
8
|
-
# *** DSL METHODS ***
|
9
|
-
#
|
10
|
-
# absent [field]
|
11
|
-
# Adds a filter selecting documents where the field is not present (no values).
|
12
|
-
#
|
13
|
-
# asc [field], ...
|
14
|
-
# Adds ascending orderings by the fields specified.
|
15
|
-
#
|
16
|
-
# See also: desc, order_by
|
17
|
-
#
|
18
|
-
# before [field], [date_time]
|
19
|
-
# Adds a filter selecting documents where the field has a date/time before
|
20
|
-
# (earlier than) the value.
|
21
|
-
#
|
22
|
-
# before_days [field], [int]
|
23
|
-
# Adds a filter selecting documents where the field has a date/time the
|
24
|
-
# specified number of days before today (now) or earlier.
|
25
|
-
#
|
26
|
-
# desc [field], ...
|
27
|
-
# Adds descending orderings by the fields specified.
|
28
|
-
#
|
29
|
-
# See also: asc, order_by
|
30
|
-
#
|
31
|
-
# filter [filter1], ...
|
32
|
-
# Adds filters to the query.
|
33
|
-
#
|
34
|
-
# Aliased as: filters
|
35
|
-
#
|
36
|
-
# filters [filter], ...
|
37
|
-
# Alias for: filter
|
38
|
-
#
|
39
|
-
# field [field1], ...
|
40
|
-
# Adds fields to result documents.
|
41
|
-
# Note that all fields are returned when none is specified.
|
42
|
-
#
|
43
|
-
# Aliased as: fields
|
44
|
-
#
|
45
|
-
# fields [field], ...
|
46
|
-
# Alias for: field
|
47
|
-
#
|
48
|
-
# id [doc_id]
|
49
|
-
# For selecting a single document by ID.
|
50
|
-
#
|
51
|
-
# join [from: {field1}, to: {field2}, where: {condition}]
|
52
|
-
# Adds a Solr join clause (see https://wiki.apache.org/solr/Join)
|
53
|
-
#
|
54
|
-
# limit [int]
|
55
|
-
# Limits the number of documents returned by the query.
|
56
|
-
#
|
57
|
-
# Aliased as: rows
|
58
|
-
#
|
59
|
-
# model [model_name], ...
|
60
|
-
# Adds a filter selecting document where ActiveFedora model equals value
|
61
|
-
# or one of the values.
|
62
|
-
#
|
63
|
-
# negative [field], [value]
|
64
|
-
# Adds a filter selecting document where field does not have the value.
|
65
|
-
#
|
66
|
-
# order_by [{field => order, ...}], ...
|
67
|
-
# Adds ordering(s) to the query.
|
68
|
-
#
|
69
|
-
# Aliased as: sort
|
70
|
-
#
|
71
|
-
# present [field]
|
72
|
-
# Adds a filter selecting document where the field has any value.
|
73
|
-
#
|
74
|
-
# q [query_clause]
|
75
|
-
# Sets a query clause for the `q` parameter.
|
76
|
-
#
|
77
|
-
# raw [clause1], ...
|
78
|
-
# Adds a filter of "raw" query clauses (i.e., pre-constructed).
|
79
|
-
#
|
80
|
-
# regexp [field], [regexp]
|
81
|
-
# Adds a filter selecting documents where the field has a value
|
82
|
-
# matching the regular expression.
|
83
|
-
# Slashes (/) in the regexp will be escaped as required by Solr.
|
84
|
-
#
|
85
|
-
# rows [int]
|
86
|
-
# Alias for: limit
|
87
|
-
#
|
88
|
-
# sort [{field => order, ...}]
|
89
|
-
# Alias for: order_by
|
90
|
-
#
|
91
|
-
# term [{field => value, ...}]
|
92
|
-
# Adds a filter of "term" query clauses for the fields and values.
|
93
|
-
#
|
94
|
-
# where [{field => value, ...}]
|
95
|
-
# Adds a filter of "standard" query clauses.
|
96
|
-
# Values will be escaped when the filter is serialized.
|
97
|
-
# If a hash value is an array, that query clause will select documents
|
98
|
-
# where the field matches any array entry.
|
99
|
-
#
|
100
2
|
class QueryBuilder
|
101
3
|
|
102
|
-
|
4
|
+
def self.build
|
5
|
+
builder = new
|
6
|
+
yield builder
|
7
|
+
builder.query
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@q = nil
|
12
|
+
@fields = [ ]
|
13
|
+
@filters = [ ]
|
14
|
+
@sort = [ ]
|
15
|
+
@rows = nil
|
16
|
+
end
|
103
17
|
|
104
|
-
def
|
105
|
-
|
106
|
-
|
107
|
-
|
18
|
+
def query
|
19
|
+
Query.new.tap do |qry|
|
20
|
+
instance_variables.each do |var|
|
21
|
+
qry.instance_variable_set(var, instance_variable_get(var))
|
22
|
+
end
|
108
23
|
end
|
109
24
|
end
|
110
25
|
|
111
|
-
# @param pid [String]
|
112
|
-
# @return [QueryBuilder]
|
113
26
|
def id(pid)
|
114
27
|
q QueryClause.id(pid)
|
115
28
|
limit 1
|
116
29
|
end
|
117
30
|
|
118
|
-
|
119
|
-
|
120
|
-
def filter(*filters)
|
121
|
-
query.filters += filters
|
31
|
+
def filter(*fltrs)
|
32
|
+
@filters.push *fltrs
|
122
33
|
self
|
123
34
|
end
|
124
|
-
alias_method :filters, :filter
|
125
35
|
|
126
|
-
|
127
|
-
|
128
|
-
def field(*fields)
|
129
|
-
query.fields += fields.flatten.map { |f| FieldAttribute.coerce(f) }
|
36
|
+
def fields(*flds)
|
37
|
+
@fields.push *flds
|
130
38
|
self
|
131
39
|
end
|
132
|
-
alias_method :fields, :field
|
133
40
|
|
134
|
-
# @param num [Integer]
|
135
|
-
# @return [QueryBuilder] self
|
136
41
|
def limit(num)
|
137
|
-
|
42
|
+
@rows = num
|
138
43
|
self
|
139
44
|
end
|
140
|
-
alias_method :rows, :limit
|
141
45
|
|
142
|
-
|
143
|
-
|
144
|
-
def order_by(*orderings)
|
145
|
-
query.sort += orderings.first.map { |field, order| SortOrder.new(field: field, order: order) }
|
46
|
+
def order_by(field, order)
|
47
|
+
@sort << [field, order].join(" ")
|
146
48
|
self
|
147
49
|
end
|
148
|
-
alias_method :sort, :order_by
|
149
50
|
|
150
|
-
|
151
|
-
|
152
|
-
def asc(*fields)
|
153
|
-
query.sort += fields.map { |field| SortOrder.asc(field) }
|
154
|
-
self
|
51
|
+
def asc(field)
|
52
|
+
order_by field, "asc"
|
155
53
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
query.sort += fields.map { |field| SortOrder.desc(field) }
|
160
|
-
self
|
54
|
+
|
55
|
+
def desc(field)
|
56
|
+
order_by field, "desc"
|
161
57
|
end
|
162
58
|
|
163
|
-
|
164
|
-
|
165
|
-
def q(query_clause)
|
166
|
-
query.q = query_clause
|
59
|
+
def q(q)
|
60
|
+
@q = q
|
167
61
|
self
|
168
62
|
end
|
169
63
|
|
170
|
-
|
171
|
-
|
172
|
-
def respond_to_missing?(name, include_all)
|
173
|
-
Filter::ClassMethods.public_instance_methods.include?(name)
|
174
|
-
end
|
64
|
+
protected
|
175
65
|
|
176
66
|
def method_missing(name, *args, &block)
|
177
|
-
if respond_to?
|
178
|
-
filter Filter.send(name, *args)
|
179
|
-
else
|
180
|
-
super
|
67
|
+
if Filter.respond_to? name
|
68
|
+
return filter Filter.send(name, *args, &block)
|
181
69
|
end
|
70
|
+
super
|
182
71
|
end
|
183
72
|
|
184
73
|
end
|