tire-contrib 0.0.3.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +18 -6
- data/Rakefile +8 -0
- data/lib/tire/README.markdown +3 -0
- data/lib/tire/queries/more_like_this/more_like_this.rb +30 -0
- data/lib/tire/queries/more_like_this.rb +43 -0
- data/lib/tire/{rails-logger → rails/logger}/controller_runtime.rb +0 -0
- data/lib/tire/rails/logger/instrumentation.rb +19 -0
- data/lib/tire/{rails-logger → rails/logger}/log_subscriber.rb +0 -0
- data/lib/tire/{rails-logger → rails/logger}/railtie.rb +3 -3
- data/lib/tire/{rails-logger.rb → rails/logger.rb} +3 -3
- data/lib/tire-contrib/README.markdown +2 -0
- data/lib/tire-contrib/version.rb +1 -1
- data/lib/tire-contrib.rb +3 -4
- data/test/queries/more_like_this/more_like_this_test.rb +37 -0
- data/test/{rails-logger → rails/logger}/active_record_article.rb +0 -0
- data/test/{rails-logger → rails/logger}/log_subscriber_test.rb +1 -1
- data/tire-contrib.gemspec +3 -2
- metadata +44 -27
- data/lib/tire/rails-logger/instrumentation.rb +0 -21
data/README.markdown
CHANGED
@@ -1,15 +1,27 @@
|
|
1
1
|
Tire Contributed Components
|
2
2
|
================================
|
3
3
|
|
4
|
-
|
5
|
-
Rubygem for _ElasticSearch_.
|
4
|
+
Extension, additions, other utilities for the [_Tire_](http://karmi.github.com/tire/)
|
5
|
+
Rubygem for [_ElasticSearch_](http://www.elasticsearch.org/).
|
6
6
|
|
7
|
-
|
7
|
+
Add this to your _Gemfile_:
|
8
8
|
|
9
|
-
|
10
|
-
------------
|
9
|
+
gem 'tire-contrib'
|
11
10
|
|
12
|
-
|
11
|
+
Then require the component you want to use in your application initializer. For example:
|
12
|
+
|
13
|
+
require 'tire/rails/logger'
|
14
|
+
|
15
|
+
See specific files and folders inside the `lib/tire` folder for instructions and documentation.
|
16
|
+
|
17
|
+
|
18
|
+
### More Like This Queries ###
|
19
|
+
|
20
|
+
Adds support for [“more like this”](http://www.elasticsearch.org/guide/reference/query-dsl/mlt-query.html) queries.
|
21
|
+
|
22
|
+
### Rails Logger ###
|
23
|
+
|
24
|
+
Adds support for displaying Tire related statistics in the Rails' log.
|
13
25
|
|
14
26
|
-----
|
15
27
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Tire
|
2
|
+
module Search
|
3
|
+
module MoreLikeThis
|
4
|
+
def more_like_this(like_text, options = {})
|
5
|
+
@value = {:mlt => {:like_text => like_text}}
|
6
|
+
@value[:mlt].update(validate_more_like_this_options(options))
|
7
|
+
@value
|
8
|
+
end
|
9
|
+
|
10
|
+
def more_like_this_field(field, like_text, options = {})
|
11
|
+
@value = {:mlt_field => {field => {:like_text => like_text}}}
|
12
|
+
# :fields is invalid in this context. Better than doing some kind of meta-black magic.
|
13
|
+
options.delete(:fields)
|
14
|
+
@value[:mlt_field][field].update(validate_more_like_this_options(options))
|
15
|
+
@value
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :mlt, :more_like_this
|
19
|
+
alias_method :mlt_field, :more_like_this_field
|
20
|
+
|
21
|
+
private
|
22
|
+
def validate_more_like_this_options(options)
|
23
|
+
valid_options = [:fields, :percent_terms_to_match, :min_term_freq,
|
24
|
+
:max_query_terms, :stop_words, :min_doc_freq, :max_doc_freq,
|
25
|
+
:min_word_len, :max_word_len, :boost_terms, :boost, :analyzer]
|
26
|
+
options.delete_if { |key, value| !valid_options.member? key }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# More Like This
|
2
|
+
# ==============
|
3
|
+
#
|
4
|
+
# Author: Mereghost <marcello.rocha@gmail.com>
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# Adds support for "more_like_this" and "more_like_this_field" queries in Tire DSL.
|
8
|
+
#
|
9
|
+
# It hooks into the Query class and inserts the more_like_this and more_like_this_field query types.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
# Usage:
|
13
|
+
# ------
|
14
|
+
#
|
15
|
+
# Require the component:
|
16
|
+
#
|
17
|
+
# require 'tire/queries/more_like_this'
|
18
|
+
#
|
19
|
+
# From that point on you should have the more_like_this (aliased to mlt) and
|
20
|
+
# the more_like_this_field (aliased to mlt_field) queries available.
|
21
|
+
#
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
# -------
|
25
|
+
#
|
26
|
+
# Tire.search 'articles' do
|
27
|
+
# query do
|
28
|
+
# more_like_this 'search for similar text'
|
29
|
+
# more_like_this_field :field_name, 'similar text'
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# For available options for these queries see:
|
34
|
+
#
|
35
|
+
# * <http://www.elasticsearch.org/guide/reference/query-dsl/mlt-query.html>
|
36
|
+
# * <http://www.elasticsearch.org/guide/reference/query-dsl/mlt-field-query.html>
|
37
|
+
#
|
38
|
+
#
|
39
|
+
require 'tire/queries/more_like_this/more_like_this'
|
40
|
+
|
41
|
+
Tire::Search::Query.class_eval do
|
42
|
+
include Tire::Search::MoreLikeThis
|
43
|
+
end
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Tire
|
2
|
+
module Rails
|
3
|
+
module Instrumentation
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
alias_method_chain :perform, :instrumentation
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform_with_instrumentation
|
11
|
+
# Wrapper around the Search.perform method that logs search times.
|
12
|
+
#
|
13
|
+
ActiveSupport::Notifications.instrument("search.tire", :name => 'Search', :search => self.to_json) do
|
14
|
+
perform_without_instrumentation
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
File without changes
|
@@ -3,9 +3,9 @@ module Tire
|
|
3
3
|
class Railtie < ::Rails::Railtie
|
4
4
|
|
5
5
|
initializer "tire.initializer" do |app|
|
6
|
-
require 'tire/rails
|
7
|
-
require 'tire/rails
|
8
|
-
require 'tire/rails
|
6
|
+
require 'tire/rails/logger/instrumentation'
|
7
|
+
require 'tire/rails/logger/log_subscriber'
|
8
|
+
require 'tire/rails/logger/controller_runtime'
|
9
9
|
|
10
10
|
# Inject instrumentation into Tire::Search
|
11
11
|
#
|
@@ -14,17 +14,17 @@
|
|
14
14
|
#
|
15
15
|
# Require the component in your `application.rb`:
|
16
16
|
#
|
17
|
-
# require 'tire/rails
|
17
|
+
# require 'tire/rails/logger'
|
18
18
|
#
|
19
19
|
# You should see an output like this in your application log:
|
20
20
|
#
|
21
21
|
# Started GET "/articles?utf8=%E2%9C%93&q=bull*&commit=search" for 127.0.0.1 at 2011-09-15 19:07:00 +0200
|
22
22
|
# Processing by ArticlesController#index as HTML
|
23
23
|
# Parameters: {"utf8"=>"✓", "q"=>"bull*", "commit"=>"search"}
|
24
|
-
#
|
24
|
+
# Search (6.7ms) {"query":{"query_string":{"query":"bull*"}}}
|
25
25
|
# Article Load (0.3ms) SELECT `articles`.* FROM `articles` WHERE `articles`.`id` IN (104126575)
|
26
26
|
# Rendered articles/index.html.erb within layouts/application (13.0ms)
|
27
27
|
# Completed 200 OK in 63ms (Views: 53.7ms | ActiveRecord: 1.8ms | Tire: 6.7ms)
|
28
28
|
#
|
29
29
|
#
|
30
|
-
require 'tire/rails
|
30
|
+
require 'tire/rails/logger/railtie'
|
data/lib/tire-contrib/version.rb
CHANGED
data/lib/tire-contrib.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'tire'
|
2
|
+
require 'tire/queries/more_like_this'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
module Tire
|
6
|
+
module Search
|
7
|
+
class MoreLikeThisTest < Test::Unit::TestCase
|
8
|
+
context "More Like This queries" do
|
9
|
+
should "search for similar documents" do
|
10
|
+
assert_equal({:mlt => {:like_text => 'similar text'}}, Query.new.mlt('similar text'))
|
11
|
+
end
|
12
|
+
|
13
|
+
should "allow to pass a list of fields to a mlt query" do
|
14
|
+
assert_equal({:mlt => {:like_text => 'similar text', :fields => ['foo', 'bar.baz']}},
|
15
|
+
Query.new.mlt('similar text', :fields => ['foo', 'bar.baz']))
|
16
|
+
assert_equal({:mlt => {:like_text => 'similar text', :fields => ['foo', 'bar.baz'], :min_term_freq => 3}},
|
17
|
+
Query.new.mlt('similar text', :fields => ['foo', 'bar.baz'], :min_term_freq => 3))
|
18
|
+
end
|
19
|
+
|
20
|
+
should "search for similar text on a selected field (mlt_field)" do
|
21
|
+
assert_equal({:mlt_field => {:foo => {:like_text => 'similar text'}}},
|
22
|
+
Query.new.mlt_field(:foo, 'similar text'))
|
23
|
+
assert_equal({:mlt_field => {:foo => {:like_text => 'similar text', :min_term_freq => 1}}},
|
24
|
+
Query.new.mlt_field(:foo, 'similar text', :min_term_freq => 1))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context "validate the options passed" do
|
28
|
+
should "drop all the invalid keys" do
|
29
|
+
assert_equal({:mlt => {:like_text => 'similar text', :fields => ['foo', 'bar.baz']}},
|
30
|
+
Query.new.mlt('similar text', :fields => ['foo', 'bar.baz'], :foo => :bar))
|
31
|
+
assert_equal({:mlt_field => {:foo => {:like_text => 'similar text'}}},
|
32
|
+
Query.new.mlt_field(:foo, 'similar text', :fields => [:bar]))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
data/tire-contrib.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency "turn"
|
20
20
|
s.add_development_dependency "shoulda"
|
21
21
|
s.add_development_dependency "mocha"
|
22
|
-
s.add_development_dependency "
|
23
|
-
s.add_development_dependency "
|
22
|
+
s.add_development_dependency "activerecord"
|
23
|
+
s.add_development_dependency "activesupport"
|
24
|
+
s.add_development_dependency "sqlite3"
|
24
25
|
|
25
26
|
s.extra_rdoc_files = [ "README.markdown", "MIT-LICENSE" ]
|
26
27
|
s.rdoc_options = [ "--charset=UTF-8" ]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tire-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tire
|
17
|
-
requirement: &
|
17
|
+
requirement: &70240919138540 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70240919138540
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &70240919135160 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.1.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70240919135160
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: turn
|
39
|
-
requirement: &
|
39
|
+
requirement: &70240919151640 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70240919151640
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: shoulda
|
50
|
-
requirement: &
|
50
|
+
requirement: &70240919149000 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70240919149000
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: mocha
|
61
|
-
requirement: &
|
61
|
+
requirement: &70240919148260 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,10 +66,10 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70240919148260
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
72
|
-
requirement: &
|
71
|
+
name: activerecord
|
72
|
+
requirement: &70240919146940 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ! '>='
|
@@ -77,10 +77,10 @@ dependencies:
|
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
|
-
version_requirements: *
|
80
|
+
version_requirements: *70240919146940
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
83
|
-
requirement: &
|
82
|
+
name: activesupport
|
83
|
+
requirement: &70240919160100 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
86
|
- - ! '>='
|
@@ -88,7 +88,18 @@ dependencies:
|
|
88
88
|
version: '0'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
|
-
version_requirements: *
|
91
|
+
version_requirements: *70240919160100
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: sqlite3
|
94
|
+
requirement: &70240919157720 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *70240919157720
|
92
103
|
description:
|
93
104
|
email:
|
94
105
|
- karmi@karmi.cz
|
@@ -105,14 +116,19 @@ files:
|
|
105
116
|
- README.markdown
|
106
117
|
- Rakefile
|
107
118
|
- lib/tire-contrib.rb
|
119
|
+
- lib/tire-contrib/README.markdown
|
108
120
|
- lib/tire-contrib/version.rb
|
109
|
-
- lib/tire/
|
110
|
-
- lib/tire/
|
111
|
-
- lib/tire/
|
112
|
-
- lib/tire/rails
|
113
|
-
- lib/tire/rails
|
114
|
-
-
|
115
|
-
-
|
121
|
+
- lib/tire/README.markdown
|
122
|
+
- lib/tire/queries/more_like_this.rb
|
123
|
+
- lib/tire/queries/more_like_this/more_like_this.rb
|
124
|
+
- lib/tire/rails/logger.rb
|
125
|
+
- lib/tire/rails/logger/controller_runtime.rb
|
126
|
+
- lib/tire/rails/logger/instrumentation.rb
|
127
|
+
- lib/tire/rails/logger/log_subscriber.rb
|
128
|
+
- lib/tire/rails/logger/railtie.rb
|
129
|
+
- test/queries/more_like_this/more_like_this_test.rb
|
130
|
+
- test/rails/logger/active_record_article.rb
|
131
|
+
- test/rails/logger/log_subscriber_test.rb
|
116
132
|
- test/test_helper.rb
|
117
133
|
- tire-contrib.gemspec
|
118
134
|
homepage: ''
|
@@ -141,7 +157,8 @@ signing_key:
|
|
141
157
|
specification_version: 3
|
142
158
|
summary: Contributions and additions for the Tire gem
|
143
159
|
test_files:
|
144
|
-
- test/
|
145
|
-
- test/rails
|
160
|
+
- test/queries/more_like_this/more_like_this_test.rb
|
161
|
+
- test/rails/logger/active_record_article.rb
|
162
|
+
- test/rails/logger/log_subscriber_test.rb
|
146
163
|
- test/test_helper.rb
|
147
164
|
has_rdoc:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Tire
|
2
|
-
module Rails
|
3
|
-
module Instrumentation
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
alias_method_chain :perform, :instrumentation
|
8
|
-
end
|
9
|
-
|
10
|
-
module InstanceMethods
|
11
|
-
def perform_with_instrumentation
|
12
|
-
# Wrapper around the Search.perform method that logs search times.
|
13
|
-
#
|
14
|
-
ActiveSupport::Notifications.instrument("search.tire", :name => 'Search', :search => self.to_json) do
|
15
|
-
perform_without_instrumentation
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|