daedal 0.0.12 → 0.0.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebac4bd85f7c907672a838d333679a3b8d46bd0c
4
- data.tar.gz: ac87f2b4e1ea3fbf0eef292f848019e4616a7a4d
3
+ metadata.gz: 49b9a5ec5d8154e612f0a8e368b4a3ede833288a
4
+ data.tar.gz: 8df178f9d7d355ea309c260ac47f5ddb762df2f5
5
5
  SHA512:
6
- metadata.gz: 1d4470546828b9f1606dd3244415a6c7dde5bc9a09c33de3f6d938755b3afcfd2a88537a4a90700cc3393b43d782f43612dbe763daa7f80a119b729c6455892b
7
- data.tar.gz: 3c2929aa9091ef19e74b3a73d3363b7e3c62241de83bb9071a52ce2d747382f1eea20bbe013b37d07d353e09b160069c1e1d2765b1bd5b7827ebb1f21dc650fa
6
+ metadata.gz: a2393948c2748df8ff9adbf435ce79c910837eddefdef9fa80db35314136005af27e90d90de71be9da3a716cb4b26039c6822929de3a343c0c3a289ef17d13b5
7
+ data.tar.gz: 6a1950ca0d71446b5c5238b30c54f4f39e37a54bb362affb21bfe879d49e0708da7f38b0f306d8755212286c6529b06ee7a4c9681e7a6fd6f145d6fc021b2eed
data/README.md CHANGED
@@ -23,6 +23,9 @@ query DSL into Ruby objects, Daedal addresses the following issues:
23
23
  Daedal also makes it easy to define custom queries tailored to your specific use case - you can see
24
24
  a simple example at the end of the documentation.
25
25
 
26
+ Daedal itself is designed more as a "low level" library, and doesn't necessarily make for terribly elegant code.
27
+ If you'd prefer a more Ruby-friendly block DSL, you can take a look at a new project I've been working on, [DaedalSL](https://github.com/RallyPointNetworks/daedal-sl).
28
+
26
29
  Installation
27
30
  ------------
28
31
 
data/lib/daedal.rb CHANGED
@@ -43,5 +43,7 @@ require 'daedal/queries/nested_query'
43
43
  require 'daedal/queries/prefix_query'
44
44
  require 'daedal/queries/fuzzy_query'
45
45
  require 'daedal/queries/query_string_query'
46
+ require 'daedal/queries/term_query'
47
+ require 'daedal/queries/terms_query'
46
48
 
47
49
  # facets
@@ -0,0 +1,44 @@
1
+ module Daedal
2
+ module Queries
3
+ "" "Class for the basic term query" ""
4
+ class TermQuery < Query
5
+
6
+ # required attributes
7
+ attribute :field, Daedal::Attributes::Field
8
+
9
+ # non required attributes, but one must be required of the two, and one only
10
+ attribute :term, Daedal::Attributes::QueryValue, required: false
11
+ attribute :value, Daedal::Attributes::QueryValue, required: false
12
+
13
+ #non required attributes
14
+ attribute :boost, Daedal::Attributes::Boost, required: false
15
+
16
+ def initialize(options={})
17
+ super options
18
+
19
+ if value.nil? && term.nil?
20
+ raise "Must give a value or a term"
21
+ elsif value && term
22
+ raise "Use either Value or Term only, but not both"
23
+ elsif value && boost.nil?
24
+ raise "Please specified boost"
25
+ end
26
+
27
+ end
28
+
29
+ def to_hash
30
+ if boost
31
+ if value
32
+ result = {term: {field => {value: value, boost: boost}}}
33
+ else
34
+ result = {term: {field => {term: term, boost: boost}}}
35
+ end
36
+ else
37
+ result = {term: {field => term}}
38
+ end
39
+
40
+ result
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ module Daedal
2
+ module Queries
3
+ "" "Class for the basic terms query" ""
4
+ class TermsQuery < Query
5
+
6
+ # required attributes
7
+ attribute :field, Daedal::Attributes::Field
8
+ attribute :terms, Array[Daedal::Attributes::QueryValue]
9
+
10
+ # not required
11
+ attribute :minimum_should_match, Integer, default: 1, required: false
12
+
13
+ def to_hash
14
+ {terms: {field => terms}, minimum_should_match: minimum_should_match}
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Daedal
2
- VERSION = '0.0.12'
2
+ VERSION = '0.0.13'
3
3
  end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Queries::TermQuery do
4
+
5
+ subject do
6
+ Daedal::Queries::TermQuery
7
+ end
8
+
9
+ let(:field) do
10
+ :foo
11
+ end
12
+
13
+ let(:term) do
14
+ :bar
15
+ end
16
+
17
+ context 'without a field or a term specified' do
18
+ it 'will raise an error' do
19
+ expect { subject.new(boost: 2) }.to raise_error(Virtus::CoercionError)
20
+ end
21
+ end
22
+
23
+ context 'without a field specified' do
24
+ it 'will raise an error' do
25
+ expect { subject.new(term: term) }.to raise_error(Virtus::CoercionError)
26
+ end
27
+ end
28
+
29
+ context 'with both value and term specified' do
30
+ it 'will raise an error' do
31
+ expect { subject.new(field: field, term: term, value: term) }.to raise_error(RuntimeError)
32
+ end
33
+ end
34
+
35
+ context 'with value specified only (without boost)' do
36
+ it 'will raise an error' do
37
+ expect { subject.new(field: field, value: term) }.to raise_error(RuntimeError)
38
+ end
39
+ end
40
+
41
+ context 'with a field and a term specified (without boost)' do
42
+ let(:query) do
43
+ subject.new(field: field, term: term)
44
+ end
45
+
46
+ let(:hash_query) do
47
+ {term: {field => term}}
48
+ end
49
+
50
+ it 'will populate the field and term attributes appropriately' do
51
+ expect(query.field).to eq field
52
+ expect(query.term).to eq term
53
+ end
54
+ it 'will have the correct hash representation' do
55
+ expect(query.to_hash).to eq hash_query
56
+ end
57
+ it 'will have the correct json representation' do
58
+ expect(query.to_json).to eq hash_query.to_json
59
+ end
60
+ end
61
+
62
+ context 'with a field and a term specified (with boost)' do
63
+ let(:query) do
64
+ subject.new(field: field, term: term, boost: 2.0)
65
+ end
66
+
67
+ let(:hash_query) do
68
+ {term: {field => {term: term, boost: 2.0}}}
69
+ end
70
+
71
+ it 'will populate the field and term attributes appropriately' do
72
+ expect(query.field).to eq field
73
+ expect(query.term).to eq term
74
+ end
75
+ it 'will have the correct hash representation' do
76
+ expect(query.to_hash).to eq hash_query
77
+ end
78
+ it 'will have the correct json representation' do
79
+ expect(query.to_json).to eq hash_query.to_json
80
+ end
81
+
82
+ end
83
+
84
+ context 'with a field and a value specified (with boost)' do
85
+ let(:query) do
86
+ subject.new(field: field, value: term, boost: 2.0)
87
+ end
88
+
89
+ let(:hash_query) do
90
+ {term: {field => {value: term, boost: 2.0}}}
91
+ end
92
+
93
+ it 'will populate the field and term attributes appropriately' do
94
+ expect(query.field).to eq field
95
+ expect(query.value).to eq term
96
+ end
97
+ it 'will have the correct hash representation' do
98
+ expect(query.to_hash).to eq hash_query
99
+ end
100
+ it 'will have the correct json representation' do
101
+ expect(query.to_json).to eq hash_query.to_json
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Daedal::Queries::TermsQuery do
4
+
5
+ subject do
6
+ Daedal::Queries::TermsQuery
7
+ end
8
+
9
+ let(:field) do
10
+ :foo
11
+ end
12
+
13
+ let(:terms) do
14
+ [:bar , :superfoo]
15
+ end
16
+
17
+ let(:hash_query) do
18
+ {terms: {field => terms} , minimum_should_match: 1}
19
+ end
20
+
21
+ context 'without a field or a list of terms specified' do
22
+ it 'will raise an error' do
23
+ expect {subject.new}.to raise_error(Virtus::CoercionError)
24
+ end
25
+ end
26
+
27
+ context 'without a field specified' do
28
+ it 'will raise an error' do
29
+ expect {subject.new(terms: terms)}.to raise_error(Virtus::CoercionError)
30
+ end
31
+ end
32
+
33
+ context 'with a field and a term specified' do
34
+ let(:terms_query) do
35
+ subject.new(field: field, terms: terms)
36
+ end
37
+
38
+ it 'will populate the field and term attributes appropriately' do
39
+ expect(terms_query.field).to eq field
40
+ expect(terms_query.terms).to eq terms
41
+ end
42
+
43
+ it 'will have minimum match option set to default 1' do
44
+ expect(terms_query.minimum_should_match).to eq 1
45
+ end
46
+
47
+ it 'will have the correct hash representation' do
48
+ expect(terms_query.to_hash).to eq hash_query
49
+ end
50
+
51
+ it 'will have the correct json representation' do
52
+ expect(terms_query.to_json).to eq hash_query.to_json
53
+ end
54
+ end
55
+
56
+ context 'with minimum should match of 2 specified' do
57
+ let(:terms_query) do
58
+ subject.new(field: field, terms: terms, minimum_should_match: 2)
59
+ end
60
+
61
+ before do
62
+ hash_query[:minimum_should_match] = 2
63
+ end
64
+
65
+ it 'will set the phrase type to :phrase' do
66
+ expect(terms_query.minimum_should_match).to eq 2
67
+ end
68
+
69
+ it 'will have the correct hash representation' do
70
+ expect(terms_query.to_hash).to eq hash_query
71
+ end
72
+
73
+ it 'will have the correct json representation' do
74
+ expect(terms_query.to_json).to eq hash_query.to_json
75
+ end
76
+
77
+ end
78
+
79
+
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daedal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Schuch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -76,6 +76,8 @@ files:
76
76
  - lib/daedal/queries/prefix_query.rb
77
77
  - lib/daedal/queries/query.rb
78
78
  - lib/daedal/queries/query_string_query.rb
79
+ - lib/daedal/queries/term_query.rb
80
+ - lib/daedal/queries/terms_query.rb
79
81
  - lib/daedal/version.rb
80
82
  - spec/spec_helper.rb
81
83
  - spec/unit/daedal/filters/and_filter_spec.rb
@@ -98,6 +100,8 @@ files:
98
100
  - spec/unit/daedal/queries/nested_query_spec.rb
99
101
  - spec/unit/daedal/queries/prefix_query_spec.rb
100
102
  - spec/unit/daedal/queries/query_string_spec.rb
103
+ - spec/unit/daedal/queries/term_query_spec.rb
104
+ - spec/unit/daedal/queries/terms_query_spec.rb
101
105
  homepage: https://github.com/cschuch/daedal
102
106
  licenses:
103
107
  - MIT