websolr-sunspot4heroku-cis 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/README.rdoc +213 -0
- data/Rakefile +15 -0
- data/VERSION +1 -0
- data/lib/websolr-sunspot4heroku.rb +2 -0
- data/websolr-sunspot4heroku-cis.gemspec +44 -0
- metadata +75 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
== About
|
2
|
+
|
3
|
+
This is the gem to install for the supported version of sunspot_rails on websolr.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
cd your_rails_app
|
8
|
+
sudo gem install websolr-sunspot4heroku
|
9
|
+
config.gem "websolr-sunspot4heroku" # into config.environment.rb
|
10
|
+
echo websolr-sunspot4heroku >> .gems # if using Heroku
|
11
|
+
./script/generate sunspot # Installs config/sunspot.yml
|
12
|
+
echo "require 'sunspot/rails/tasks'" >> Rakefile # Installs local development tasks
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
=== Starting a local development server
|
17
|
+
|
18
|
+
To start up a Solr instance for development, issue the following:
|
19
|
+
|
20
|
+
rake sunspot:solr:start
|
21
|
+
|
22
|
+
=== Using in production
|
23
|
+
|
24
|
+
You need to make sure that the WEBSOLR_URL environment variable is set correctly.
|
25
|
+
|
26
|
+
If you're using Heroku, this should happen automatically. You can verify by running <code>heroku config</code>.
|
27
|
+
|
28
|
+
If you're running in your own environment, set the environment variable as you normally would on a *nix system.
|
29
|
+
|
30
|
+
If you have to set the variable in Ruby, you should be able to put the following in an Rails initializer:
|
31
|
+
|
32
|
+
if RAILS_ENV == "production"
|
33
|
+
ENV["WEBSOLR_URL"] = "http://index.websolr.com/solr/[your-api-key]"
|
34
|
+
load "websolr-sunspot_rails.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
=== Setup
|
38
|
+
|
39
|
+
In order for an ActiveRecord model to be indexable and searchable, it must be
|
40
|
+
configured for search. For example:
|
41
|
+
|
42
|
+
class Post < ActiveRecord::Base
|
43
|
+
searchable do
|
44
|
+
text :title, :body
|
45
|
+
integer :blog_id
|
46
|
+
time :updated_at
|
47
|
+
string :sort_title do
|
48
|
+
title.downcase.sub(/^(an?|the) /, '')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
See the documentation for Sunspot.setup for full details on what can go in the
|
54
|
+
configuration block.
|
55
|
+
|
56
|
+
=== Indexing
|
57
|
+
|
58
|
+
By default, models are indexed whenever they are saved, and removed from the
|
59
|
+
index whenever they are destroyed. This behavior can be disabled:
|
60
|
+
|
61
|
+
class Post < ActiveRecord::Base
|
62
|
+
searchable :auto_index => false, :auto_remove => false do
|
63
|
+
# setup...
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Note that <b>using the <code>:auto_remove</code> option is not recommended
|
68
|
+
</b>, as destroying an object without removing it from the index will
|
69
|
+
create an orphaned document in the index, which is a Bad Thing. Turning off
|
70
|
+
<code>:auto_index</code> is perfectly safe if you prefer to manage indexing manually
|
71
|
+
(perhaps using a background job).
|
72
|
+
|
73
|
+
If you have disabled lifecycle indexing hooks, you can invoke indexing
|
74
|
+
operations directly on your model:
|
75
|
+
|
76
|
+
post = Post.create
|
77
|
+
post.index
|
78
|
+
post.remove_from_index
|
79
|
+
|
80
|
+
=== Committing
|
81
|
+
|
82
|
+
When data is changed in Solr, it is initially stored in memory and not made
|
83
|
+
available to the currently running searcher instance. Issuing a +commit+ to Solr
|
84
|
+
will cause it to write the changes to disk, and instantiate a new searcher
|
85
|
+
instance. This operation is fairly expensive, so rather than issuing a commit
|
86
|
+
every time a document is added or removed, Sunspot::Rails issues a commit at
|
87
|
+
the end of any request where data has been added to or removed from Solr. If
|
88
|
+
you need to immediately issue a commit, bang!-versions of the methods are
|
89
|
+
available:
|
90
|
+
|
91
|
+
post = Post.create
|
92
|
+
post.index!
|
93
|
+
# this is the same as...
|
94
|
+
post.index
|
95
|
+
Sunspot.commit
|
96
|
+
|
97
|
+
When writing tests outside of the context of a controller request, you will want
|
98
|
+
to use one of these two approaches.
|
99
|
+
|
100
|
+
=== Searching
|
101
|
+
|
102
|
+
Do it like this:
|
103
|
+
|
104
|
+
Post.search do
|
105
|
+
with :blog_id, 1
|
106
|
+
with(:updated_at).greater_than(Time.now - 2.weeks)
|
107
|
+
order :sort_title, :asc
|
108
|
+
paginate :page => 1, :per_page => 15
|
109
|
+
end
|
110
|
+
|
111
|
+
See the documentation for <code>Sunspot.search</code> for all the options
|
112
|
+
available in the search block, and the information available in the result
|
113
|
+
block.
|
114
|
+
|
115
|
+
=== Searching for IDs
|
116
|
+
|
117
|
+
In some situations, you may want to get the IDs for models returned by a search
|
118
|
+
without actually loading the models out of the database. For that, you can
|
119
|
+
call +search_ids+, using the same block format as #search. This will return an
|
120
|
+
array of IDs.
|
121
|
+
|
122
|
+
|
123
|
+
=== Searching for multiple types
|
124
|
+
|
125
|
+
Sunspot is entirely agnostic about whether searches are for one or more types;
|
126
|
+
the only restriction is that columns used for restriction, ordering, etc. are
|
127
|
+
defined in the same way for all types being searched. Sunspot::Rails does not
|
128
|
+
provide any additional support for this, since there is not anything useful to
|
129
|
+
be added, so just use the interface provided by Sunspot:
|
130
|
+
|
131
|
+
Sunspot.search(Post, Comment) do
|
132
|
+
with :blog_id, 1
|
133
|
+
order :created_at, :asc
|
134
|
+
end
|
135
|
+
|
136
|
+
Be sure to check out the Sunspot documentation for all the details.
|
137
|
+
|
138
|
+
=== Adding search functionality in mixins
|
139
|
+
|
140
|
+
Sunspot does not require that search setup for a given class happen all in one
|
141
|
+
place; it is perfectly acceptable to call the <code>Sunspot.setup</code> method
|
142
|
+
more than once. This capability is particularly useful for adding search
|
143
|
+
functionality in mixins. For instance, if you have a +Ratable+ module, you may
|
144
|
+
wish to add additional search fields for searchable classes that mix in that
|
145
|
+
module. For example:
|
146
|
+
|
147
|
+
module Ratable
|
148
|
+
def self.included(base)
|
149
|
+
if base.searchable?
|
150
|
+
base.searchable do
|
151
|
+
float :average_rating do
|
152
|
+
ratings.average(:value)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
Note the use of <code>base.searchable?</code> - this ensures that only classes
|
160
|
+
that already have search enabled will have the additional configuration added.
|
161
|
+
The above pattern requires that the class be declared searchable before the
|
162
|
+
module is mixed in; other patterns (such as passing a :searchable option to an
|
163
|
+
acts_as_-style declaration) may be more flexible.
|
164
|
+
|
165
|
+
=== Utility methods
|
166
|
+
|
167
|
+
If you need to completely reindex all of the instances of a given model class,
|
168
|
+
you can issue:
|
169
|
+
|
170
|
+
Post.reindex
|
171
|
+
|
172
|
+
If for some reason models get deleted from the database, but not from the index,
|
173
|
+
they will become index orphans - not a good situation. To get IDs that exist in
|
174
|
+
the index but not the database, you can use the +index_orphans+ method; to
|
175
|
+
remove those documents from the index, use +clean_index_orphans+. Note that
|
176
|
+
neither of these operations should be needed if Sunspot and Sunspot::Rails are
|
177
|
+
used as intended.
|
178
|
+
|
179
|
+
|
180
|
+
== Testing Solr integration using RSpec
|
181
|
+
|
182
|
+
To disable the sunspot-solr integration for your active record models, add the
|
183
|
+
following line to your spec_helper.rb
|
184
|
+
|
185
|
+
require 'sunspot/spec/extension'
|
186
|
+
|
187
|
+
This will disable all automatic after_save/after_destroy solr-requests generated
|
188
|
+
via the #searchable method. This will not disable/mock explicit calls in your code.
|
189
|
+
|
190
|
+
If you want to test the sunspot-solr integration with active record, you can
|
191
|
+
reenable the after_save/after_destroy hooks by adding 'integrate_sunspot' in your
|
192
|
+
examples.
|
193
|
+
|
194
|
+
describe Searches do
|
195
|
+
integrate_sunspot
|
196
|
+
|
197
|
+
before(:each) do
|
198
|
+
@movie = Factory.create :movie
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should find a movie" do
|
202
|
+
Movie.search { keywords @movie.title }.first.should == @movie
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
== Further Reading
|
209
|
+
|
210
|
+
Reading the {Sunspot documentation}[http://outoftime.github.com/sunspot/docs] is
|
211
|
+
highly recommended. Sunspot::Rails exists to wrap Sunspot with a Rails-friendly
|
212
|
+
API, but almost all of the functionality you use in Sunspot::Rails is
|
213
|
+
implemented in Sunspot.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), "VERSION"))
|
2
|
+
|
3
|
+
desc "Build the websolr-sunspot_rails gem for local testing"
|
4
|
+
task :build do
|
5
|
+
system "gem build websolr-sunspot_rails_geoding.gemspec"
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Release the websolr-sunspot_rails_geoding gem"
|
9
|
+
task :release => :build do
|
10
|
+
version_tag = "v#{VERSION}"
|
11
|
+
system "git tag -am 'Release version #{VERSION}' '#{version_tag}'"
|
12
|
+
system "git push -f origin #{version_tag}:#{version_tag}"
|
13
|
+
system "gem push websolr-sunspot_rails_geoding-#{VERSION}.gem"
|
14
|
+
FileUtils.rm("websolr-sunspot_rails_geoding-#{VERSION}.gem")
|
15
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), "VERSION"))
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{websolr-sunspot4heroku-cis}
|
6
|
+
s.version = VERSION
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.authors = ["Sapna Jadon", "CISROR Team" ]
|
10
|
+
s.date = %q{2013-10-31}
|
11
|
+
s.description = %q{websolr with geocoding for heroku}
|
12
|
+
s.email = %q{jadon.sapna11@gmail.com}
|
13
|
+
s.files = [
|
14
|
+
".document",
|
15
|
+
".gitignore",
|
16
|
+
"README.rdoc",
|
17
|
+
"Rakefile",
|
18
|
+
"VERSION",
|
19
|
+
"lib/websolr-sunspot4heroku.rb",
|
20
|
+
"websolr-sunspot4heroku-cis.gemspec"
|
21
|
+
]
|
22
|
+
|
23
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
s.rubygems_version = %q{1.3.6}
|
26
|
+
s.summary = %q{websolr with geocoding for heroku}
|
27
|
+
|
28
|
+
if s.respond_to? :specification_version then
|
29
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
30
|
+
s.specification_version = 3
|
31
|
+
|
32
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
33
|
+
s.add_runtime_dependency(%q<sunspot_rails>)
|
34
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
35
|
+
else
|
36
|
+
s.add_dependency(%q<sunspot_rails>)
|
37
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
38
|
+
end
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<sunspot_rails>)
|
41
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: websolr-sunspot4heroku-cis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sapna Jadon
|
9
|
+
- CISROR Team
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sunspot_rails
|
17
|
+
requirement: &7638340 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *7638340
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &7636620 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *7636620
|
37
|
+
description: websolr with geocoding for heroku
|
38
|
+
email: jadon.sapna11@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .document
|
44
|
+
- .gitignore
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- lib/websolr-sunspot4heroku.rb
|
49
|
+
- websolr-sunspot4heroku-cis.gemspec
|
50
|
+
homepage:
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --charset=UTF-8
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.11
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: websolr with geocoding for heroku
|
75
|
+
test_files: []
|