elastic_searchable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/elastic_searchable.gemspec +85 -0
- data/lib/elastic_searchable.rb +13 -0
- data/lib/elastic_searchable/active_record.rb +56 -0
- data/lib/elastic_searchable/callbacks.rb +28 -0
- data/lib/elastic_searchable/index.rb +41 -0
- data/lib/elastic_searchable/queries.rb +67 -0
- data/test/database.yml +3 -0
- data/test/helper.rb +22 -0
- data/test/test_elastic_searchable.rb +55 -0
- metadata +238 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
gem "activerecord", "~> 2.3.5"
|
4
|
+
gem 'rubberband', '~> 0.0.6'
|
5
|
+
gem 'backgrounded', '~> 0.7.0'
|
6
|
+
gem 'will_paginate', '~> 2.3.15'
|
7
|
+
gem 'larsklevan-after_commit', '~> 1.0.5', :require => 'after_commit'
|
8
|
+
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "shoulda", ">= 0"
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.5.2"
|
16
|
+
gem "rcov", ">= 0"
|
17
|
+
gem 'sqlite3-ruby', '~> 1.3.2'
|
18
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Ryan Sonnek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= elastic_searchable
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to elastic_searchable
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Ryan Sonnek. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "elastic_searchable"
|
16
|
+
gem.homepage = "http://github.com/wireframe/elastic_searchable"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{elastic search for activerecord}
|
19
|
+
gem.description = %Q{integrate the elastic search engine with rails}
|
20
|
+
gem.email = "ryan@codecrate.com"
|
21
|
+
gem.authors = ["Ryan Sonnek"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "elastic_searchable #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{elastic_searchable}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Sonnek"]
|
12
|
+
s.date = %q{2011-01-25}
|
13
|
+
s.description = %q{integrate the elastic search engine with rails}
|
14
|
+
s.email = %q{ryan@codecrate.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"elastic_searchable.gemspec",
|
27
|
+
"lib/elastic_searchable.rb",
|
28
|
+
"lib/elastic_searchable/active_record.rb",
|
29
|
+
"lib/elastic_searchable/callbacks.rb",
|
30
|
+
"lib/elastic_searchable/index.rb",
|
31
|
+
"lib/elastic_searchable/queries.rb",
|
32
|
+
"test/database.yml",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/test_elastic_searchable.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/wireframe/elastic_searchable}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.4.2}
|
40
|
+
s.summary = %q{elastic search for activerecord}
|
41
|
+
s.test_files = [
|
42
|
+
"test/helper.rb",
|
43
|
+
"test/test_elastic_searchable.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.5"])
|
51
|
+
s.add_runtime_dependency(%q<rubberband>, ["~> 0.0.6"])
|
52
|
+
s.add_runtime_dependency(%q<backgrounded>, ["~> 0.7.0"])
|
53
|
+
s.add_runtime_dependency(%q<will_paginate>, ["~> 2.3.15"])
|
54
|
+
s.add_runtime_dependency(%q<larsklevan-after_commit>, ["~> 1.0.5"])
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
62
|
+
s.add_dependency(%q<rubberband>, ["~> 0.0.6"])
|
63
|
+
s.add_dependency(%q<backgrounded>, ["~> 0.7.0"])
|
64
|
+
s.add_dependency(%q<will_paginate>, ["~> 2.3.15"])
|
65
|
+
s.add_dependency(%q<larsklevan-after_commit>, ["~> 1.0.5"])
|
66
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
s.add_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
74
|
+
s.add_dependency(%q<rubberband>, ["~> 0.0.6"])
|
75
|
+
s.add_dependency(%q<backgrounded>, ["~> 0.7.0"])
|
76
|
+
s.add_dependency(%q<will_paginate>, ["~> 2.3.15"])
|
77
|
+
s.add_dependency(%q<larsklevan-after_commit>, ["~> 1.0.5"])
|
78
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
79
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
80
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
81
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
82
|
+
s.add_dependency(%q<sqlite3-ruby>, ["~> 1.3.2"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubberband'
|
2
|
+
require 'elastic_searchable/active_record'
|
3
|
+
|
4
|
+
module ElasticSearchable
|
5
|
+
class << self
|
6
|
+
attr_accessor :searcher
|
7
|
+
def searcher
|
8
|
+
@searcher ||= ElasticSearch.new("localhost:9200")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveRecord::Base.send(:include, ElasticSearchable::ActiveRecord)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'after_commit'
|
3
|
+
require 'backgrounded'
|
4
|
+
require 'elastic_searchable/queries'
|
5
|
+
require 'elastic_searchable/callbacks'
|
6
|
+
require 'elastic_searchable/index'
|
7
|
+
|
8
|
+
module ElasticSearchable
|
9
|
+
module ActiveRecord
|
10
|
+
def self.included(base)
|
11
|
+
base.send :extend, ClassMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
attr_accessor :index_name
|
16
|
+
attr_accessor :elastic_search_type
|
17
|
+
|
18
|
+
# Valid options:
|
19
|
+
# :index_name (will default class name using method "underscore")
|
20
|
+
def elastic_searchable(options = {})
|
21
|
+
options.symbolize_keys!
|
22
|
+
|
23
|
+
@index_name = options[:index_name] || self.name.underscore.gsub(/\//,'-')
|
24
|
+
@elastic_search_type = options[:elastic_search_type] || self.name.underscore.singularize.gsub(/\//,'-')
|
25
|
+
|
26
|
+
@index_options = options[:index_options] || {}
|
27
|
+
@mapping = options[:mapping] || false
|
28
|
+
|
29
|
+
extend ElasticSearchable::ActiveRecord::Index
|
30
|
+
extend ElasticSearchable::Queries
|
31
|
+
|
32
|
+
include ElasticSearchable::ActiveRecord::InstanceMethods
|
33
|
+
include ElasticSearchable::Callbacks
|
34
|
+
|
35
|
+
add_indexing_callbacks
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module InstanceMethods
|
40
|
+
# build json document to index in elasticsearch
|
41
|
+
# default implementation simply calls to_json
|
42
|
+
# implementations can override this method to index custom content
|
43
|
+
def indexed_json_document
|
44
|
+
self.to_json
|
45
|
+
end
|
46
|
+
def local_index_in_elastic_search(options = {})
|
47
|
+
options[:id] ||= self.id.to_s
|
48
|
+
document = self.indexed_json_document
|
49
|
+
ElasticSearchable.searcher.index document, self.class.elastic_search_options(options)
|
50
|
+
|
51
|
+
self.run_callbacks("after_index_on_#{options[:lifecycle]}".to_sym) if options[:lifecycle]
|
52
|
+
self.run_callbacks(:after_index)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ElasticSearchable
|
2
|
+
module Callbacks
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def add_indexing_callbacks
|
9
|
+
backgrounded :update_index_on_create => {:queue => 'searchindex'}, :update_index_on_update => {:queue => 'searchindex'}
|
10
|
+
class << self
|
11
|
+
backgrounded :delete_id_from_index => {:queue => 'searchindex'}
|
12
|
+
end
|
13
|
+
|
14
|
+
define_callbacks :after_index_on_create, :after_index_on_update, :after_index
|
15
|
+
after_commit_on_create :update_index_on_create_backgrounded
|
16
|
+
after_commit_on_update :update_index_on_update_backgrounded
|
17
|
+
after_commit_on_destroy Proc.new {|o| o.class.delete_id_from_index_backgrounded(o.id) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_index_on_create
|
22
|
+
local_index_in_elastic_search :lifecycle => :create
|
23
|
+
end
|
24
|
+
def update_index_on_update
|
25
|
+
local_index_in_elastic_search :lifecycle => :update
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ElasticSearchable
|
2
|
+
module ActiveRecord
|
3
|
+
module Index
|
4
|
+
def create_index
|
5
|
+
self.delete_index
|
6
|
+
ElasticSearchable.searcher.create_index(index_name, @index_options)
|
7
|
+
self.find_each do |record|
|
8
|
+
record.local_index_in_elastic_search
|
9
|
+
end
|
10
|
+
self.refresh_index
|
11
|
+
end
|
12
|
+
|
13
|
+
# explicitly refresh the index, making all operations performed since the last refresh
|
14
|
+
# available for search
|
15
|
+
#
|
16
|
+
# http://www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/refresh/
|
17
|
+
def refresh_index
|
18
|
+
ElasticSearchable.searcher.refresh index_name
|
19
|
+
end
|
20
|
+
|
21
|
+
# deletes the index for this model
|
22
|
+
def delete_index
|
23
|
+
begin
|
24
|
+
ElasticSearchable.searcher.delete_index index_name
|
25
|
+
rescue ElasticSearch::RequestError
|
26
|
+
# it's ok, this means that the index doesn't exist
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#optimize the index
|
31
|
+
def optimize_index
|
32
|
+
ElasticSearchable.searcher.optimize index_name
|
33
|
+
end
|
34
|
+
|
35
|
+
#delete one record from the index
|
36
|
+
def delete_id_from_index(id, options = {})
|
37
|
+
ElasticSearchable.searcher.delete id.to_s, elastic_search_options(options)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'will_paginate/collection'
|
2
|
+
|
3
|
+
module ElasticSearchable
|
4
|
+
module Queries
|
5
|
+
# search_hits returns a raw ElasticSearch::Api::Hits object for the search results
|
6
|
+
# see #search for the valid options
|
7
|
+
def search_hits(query, options = {})
|
8
|
+
if query.kind_of?(Hash)
|
9
|
+
query = {:query => query}
|
10
|
+
end
|
11
|
+
ElasticSearchable.searcher.search query, elastic_search_options(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# search returns a will_paginate collection of ActiveRecord objects for the search results
|
15
|
+
#
|
16
|
+
# see ElasticSearch::Api::Index#search for the full list of valid options
|
17
|
+
#
|
18
|
+
# note that the collection may include nils if ElasticSearch returns a result hit for a
|
19
|
+
# record that has been deleted on the database
|
20
|
+
def search(query, options = {})
|
21
|
+
hits = search_hits(query, options)
|
22
|
+
results = WillPaginate::Collection.new(hits.current_page, hits.per_page, hits.total_entries)
|
23
|
+
results.replace self.find(hits.collect(&:_id))
|
24
|
+
results
|
25
|
+
end
|
26
|
+
|
27
|
+
# counts the number of results for this query.
|
28
|
+
def search_count(query = "*", options = {})
|
29
|
+
if query.kind_of?(Hash)
|
30
|
+
query = {:query => query}
|
31
|
+
end
|
32
|
+
ElasticSearchable.searcher.count query, elastic_search_options(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def facets(fields_list, options = {})
|
36
|
+
size = options.delete(:size) || 10
|
37
|
+
fields_list = [fields_list] unless fields_list.kind_of?(Array)
|
38
|
+
|
39
|
+
if !options[:query]
|
40
|
+
options[:query] = {:match_all => true}
|
41
|
+
elsif options[:query].kind_of?(String)
|
42
|
+
options[:query] = {:query_string => {:query => options[:query]}}
|
43
|
+
end
|
44
|
+
|
45
|
+
options[:facets] = {}
|
46
|
+
fields_list.each do |field|
|
47
|
+
options[:facets][field] = {:terms => {:field => field, :size => size}}
|
48
|
+
end
|
49
|
+
|
50
|
+
hits = ElasticSearchable.searcher.search options, elastic_search_options
|
51
|
+
out = {}
|
52
|
+
|
53
|
+
fields_list.each do |field|
|
54
|
+
out[field.to_sym] = {}
|
55
|
+
hits.facets[field.to_s]["terms"].each do |term|
|
56
|
+
out[field.to_sym][term["term"]] = term["count"]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
out
|
61
|
+
end
|
62
|
+
|
63
|
+
def elastic_search_options(options = {})
|
64
|
+
options.merge(:index => self.index_name, :type => self.elastic_search_type)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/test/database.yml
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'elastic_searchable'
|
16
|
+
|
17
|
+
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
18
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
19
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
20
|
+
|
21
|
+
class Test::Unit::TestCase
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
2
|
+
|
3
|
+
class TestElasticSearchable < Test::Unit::TestCase
|
4
|
+
ActiveRecord::Schema.define(:version => 1) do
|
5
|
+
create_table :posts, :force => true do |t|
|
6
|
+
t.column :title, :string
|
7
|
+
t.column :body, :string
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Post < ActiveRecord::Base
|
12
|
+
elastic_searchable
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'Post class with default elastic_searchable config' do
|
16
|
+
setup do
|
17
|
+
@clazz = Post
|
18
|
+
end
|
19
|
+
should 'respond to :search' do
|
20
|
+
assert @clazz.respond_to?(:search)
|
21
|
+
end
|
22
|
+
should 'define index_name' do
|
23
|
+
assert_equal 'test_elastic_searchable-post', @clazz.index_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'Post.create_index' do
|
28
|
+
setup do
|
29
|
+
Post.create_index
|
30
|
+
@status = ElasticSearchable.searcher.index_status Post.index_name
|
31
|
+
end
|
32
|
+
should 'have created index' do
|
33
|
+
assert @status['ok']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'creating new instance' do
|
38
|
+
setup do
|
39
|
+
Post.delete_all
|
40
|
+
@post = Post.create :title => 'foo', :body => "bar"
|
41
|
+
Post.create_index
|
42
|
+
end
|
43
|
+
context 'searching for results' do
|
44
|
+
setup do
|
45
|
+
@results = Post.search 'foo'
|
46
|
+
end
|
47
|
+
should 'find created object' do
|
48
|
+
assert_equal @post, @results.first
|
49
|
+
end
|
50
|
+
should 'be paginated' do
|
51
|
+
assert_equal 1, @results.total_entries
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: elastic_searchable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ryan Sonnek
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-25 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 5
|
33
|
+
version: 2.3.5
|
34
|
+
requirement: *id001
|
35
|
+
prerelease: false
|
36
|
+
name: activerecord
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :runtime
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 19
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
- 6
|
49
|
+
version: 0.0.6
|
50
|
+
requirement: *id002
|
51
|
+
prerelease: false
|
52
|
+
name: rubberband
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
- 7
|
64
|
+
- 0
|
65
|
+
version: 0.7.0
|
66
|
+
requirement: *id003
|
67
|
+
prerelease: false
|
68
|
+
name: backgrounded
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
type: :runtime
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 29
|
77
|
+
segments:
|
78
|
+
- 2
|
79
|
+
- 3
|
80
|
+
- 15
|
81
|
+
version: 2.3.15
|
82
|
+
requirement: *id004
|
83
|
+
prerelease: false
|
84
|
+
name: will_paginate
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
type: :runtime
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 29
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 0
|
96
|
+
- 5
|
97
|
+
version: 1.0.5
|
98
|
+
requirement: *id005
|
99
|
+
prerelease: false
|
100
|
+
name: larsklevan-after_commit
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
type: :development
|
103
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
requirement: *id006
|
113
|
+
prerelease: false
|
114
|
+
name: shoulda
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
type: :development
|
117
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
hash: 23
|
123
|
+
segments:
|
124
|
+
- 1
|
125
|
+
- 0
|
126
|
+
- 0
|
127
|
+
version: 1.0.0
|
128
|
+
requirement: *id007
|
129
|
+
prerelease: false
|
130
|
+
name: bundler
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
type: :development
|
133
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 7
|
139
|
+
segments:
|
140
|
+
- 1
|
141
|
+
- 5
|
142
|
+
- 2
|
143
|
+
version: 1.5.2
|
144
|
+
requirement: *id008
|
145
|
+
prerelease: false
|
146
|
+
name: jeweler
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
type: :development
|
149
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
requirement: *id009
|
159
|
+
prerelease: false
|
160
|
+
name: rcov
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
type: :development
|
163
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ~>
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
hash: 31
|
169
|
+
segments:
|
170
|
+
- 1
|
171
|
+
- 3
|
172
|
+
- 2
|
173
|
+
version: 1.3.2
|
174
|
+
requirement: *id010
|
175
|
+
prerelease: false
|
176
|
+
name: sqlite3-ruby
|
177
|
+
description: integrate the elastic search engine with rails
|
178
|
+
email: ryan@codecrate.com
|
179
|
+
executables: []
|
180
|
+
|
181
|
+
extensions: []
|
182
|
+
|
183
|
+
extra_rdoc_files:
|
184
|
+
- LICENSE.txt
|
185
|
+
- README.rdoc
|
186
|
+
files:
|
187
|
+
- .document
|
188
|
+
- Gemfile
|
189
|
+
- LICENSE.txt
|
190
|
+
- README.rdoc
|
191
|
+
- Rakefile
|
192
|
+
- VERSION
|
193
|
+
- elastic_searchable.gemspec
|
194
|
+
- lib/elastic_searchable.rb
|
195
|
+
- lib/elastic_searchable/active_record.rb
|
196
|
+
- lib/elastic_searchable/callbacks.rb
|
197
|
+
- lib/elastic_searchable/index.rb
|
198
|
+
- lib/elastic_searchable/queries.rb
|
199
|
+
- test/database.yml
|
200
|
+
- test/helper.rb
|
201
|
+
- test/test_elastic_searchable.rb
|
202
|
+
has_rdoc: true
|
203
|
+
homepage: http://github.com/wireframe/elastic_searchable
|
204
|
+
licenses:
|
205
|
+
- MIT
|
206
|
+
post_install_message:
|
207
|
+
rdoc_options: []
|
208
|
+
|
209
|
+
require_paths:
|
210
|
+
- lib
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
none: false
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
hash: 3
|
217
|
+
segments:
|
218
|
+
- 0
|
219
|
+
version: "0"
|
220
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
221
|
+
none: false
|
222
|
+
requirements:
|
223
|
+
- - ">="
|
224
|
+
- !ruby/object:Gem::Version
|
225
|
+
hash: 3
|
226
|
+
segments:
|
227
|
+
- 0
|
228
|
+
version: "0"
|
229
|
+
requirements: []
|
230
|
+
|
231
|
+
rubyforge_project:
|
232
|
+
rubygems_version: 1.4.2
|
233
|
+
signing_key:
|
234
|
+
specification_version: 3
|
235
|
+
summary: elastic search for activerecord
|
236
|
+
test_files:
|
237
|
+
- test/helper.rb
|
238
|
+
- test/test_elastic_searchable.rb
|