ddr-models 2.4.0.rc4 → 2.4.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/ddr-models.gemspec +1 -1
- data/lib/ddr/index.rb +1 -2
- data/lib/ddr/index/field_attribute.rb +18 -0
- data/lib/ddr/index/filter.rb +70 -38
- data/lib/ddr/index/filters.rb +7 -20
- data/lib/ddr/index/query.rb +13 -8
- data/lib/ddr/index/query_builder.rb +122 -49
- data/lib/ddr/index/query_clause.rb +55 -41
- data/lib/ddr/index/query_params.rb +28 -12
- data/lib/ddr/index/sort_order.rb +11 -3
- data/lib/ddr/models/version.rb +1 -1
- data/spec/index/filter_spec.rb +74 -32
- data/spec/index/query_builder_spec.rb +45 -24
- data/spec/index/query_clause_spec.rb +29 -21
- data/spec/index/query_spec.rb +6 -3
- metadata +5 -12
- data/lib/ddr/index/queries.rb +0 -20
- data/lib/ddr/index/query_value.rb +0 -24
- data/spec/index/filters_spec.rb +0 -34
- data/spec/index/queries_spec.rb +0 -21
- data/spec/index/query_value_spec.rb +0 -33
@@ -2,43 +2,51 @@ module Ddr::Index
|
|
2
2
|
RSpec.describe QueryClause do
|
3
3
|
|
4
4
|
describe "class methods" do
|
5
|
-
describe ".build" do
|
6
|
-
subject { QueryClause.build("foo", "bar") }
|
7
|
-
it { is_expected.to eq "foo:bar" }
|
8
|
-
end
|
9
5
|
describe ".unique_key" do
|
10
|
-
subject {
|
11
|
-
|
6
|
+
subject { described_class.unique_key("test:1") }
|
7
|
+
its(:to_s) { is_expected.to eq "{!term f=id}test:1" }
|
12
8
|
end
|
13
9
|
describe ".id" do
|
14
|
-
subject {
|
15
|
-
|
10
|
+
subject { described_class.id("test:1") }
|
11
|
+
its(:to_s) { is_expected.to eq "{!term f=id}test:1" }
|
16
12
|
end
|
17
13
|
describe ".negative" do
|
18
|
-
subject {
|
19
|
-
|
14
|
+
subject { described_class.negative("foo", "Jungle Fever") }
|
15
|
+
its(:to_s) { is_expected.to eq "-foo:\"Jungle Fever\"" }
|
20
16
|
end
|
21
17
|
describe ".present" do
|
22
|
-
subject {
|
23
|
-
|
18
|
+
subject { described_class.present("foo") }
|
19
|
+
its(:to_s) { is_expected.to eq "foo:[* TO *]" }
|
24
20
|
end
|
25
21
|
describe ".absent" do
|
26
|
-
subject {
|
27
|
-
|
22
|
+
subject { described_class.absent("foo") }
|
23
|
+
its(:to_s) { is_expected.to eq "-foo:[* TO *]" }
|
28
24
|
end
|
29
|
-
describe ".
|
30
|
-
subject {
|
31
|
-
|
25
|
+
describe ".disjunction" do
|
26
|
+
subject { described_class.disjunction("foo", ["Jungle Fever", "bar"]) }
|
27
|
+
its(:to_s) { is_expected.to eq "{!lucene q.op=OR df=foo}\"Jungle Fever\" bar" }
|
32
28
|
end
|
33
29
|
describe ".before" do
|
34
|
-
|
30
|
+
subject { described_class.before("foo", DateTime.parse("2015-12-14T20:40:06Z")) }
|
31
|
+
its(:to_s) { is_expected.to eq "foo:[* TO 2015-12-14T20:40:06Z]" }
|
35
32
|
end
|
36
33
|
describe ".before_days" do
|
37
|
-
subject {
|
38
|
-
|
34
|
+
subject { described_class.before_days("foo", 5) }
|
35
|
+
its(:to_s) { is_expected.to eq "foo:[* TO NOW-5DAYS]" }
|
39
36
|
end
|
40
37
|
describe ".term" do
|
41
|
-
|
38
|
+
subject { described_class.term("foo", "bar") }
|
39
|
+
its(:to_s) { is_expected.to eq "{!term f=foo}bar" }
|
40
|
+
end
|
41
|
+
describe ".where" do
|
42
|
+
describe "when the value is a string" do
|
43
|
+
subject { described_class.where("foo", "Jungle Fever") }
|
44
|
+
its(:to_s) { is_expected.to eq "foo:\"Jungle Fever\"" }
|
45
|
+
end
|
46
|
+
describe "when the value is an array" do
|
47
|
+
subject { described_class.where("foo", ["Jungle Fever", "bar"]) }
|
48
|
+
its(:to_s) { is_expected.to eq "{!lucene q.op=OR df=foo}\"Jungle Fever\" bar" }
|
49
|
+
end
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
data/spec/index/query_spec.rb
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
module Ddr::Index
|
2
2
|
RSpec.describe Query do
|
3
|
+
|
3
4
|
let(:id) { UniqueKeyField.instance }
|
4
5
|
let(:foo) { Field.new("foo") }
|
5
6
|
let(:spam) { Field.new("spam") }
|
6
7
|
let(:filter) { Filter.where(spam=>"eggs") }
|
7
8
|
let(:sort_order) { SortOrder.new(field: foo, order: "asc") }
|
8
9
|
let(:fields) { [id, foo, spam] }
|
10
|
+
|
9
11
|
subject {
|
10
12
|
described_class.new(q: "foo:bar",
|
11
|
-
filters: filter,
|
13
|
+
filters: [filter],
|
12
14
|
fields: fields,
|
13
15
|
sort: sort_order,
|
14
16
|
rows: 50)
|
15
17
|
}
|
18
|
+
|
16
19
|
its(:to_s) {
|
17
|
-
is_expected.to eq "q=foo%3Abar&fq
|
20
|
+
is_expected.to eq "q=foo%3Abar&fq=spam%3Aeggs&fl=id%2Cfoo%2Cspam&sort=foo+asc&rows=50"
|
18
21
|
}
|
19
22
|
its(:params) {
|
20
|
-
is_expected.to eq({q: "foo:bar", fl: "id,foo,spam", fq: ["
|
23
|
+
is_expected.to eq({q: "foo:bar", fl: "id,foo,spam", fq: ["spam:eggs"], sort: "foo asc", rows: 50})
|
21
24
|
}
|
22
25
|
end
|
23
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddr-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.0.
|
4
|
+
version: 2.4.0.rc5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Coble
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-12-
|
12
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -233,14 +233,14 @@ dependencies:
|
|
233
233
|
requirements:
|
234
234
|
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: '1.
|
236
|
+
version: '1.11'
|
237
237
|
type: :development
|
238
238
|
prerelease: false
|
239
239
|
version_requirements: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
241
|
- - "~>"
|
242
242
|
- !ruby/object:Gem::Version
|
243
|
-
version: '1.
|
243
|
+
version: '1.11'
|
244
244
|
- !ruby/object:Gem::Dependency
|
245
245
|
name: rake
|
246
246
|
requirement: !ruby/object:Gem::Requirement
|
@@ -466,17 +466,16 @@ files:
|
|
466
466
|
- lib/ddr/index/csv_query_result.rb
|
467
467
|
- lib/ddr/index/document_builder.rb
|
468
468
|
- lib/ddr/index/field.rb
|
469
|
+
- lib/ddr/index/field_attribute.rb
|
469
470
|
- lib/ddr/index/fields.rb
|
470
471
|
- lib/ddr/index/filter.rb
|
471
472
|
- lib/ddr/index/filters.rb
|
472
473
|
- lib/ddr/index/legacy_license_fields.rb
|
473
|
-
- lib/ddr/index/queries.rb
|
474
474
|
- lib/ddr/index/query.rb
|
475
475
|
- lib/ddr/index/query_builder.rb
|
476
476
|
- lib/ddr/index/query_clause.rb
|
477
477
|
- lib/ddr/index/query_params.rb
|
478
478
|
- lib/ddr/index/query_result.rb
|
479
|
-
- lib/ddr/index/query_value.rb
|
480
479
|
- lib/ddr/index/response.rb
|
481
480
|
- lib/ddr/index/sort_order.rb
|
482
481
|
- lib/ddr/index/unique_key_field.rb
|
@@ -635,12 +634,9 @@ files:
|
|
635
634
|
- spec/helpers/models_helper_spec.rb
|
636
635
|
- spec/index/fields_spec.rb
|
637
636
|
- spec/index/filter_spec.rb
|
638
|
-
- spec/index/filters_spec.rb
|
639
|
-
- spec/index/queries_spec.rb
|
640
637
|
- spec/index/query_builder_spec.rb
|
641
638
|
- spec/index/query_clause_spec.rb
|
642
639
|
- spec/index/query_spec.rb
|
643
|
-
- spec/index/query_value_spec.rb
|
644
640
|
- spec/jobs/fits_file_characterization_spec.rb
|
645
641
|
- spec/jobs/fixity_check_spec.rb
|
646
642
|
- spec/jobs/job_spec.rb
|
@@ -810,12 +806,9 @@ test_files:
|
|
810
806
|
- spec/helpers/models_helper_spec.rb
|
811
807
|
- spec/index/fields_spec.rb
|
812
808
|
- spec/index/filter_spec.rb
|
813
|
-
- spec/index/filters_spec.rb
|
814
|
-
- spec/index/queries_spec.rb
|
815
809
|
- spec/index/query_builder_spec.rb
|
816
810
|
- spec/index/query_clause_spec.rb
|
817
811
|
- spec/index/query_spec.rb
|
818
|
-
- spec/index/query_value_spec.rb
|
819
812
|
- spec/jobs/fits_file_characterization_spec.rb
|
820
813
|
- spec/jobs/fixity_check_spec.rb
|
821
814
|
- spec/jobs/job_spec.rb
|
data/lib/ddr/index/queries.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Ddr::Index
|
2
|
-
module Queries
|
3
|
-
|
4
|
-
# Returns a query for a single index document.
|
5
|
-
# @param doc_id [String] the index document id
|
6
|
-
# @return [Query] the query
|
7
|
-
def self.id(doc_id)
|
8
|
-
builder = QueryBuilder.new { id doc_id }
|
9
|
-
builder.query
|
10
|
-
end
|
11
|
-
|
12
|
-
# Returns a query for the index document for an object.
|
13
|
-
# @param obj [ActiveFedora::Base] the object
|
14
|
-
# @return [Query] the query
|
15
|
-
def self.object(obj)
|
16
|
-
id(obj.pid)
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Ddr::Index
|
2
|
-
class QueryValue
|
3
|
-
|
4
|
-
class << self
|
5
|
-
# Returns an escaped query value
|
6
|
-
# @param value [String] the unescaped value
|
7
|
-
# @return [String] the escaped value
|
8
|
-
def build(value)
|
9
|
-
RSolr.solr_escape(value)
|
10
|
-
end
|
11
|
-
|
12
|
-
# Builds an escaped query value for use in filtering on a field for any value in the list of values
|
13
|
-
# @param values [Enumerable<String>]
|
14
|
-
# @return [String] query value
|
15
|
-
def or_values(values)
|
16
|
-
unless values.is_a?(::Enumerable) && values.present?
|
17
|
-
raise ArgumentError, "`#{self.name}.or_values` requires a non-empty enumerable of strings."
|
18
|
-
end
|
19
|
-
"(%s)" % values.map { |value| build(value) }.join(" OR ")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
data/spec/index/filters_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Ddr::Index
|
2
|
-
RSpec.describe Filters do
|
3
|
-
|
4
|
-
describe "class methods" do
|
5
|
-
describe ".is_governed_by" do
|
6
|
-
describe "with an object" do
|
7
|
-
subject { Filters.is_governed_by(Item.new(pid: "test:1")) }
|
8
|
-
its(:clauses) { is_expected.to eq(["{!term f=is_governed_by_ssim}info:fedora/test:1"]) }
|
9
|
-
end
|
10
|
-
describe "with an ID" do
|
11
|
-
subject { Filters.is_governed_by("test:1") }
|
12
|
-
its(:clauses) { is_expected.to eq(["{!term f=is_governed_by_ssim}info:fedora/test:1"]) }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".is_member_of_collection" do
|
17
|
-
describe "with an object" do
|
18
|
-
subject { Filters.is_member_of_collection(Item.new(pid: "test:1")) }
|
19
|
-
its(:clauses) { is_expected.to eq(["{!term f=is_member_of_collection_ssim}info:fedora/test:1"]) }
|
20
|
-
end
|
21
|
-
describe "with an ID" do
|
22
|
-
subject { Filters.is_member_of_collection("test:1") }
|
23
|
-
its(:clauses) { is_expected.to eq(["{!term f=is_member_of_collection_ssim}info:fedora/test:1"]) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe ".has_content" do
|
28
|
-
subject { Filters.has_content }
|
29
|
-
its(:clauses) { is_expected.to eq(["active_fedora_model_ssi:(Component OR Attachment OR Target)"]) }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
data/spec/index/queries_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Ddr::Index
|
2
|
-
RSpec.describe Queries do
|
3
|
-
|
4
|
-
describe "module methods" do
|
5
|
-
let(:obj) { FactoryGirl.create(:item) }
|
6
|
-
|
7
|
-
describe ".id" do
|
8
|
-
specify {
|
9
|
-
expect(Queries.id(obj.pid).pids.to_a).to eq [obj.pid]
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
describe ".object" do
|
14
|
-
specify {
|
15
|
-
expect(Queries.object(obj).pids.to_a).to eq [obj.pid]
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Ddr::Index
|
2
|
-
RSpec.describe QueryValue do
|
3
|
-
|
4
|
-
describe ".or_values" do
|
5
|
-
describe "when argument is nil" do
|
6
|
-
it "raises an exception" do
|
7
|
-
expect { described_class.or_values(nil) }.to raise_error(ArgumentError)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
describe "when argument is empty" do
|
11
|
-
it "raises an exception" do
|
12
|
-
expect { described_class.or_values([]) }.to raise_error(ArgumentError)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
describe "when argument is not enumerable" do
|
16
|
-
it "raises an exception" do
|
17
|
-
expect { described_class.or_values("foo") }.to raise_error(ArgumentError)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
describe "when argument size == 1" do
|
21
|
-
it "returns the first value, escaped" do
|
22
|
-
expect(described_class.or_values(["foo:bar"])).to eq("(foo\\:bar)")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
describe "when argument size > 1" do
|
26
|
-
it "return the escaped values OR'd together in parentheses" do
|
27
|
-
expect(described_class.or_values(["foo:bar", "spam:eggs"])).to eq("(foo\\:bar OR spam\\:eggs)")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|