ansr_blacklight 0.0.3
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 +15 -0
- data/Gemfile +3 -0
- data/README.md +37 -0
- data/ansr_blacklight.gemspec +28 -0
- data/lib/ansr_blacklight.rb +57 -0
- data/lib/ansr_blacklight/arel.rb +6 -0
- data/lib/ansr_blacklight/arel/big_table.rb +57 -0
- data/lib/ansr_blacklight/arel/visitors.rb +6 -0
- data/lib/ansr_blacklight/arel/visitors/query_builder.rb +217 -0
- data/lib/ansr_blacklight/arel/visitors/to_no_sql.rb +14 -0
- data/lib/ansr_blacklight/base.rb +21 -0
- data/lib/ansr_blacklight/connection_adapters/no_sql_adapter.rb +38 -0
- data/lib/ansr_blacklight/model/querying.rb +29 -0
- data/lib/ansr_blacklight/relation.rb +50 -0
- data/lib/ansr_blacklight/relation/solr_projection_methods.rb +55 -0
- data/lib/ansr_blacklight/request_builders.rb +141 -0
- data/lib/ansr_blacklight/solr.rb +4 -0
- data/lib/ansr_blacklight/solr/request.rb +46 -0
- data/lib/ansr_blacklight/solr/response.rb +94 -0
- data/lib/ansr_blacklight/solr/response/group.rb +32 -0
- data/lib/ansr_blacklight/solr/response/group_response.rb +50 -0
- data/lib/ansr_blacklight/solr/response/more_like_this.rb +14 -0
- data/lib/ansr_blacklight/solr/response/pagination_methods.rb +35 -0
- data/lib/ansr_blacklight/solr/response/spelling.rb +92 -0
- data/spec/fixtures/config.yml +0 -0
- data/spec/lib/loaded_relation_spec.rb +223 -0
- data/spec/lib/queryable_relation_spec.rb +133 -0
- data/spec/lib/relation/faceting_spec.rb +475 -0
- data/spec/lib/relation/grouping_spec.rb +159 -0
- data/spec/spec_helper.rb +72 -0
- metadata +225 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# check the methods that do solr requests. Note that we are not testing if
|
5
|
+
# solr gives "correct" responses, as that's out of scope (it's a part of
|
6
|
+
# testing the solr code itself). We *are* testing if blacklight code sends
|
7
|
+
# queries to solr such that it gets appropriate results. When a user does a search,
|
8
|
+
# do we get data back from solr (i.e. did we properly configure blacklight code
|
9
|
+
# to talk with solr and get results)? when we do a document request, does
|
10
|
+
# blacklight code get a single document returned?)
|
11
|
+
#
|
12
|
+
describe Ansr::Blacklight do
|
13
|
+
|
14
|
+
class TestTable < Ansr::Arel::BigTable
|
15
|
+
|
16
|
+
def [](val)
|
17
|
+
key = (Arel::Attributes::Attribute === val) ? val.name.to_sym : val.to_sym
|
18
|
+
key == :configured ? Ansr::Arel::ConfiguredField.new(key, {:property => 'test', :escape => 'tes"t'}) : super(val)
|
19
|
+
end
|
20
|
+
|
21
|
+
def fields
|
22
|
+
[:id]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
before do
|
28
|
+
Object.const_set('GroupModel', Class.new(TestModel))
|
29
|
+
GroupModel.solr = stub_solr(sample_response)
|
30
|
+
GroupModel.configure do |config|
|
31
|
+
config[:table_class] = TestTable
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
Object.send(:remove_const, :GroupModel)
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:response) do
|
40
|
+
create_response(sample_response)
|
41
|
+
end
|
42
|
+
|
43
|
+
let(:group) do
|
44
|
+
response.grouped(GroupModel).select { |x| x.key == "result_group_ssi" }.first
|
45
|
+
end
|
46
|
+
|
47
|
+
subject do
|
48
|
+
group.groups.first
|
49
|
+
end
|
50
|
+
|
51
|
+
describe Ansr::Blacklight::Solr::Response::Group do
|
52
|
+
describe "#doclist" do
|
53
|
+
it "should be the raw list of documents from solr" do
|
54
|
+
expect(subject.doclist).to be_a Hash
|
55
|
+
expect(subject.doclist['docs'].first[:id]).to eq 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#total" do
|
60
|
+
it "should be the number of results found in a group" do
|
61
|
+
expect(subject.total).to eq 2
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#start" do
|
66
|
+
it "should be the offset for the results in the group" do
|
67
|
+
expect(subject.start).to eq 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#docs" do
|
72
|
+
it "should be a list of GroupModels" do
|
73
|
+
subject.docs.each do |doc|
|
74
|
+
expect(doc).to be_a_kind_of GroupModel
|
75
|
+
end
|
76
|
+
|
77
|
+
expect(subject.docs.first.id).to eq 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#field" do
|
82
|
+
it "should be the field the group belongs to" do
|
83
|
+
expect(subject.field).to eq "result_group_ssi"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe Ansr::Blacklight::Solr::Response do
|
89
|
+
let(:response) do
|
90
|
+
create_response(sample_response)
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:group) do
|
94
|
+
response.grouped(GroupModel).select { |x| x.key == "result_group_ssi" }.first
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "groups" do
|
98
|
+
it "should return an array of Groups" do
|
99
|
+
response.grouped(GroupModel).should be_a Array
|
100
|
+
|
101
|
+
expect(group.groups).to have(2).items
|
102
|
+
group.groups.each do |group|
|
103
|
+
expect(group).to be_a Ansr::Blacklight::Solr::Response::Group
|
104
|
+
end
|
105
|
+
end
|
106
|
+
it "should include a list of SolrDocuments" do
|
107
|
+
|
108
|
+
group.groups.each do |group|
|
109
|
+
group.docs.each do |doc|
|
110
|
+
expect(doc).to be_a GroupModel
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "total" do
|
117
|
+
it "should return the ngroups value" do
|
118
|
+
expect(group.total).to eq 3
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "facets" do
|
123
|
+
it "should exist in the response object (not testing, we just extend the module)" do
|
124
|
+
expect(group).to respond_to :facets
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "rows" do
|
129
|
+
it "should get the rows from the response" do
|
130
|
+
expect(group.rows).to eq 3
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "group_field" do
|
135
|
+
it "should be the field name for the current group" do
|
136
|
+
expect(group.group_field).to eq "result_group_ssi"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "group_limit" do
|
141
|
+
it "should be the number of documents to return for a group" do
|
142
|
+
expect(group.group_limit).to eq 5
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def sample_response
|
148
|
+
{"responseHeader" => {"params" =>{"rows" => 3, "group.limit" => 5}},
|
149
|
+
"grouped" =>
|
150
|
+
{'result_group_ssi' =>
|
151
|
+
{'groups' => [{'groupValue'=>"Group 1", 'doclist'=>{'numFound'=>2, 'start' => 0, 'docs'=>[{:id=>1}, {:id => 'x'}]}},
|
152
|
+
{'groupValue'=>"Group 2", 'doclist'=>{'numFound'=>3, 'docs'=>[{:id=>2}, :id=>3]}}
|
153
|
+
],
|
154
|
+
'ngroups' => "3"
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app/models'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
ENV["RAILS_ENV"] ||= 'test'
|
7
|
+
require 'ansr'
|
8
|
+
require 'rails/all'
|
9
|
+
require 'rspec/rails'
|
10
|
+
require 'loggable'
|
11
|
+
require 'ansr_blacklight'
|
12
|
+
#require 'blacklight'
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
# == Mock Framework
|
16
|
+
#
|
17
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
18
|
+
#
|
19
|
+
# config.mock_with :mocha
|
20
|
+
# config.mock_with :flexmock
|
21
|
+
# config.mock_with :rr
|
22
|
+
config.mock_with :rspec
|
23
|
+
|
24
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
25
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
26
|
+
|
27
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
28
|
+
# examples within a transaction, remove the following line or assign false
|
29
|
+
# instead of true.
|
30
|
+
#config.use_transactional_fixtures = true
|
31
|
+
end
|
32
|
+
|
33
|
+
def fixture_path(path)
|
34
|
+
File.join(File.dirname(__FILE__), '..', 'fixtures', path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def fixture path, &block
|
38
|
+
if block_given?
|
39
|
+
open(fixture_path(path)) &block
|
40
|
+
else
|
41
|
+
open(fixture_path(path))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def read_fixture(path)
|
46
|
+
_f = fixture(path)
|
47
|
+
_f.read
|
48
|
+
ensure
|
49
|
+
_f and _f.close
|
50
|
+
end
|
51
|
+
|
52
|
+
def stub_solr(response='')
|
53
|
+
solr = double('Solr')
|
54
|
+
solr.stub(:send_and_receive).and_return(response)
|
55
|
+
solr
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_response(response, params = {})
|
59
|
+
Ansr::Blacklight::Solr::Response.new(response, params)
|
60
|
+
end
|
61
|
+
|
62
|
+
class TestModel < Ansr::Blacklight::Base
|
63
|
+
configure do |config|
|
64
|
+
config[:unique_key] = 'id'
|
65
|
+
end
|
66
|
+
def self.solr=(solr)
|
67
|
+
@solr = solr
|
68
|
+
end
|
69
|
+
def self.solr
|
70
|
+
@solr
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ansr_blacklight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Armintor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ansr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json-ld
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: loggable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.6
|
76
|
+
- - <
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '5'
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 3.2.6
|
86
|
+
- - <
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sass-rails
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rake
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: bundler
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 1.0.14
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.0.14
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rspec-rails
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: yard
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
description: Wrapping the Blacklight/RSolr in Rails-like models and relations
|
160
|
+
email:
|
161
|
+
- armintor@gmail.com
|
162
|
+
executables: []
|
163
|
+
extensions: []
|
164
|
+
extra_rdoc_files: []
|
165
|
+
files:
|
166
|
+
- Gemfile
|
167
|
+
- README.md
|
168
|
+
- ansr_blacklight.gemspec
|
169
|
+
- lib/ansr_blacklight.rb
|
170
|
+
- lib/ansr_blacklight/arel.rb
|
171
|
+
- lib/ansr_blacklight/arel/big_table.rb
|
172
|
+
- lib/ansr_blacklight/arel/visitors.rb
|
173
|
+
- lib/ansr_blacklight/arel/visitors/query_builder.rb
|
174
|
+
- lib/ansr_blacklight/arel/visitors/to_no_sql.rb
|
175
|
+
- lib/ansr_blacklight/base.rb
|
176
|
+
- lib/ansr_blacklight/connection_adapters/no_sql_adapter.rb
|
177
|
+
- lib/ansr_blacklight/model/querying.rb
|
178
|
+
- lib/ansr_blacklight/relation.rb
|
179
|
+
- lib/ansr_blacklight/relation/solr_projection_methods.rb
|
180
|
+
- lib/ansr_blacklight/request_builders.rb
|
181
|
+
- lib/ansr_blacklight/solr.rb
|
182
|
+
- lib/ansr_blacklight/solr/request.rb
|
183
|
+
- lib/ansr_blacklight/solr/response.rb
|
184
|
+
- lib/ansr_blacklight/solr/response/group.rb
|
185
|
+
- lib/ansr_blacklight/solr/response/group_response.rb
|
186
|
+
- lib/ansr_blacklight/solr/response/more_like_this.rb
|
187
|
+
- lib/ansr_blacklight/solr/response/pagination_methods.rb
|
188
|
+
- lib/ansr_blacklight/solr/response/spelling.rb
|
189
|
+
- spec/fixtures/config.yml
|
190
|
+
- spec/lib/loaded_relation_spec.rb
|
191
|
+
- spec/lib/queryable_relation_spec.rb
|
192
|
+
- spec/lib/relation/faceting_spec.rb
|
193
|
+
- spec/lib/relation/grouping_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
homepage: https://github.com/barmintor/ansr/tree/master/ansr_blacklight
|
196
|
+
licenses: []
|
197
|
+
metadata: {}
|
198
|
+
post_install_message:
|
199
|
+
rdoc_options: []
|
200
|
+
require_paths:
|
201
|
+
- lib
|
202
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - ! '>='
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
requirements: []
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 2.2.2
|
215
|
+
signing_key:
|
216
|
+
specification_version: 4
|
217
|
+
summary: ActiveRecord-style models and relations for Blacklight
|
218
|
+
test_files:
|
219
|
+
- spec/fixtures/config.yml
|
220
|
+
- spec/lib/loaded_relation_spec.rb
|
221
|
+
- spec/lib/queryable_relation_spec.rb
|
222
|
+
- spec/lib/relation/faceting_spec.rb
|
223
|
+
- spec/lib/relation/grouping_spec.rb
|
224
|
+
- spec/spec_helper.rb
|
225
|
+
has_rdoc:
|