simple_solr 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.travis.yml +3 -0
- data/CHANGELOG.rdoc +7 -1
- data/DEVELOPMENT.rdoc +7 -2
- data/Gemfile +2 -1
- data/README.rdoc +16 -1
- data/lib/simple_solr/search.rb +8 -1
- data/lib/simple_solr/update.rb +5 -3
- data/lib/simple_solr/version.rb +1 -1
- data/spec/simple_solr/search_spec.rb +13 -2
- data/spec/support/database.rb +7 -31
- metadata +11 -12
- data/spec/db/database.yml.example +0 -3
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.6.0 (Aug 18, 2011)
|
2
|
+
|
3
|
+
- Return the parsed response from httparty for search results
|
4
|
+
- Sets the request content type to 'text/xml'
|
5
|
+
|
6
|
+
|
1
7
|
== 0.5.0 (Aug 17, 2011)
|
2
8
|
|
3
9
|
- Added simple_search method to retrieve results
|
@@ -12,4 +18,4 @@
|
|
12
18
|
|
13
19
|
== 0.4.0 (Aug 16, 2011)
|
14
20
|
|
15
|
-
- First release as a gem, indexing works
|
21
|
+
- First release as a gem, indexing works
|
data/DEVELOPMENT.rdoc
CHANGED
@@ -7,5 +7,10 @@ To get started, also no surprises:
|
|
7
7
|
|
8
8
|
1. gem install bundler (if you haven't already)
|
9
9
|
2. bundle
|
10
|
-
|
11
|
-
|
10
|
+
4. rake
|
11
|
+
|
12
|
+
|
13
|
+
== Database
|
14
|
+
|
15
|
+
SimpleSolr uses an in-memory SQLite database. This is more to satisfy
|
16
|
+
ActiveRecord than for SimpleSolr, but it's so fast it does not matter.
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -8,6 +8,7 @@ query strings and hashes directly, instead of with Ruby objects.
|
|
8
8
|
SimpleSolr is ideal when the Solr you use has been provided by a third party
|
9
9
|
and is more or less running fine without you.
|
10
10
|
|
11
|
+
|
11
12
|
=== Design goals and benefits of SimpleSolr
|
12
13
|
|
13
14
|
* only a few dozen lines of code
|
@@ -65,6 +66,7 @@ with just your environment and +solr+ key in there. You can leave out values
|
|
65
66
|
in the +master_solr+ section, since the gem will fall back to using values from
|
66
67
|
the +solr+ section instead.
|
67
68
|
|
69
|
+
|
68
70
|
=== Your models
|
69
71
|
|
70
72
|
<b>Note: in these examples I am using a class called Document. This is just for
|
@@ -92,6 +94,7 @@ Full example:
|
|
92
94
|
field :id, lambda { |record| "full-document-#{record.id}" }
|
93
95
|
field :title
|
94
96
|
field :date_creation, :created_at
|
97
|
+
field :date_offline, lambda { |record| record.offline_at.utc.iso8601 if record.offline_at? }
|
95
98
|
field :shared, false
|
96
99
|
field :publisher, "Megacorp LLC"
|
97
100
|
field :body
|
@@ -109,14 +112,17 @@ Use the latter if you want to add a dynamic field to Solr. The model
|
|
109
112
|
instance is passed as a parameter, so Bob's your uncle and the sky's
|
110
113
|
the limit.
|
111
114
|
|
115
|
+
|
112
116
|
=== Debugging
|
113
117
|
|
118
|
+
As far as I am concerned, one of the <b>killer features</b> of this gem.
|
114
119
|
If something isn't quite working, set httparty's +debug_output+ flag
|
115
120
|
on your model:
|
116
121
|
|
117
122
|
Document.debug_output
|
118
123
|
|
119
|
-
and then save the model to see the HTTP conversation on $
|
124
|
+
and then save the model to see the HTTP conversation on $stderr.
|
125
|
+
|
120
126
|
|
121
127
|
== Searching
|
122
128
|
|
@@ -171,6 +177,15 @@ If you want to add a bunch of existing models to Solr, you can:
|
|
171
177
|
Document.all.each do |document|
|
172
178
|
document.add_to_solr
|
173
179
|
end
|
180
|
+
|
181
|
+
Same for deleting documents:
|
182
|
+
|
183
|
+
Document.all.each do |document|
|
184
|
+
document.delete_from_solr
|
185
|
+
end
|
186
|
+
|
187
|
+
Just remember to not touch the +id+ field since you added the model, since
|
188
|
+
this key is used to delete documents from Solr.
|
174
189
|
|
175
190
|
|
176
191
|
== Helping out
|
data/lib/simple_solr/search.rb
CHANGED
@@ -4,9 +4,16 @@ module SimpleSolr
|
|
4
4
|
# For instance, to limit the results by using an +fq+ parameter:
|
5
5
|
#
|
6
6
|
# Product.simple_search 'delicious', :fq => "category:fruit"
|
7
|
+
#
|
8
|
+
# Returns a hash with the search results:
|
9
|
+
#
|
10
|
+
# {
|
11
|
+
# "lst" => [{"int"=>["0", "18"], "name"=>"responseHeader"},{"name"=>"highlighting"}],
|
12
|
+
# "result" => {"name"=>"response", "numFound"=>"0", "start"=>"0", "maxScore"=>"0.0"}
|
13
|
+
# }
|
7
14
|
def simple_search(query, params={})
|
8
15
|
query = {:q => query}
|
9
|
-
get(SimpleSolr.configuration.uri + "/select", :query => query.merge(params))
|
16
|
+
get(SimpleSolr.configuration.uri + "/select", :query => query.merge(params)).parsed_response['response']
|
10
17
|
end
|
11
18
|
end
|
12
19
|
end
|
data/lib/simple_solr/update.rb
CHANGED
@@ -5,10 +5,11 @@ module SimpleSolr
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
def simple_solr
|
8
|
+
def simple_solr
|
9
9
|
class_eval do
|
10
10
|
# httparty
|
11
11
|
include HTTParty
|
12
|
+
headers 'Content-Type' => 'text/xml'
|
12
13
|
|
13
14
|
# callbacks
|
14
15
|
after_save :add_to_solr
|
@@ -17,8 +18,9 @@ module SimpleSolr
|
|
17
18
|
|
18
19
|
# Store the simple_solr fields for this class
|
19
20
|
cattr_accessor :simple_solr_fields
|
20
|
-
self.simple_solr_fields = { id
|
21
|
-
|
21
|
+
self.simple_solr_fields = { :id => nil }
|
22
|
+
|
23
|
+
yield if block_given?
|
22
24
|
|
23
25
|
include InstanceMethods
|
24
26
|
end
|
data/lib/simple_solr/version.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SimpleSolr::Search do
|
4
|
+
let(:response) { stub("response")}
|
5
|
+
let(:httparty) { stub("httparty", :parsed_response => {'response' => response})}
|
6
|
+
|
4
7
|
describe SimpleDocument do
|
8
|
+
before do
|
9
|
+
SimpleDocument.stub(:get).and_return(httparty)
|
10
|
+
end
|
11
|
+
|
5
12
|
it "responds to search" do
|
6
13
|
SimpleDocument.should respond_to(:simple_search)
|
7
14
|
end
|
8
15
|
|
9
16
|
it "gets results" do
|
10
|
-
SimpleDocument.should_receive(:get).with("http://test.local:8983/solr/select", :query => {:q => 'bonanza'})
|
17
|
+
SimpleDocument.should_receive(:get).with("http://test.local:8983/solr/select", :query => {:q => 'bonanza'}).and_return(httparty)
|
11
18
|
SimpleDocument.simple_search 'bonanza'
|
12
19
|
end
|
13
20
|
|
14
21
|
it "allows parameters" do
|
15
|
-
SimpleDocument.should_receive(:get).with("http://test.local:8983/solr/select", :query => {:q => 'bonanza', :fq => "brand_site:www.example.com"})
|
22
|
+
SimpleDocument.should_receive(:get).with("http://test.local:8983/solr/select", :query => {:q => 'bonanza', :fq => "brand_site:www.example.com"}).and_return(httparty)
|
16
23
|
SimpleDocument.simple_search 'bonanza', :fq => "brand_site:www.example.com"
|
17
24
|
end
|
25
|
+
|
26
|
+
it "returns parsed response" do
|
27
|
+
SimpleDocument.simple_search('bonanza').should eq(response)
|
28
|
+
end
|
18
29
|
end
|
19
30
|
end
|
data/spec/support/database.rb
CHANGED
@@ -1,33 +1,9 @@
|
|
1
|
-
|
1
|
+
# Create schema and load the models
|
2
|
+
ActiveRecord::Base.establish_connection({:adapter => "sqlite3", :database => ":memory:"})
|
2
3
|
|
3
|
-
|
4
|
+
ActiveRecord::Base.silence do
|
5
|
+
ActiveRecord::Migration.verbose = false
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
ActiveRecord::Base.establish_connection(active_record_configuration)
|
10
|
-
|
11
|
-
ActiveRecord::Base.silence do
|
12
|
-
ActiveRecord::Migration.verbose = false
|
13
|
-
|
14
|
-
load(File.dirname(__FILE__) + '/../db/schema.rb')
|
15
|
-
load(File.dirname(__FILE__) + '/../db/models.rb')
|
16
|
-
end
|
17
|
-
|
18
|
-
else
|
19
|
-
abort <<-FAIL
|
20
|
-
|
21
|
-
Please create #{database_yml} first to configure your database.
|
22
|
-
Take a look at: #{database_yml}.example"
|
23
|
-
|
24
|
-
FAIL
|
25
|
-
end
|
26
|
-
|
27
|
-
def clean_database!
|
28
|
-
[SimpleDocument].each do |model|
|
29
|
-
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
clean_database!
|
7
|
+
load(File.dirname(__FILE__) + '/../db/schema.rb')
|
8
|
+
load(File.dirname(__FILE__) + '/../db/models.rb')
|
9
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_solr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-18 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153333520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153333520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activerecord
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153333100 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153333100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: httparty
|
38
|
-
requirement: &
|
38
|
+
requirement: &2164268940 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2164268940
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: builder
|
49
|
-
requirement: &
|
49
|
+
requirement: &2164268520 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2164268520
|
58
58
|
description: Solr client for Ruby on Rails with as few features as possible.
|
59
59
|
email:
|
60
60
|
- joost@spacebabies.nl
|
@@ -64,6 +64,7 @@ extra_rdoc_files: []
|
|
64
64
|
files:
|
65
65
|
- .gitignore
|
66
66
|
- .rspec
|
67
|
+
- .travis.yml
|
67
68
|
- CHANGELOG.rdoc
|
68
69
|
- DEVELOPMENT.rdoc
|
69
70
|
- Gemfile
|
@@ -77,7 +78,6 @@ files:
|
|
77
78
|
- simple_solr.gemspec
|
78
79
|
- spec/config/master_slave.yml
|
79
80
|
- spec/config/simple_solr.yml
|
80
|
-
- spec/db/database.yml.example
|
81
81
|
- spec/db/models.rb
|
82
82
|
- spec/db/schema.rb
|
83
83
|
- spec/simple_solr/configuration_spec.rb
|
@@ -114,7 +114,6 @@ summary: Simple Solr client
|
|
114
114
|
test_files:
|
115
115
|
- spec/config/master_slave.yml
|
116
116
|
- spec/config/simple_solr.yml
|
117
|
-
- spec/db/database.yml.example
|
118
117
|
- spec/db/models.rb
|
119
118
|
- spec/db/schema.rb
|
120
119
|
- spec/simple_solr/configuration_spec.rb
|