gummi 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gummi/db_layer/document/search/filtered.rb +4 -2
- data/lib/gummi/db_layer/document/search/searching.rb +4 -3
- data/lib/gummi/db_layer/favorstuff.rb +15 -0
- data/lib/gummi/version.rb +1 -1
- data/spec/lib/gummi/db_layer/document_spec.rb +3 -3
- data/spec/lib/gummi/repository_layer/repository_spec.rb +10 -4
- data/spec/spec_helper.rb +15 -4
- metadata +2 -1
@@ -6,12 +6,14 @@ module Gummi
|
|
6
6
|
include Gummi::DbLayer::Document::Search::Searching
|
7
7
|
|
8
8
|
attribute :query_string, Gummi::DbLayer::Fields::SanitizedString
|
9
|
-
attribute :query_filters, Array[Hash],
|
10
|
-
attribute :facets, Hash,
|
9
|
+
attribute :query_filters, Array[Hash], default: []
|
10
|
+
attribute :facets, Hash, default: {}
|
11
|
+
attribute :sort, Hash, default: {}
|
11
12
|
|
12
13
|
def to_client_args
|
13
14
|
args = super
|
14
15
|
args[:body] = { query: filtered, facets: facets }
|
16
|
+
args[:body].merge!(sort: sort) if sort.present?
|
15
17
|
args
|
16
18
|
end
|
17
19
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
def self.favored_by(user_id, lot_ids = nil, search_options = {})
|
2
|
+
seek = Seek.new search_options, valid_sort_bys: %w{ catalogue_number }, max_per_page: 50, default_sort_by: :catalogue_number, default_sort_direction: :asc
|
3
|
+
favor_query = { filtered: { query: { match_all: {} }, filter: { term: { user_id: user_id.to_i } } } }
|
4
|
+
favor_filter = { has_child: { type: DB::Favoring.document_type, query: favor_query } }
|
5
|
+
if lot_ids
|
6
|
+
lot_ids = lot_ids.presence || [-1]
|
7
|
+
lot_query = { ids: { values: lot_ids } }
|
8
|
+
query = { filtered: { query: lot_query, filter: favor_filter }}
|
9
|
+
body = { query: query }
|
10
|
+
else
|
11
|
+
body = { query: favor_filter }
|
12
|
+
end
|
13
|
+
body.merge! sort: { seek.sort_by => seek.sort_direction }
|
14
|
+
raw_search seek.to_hash.merge options: { body: body }
|
15
|
+
end
|
data/lib/gummi/version.rb
CHANGED
@@ -57,7 +57,7 @@ describe Gummi::DbLayer::Document do
|
|
57
57
|
|
58
58
|
context 'attributes' do
|
59
59
|
|
60
|
-
context 'date times' do
|
60
|
+
context 'date times', elastic: true do
|
61
61
|
it 'coerces from elastics strings to real Time' do
|
62
62
|
time = Time.now
|
63
63
|
person = DB::Person.new(born_at: time)
|
@@ -96,7 +96,7 @@ describe Gummi::DbLayer::Document do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
context 'getting from elastic' do
|
99
|
+
context 'getting from elastic', elastic: true do
|
100
100
|
let(:person) { DB::Person.create(name: 'Buzz Lightyear') }
|
101
101
|
|
102
102
|
it 'returns an instance of the document_class' do
|
@@ -105,7 +105,7 @@ describe Gummi::DbLayer::Document do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
context 'child documents' do
|
108
|
+
context 'child documents', elastic: true do
|
109
109
|
let(:person) { DB::Person.create name: 'Superman' }
|
110
110
|
let(:rating) { DB::Rating.create person_id: person.id, stars: 5 }
|
111
111
|
|
@@ -16,7 +16,7 @@ describe Gummi::RepositoryLayer::Repository do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
describe '.get' do
|
19
|
+
describe '.get', elastic: true do
|
20
20
|
context 'existing record' do
|
21
21
|
let (:db_person) { DB::Person.create name: 'Buzz Lightyear' }
|
22
22
|
|
@@ -34,14 +34,20 @@ describe Gummi::RepositoryLayer::Repository do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe '.search' do
|
37
|
+
describe '.search', elastic: true do
|
38
|
+
let(:buzz) { DB::Person.create name: 'Buzz Lightyear' }
|
39
|
+
let(:woody) { DB::Person.create name: 'Woody' }
|
38
40
|
|
39
41
|
before do
|
40
|
-
|
41
|
-
DB::Person.create name: 'Woody'
|
42
|
+
buzz && woody
|
42
43
|
Gummi::DbLayer::DefaultIndex.refresh
|
43
44
|
end
|
44
45
|
|
46
|
+
it 'sorts correctly' do
|
47
|
+
People.search(sort: { name: :asc }).records.map(&:name).should == [buzz.name, woody.name]
|
48
|
+
People.search(sort: { name: :desc }).records.map(&:name).should == [woody.name, buzz.name]
|
49
|
+
end
|
50
|
+
|
45
51
|
it 'finds the correct documents' do
|
46
52
|
result = People.search do |search|
|
47
53
|
search.query_string = 'Woody'
|
data/spec/spec_helper.rb
CHANGED
@@ -33,14 +33,25 @@ require 'db/person'
|
|
33
33
|
require 'db/rating'
|
34
34
|
require 'db/ship'
|
35
35
|
|
36
|
+
def setup_elastic
|
37
|
+
Gummi::DbLayer::DefaultIndex.setup
|
38
|
+
DB::Person.sync_mapping!
|
39
|
+
DB::Rating.sync_mapping!
|
40
|
+
DB::Ship.sync_mapping!
|
41
|
+
end
|
42
|
+
|
36
43
|
RSpec.configure do |config|
|
37
44
|
config.before(:suite) do
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
setup_elastic
|
46
|
+
end
|
47
|
+
|
48
|
+
config.before(:each, elastic: true) do
|
49
|
+
setup_elastic
|
42
50
|
end
|
43
51
|
|
52
|
+
config.after(:each, elastic: true) do
|
53
|
+
Gummi::DbLayer::DefaultIndex.teardown
|
54
|
+
end
|
44
55
|
config.after(:suite) do
|
45
56
|
Gummi::DbLayer::DefaultIndex.teardown
|
46
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gummi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- lib/gummi/db_layer/document/search/raw.rb
|
215
215
|
- lib/gummi/db_layer/document/search/result.rb
|
216
216
|
- lib/gummi/db_layer/document/search/searching.rb
|
217
|
+
- lib/gummi/db_layer/favorstuff.rb
|
217
218
|
- lib/gummi/db_layer/fields/boolean.rb
|
218
219
|
- lib/gummi/db_layer/fields/integer.rb
|
219
220
|
- lib/gummi/db_layer/fields/keyword.rb
|