indextank 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/indextank.rb +1 -1
- data/lib/indextank/document.rb +3 -16
- data/lib/indextank/function.rb +2 -22
- data/lib/indextank/index.rb +46 -1
- metadata +3 -16
data/lib/indextank.rb
CHANGED
@@ -5,7 +5,7 @@ directory = File.expand_path(File.dirname(__FILE__))
|
|
5
5
|
require File.join(directory, 'indextank', 'client')
|
6
6
|
|
7
7
|
module IndexTank
|
8
|
-
VERSION = "0.0.
|
8
|
+
VERSION = "0.0.6"
|
9
9
|
|
10
10
|
def self.setup_connection(url, &block)
|
11
11
|
@conn = Faraday::Connection.new(:url => url) do |builder|
|
data/lib/indextank/document.rb
CHANGED
@@ -7,7 +7,7 @@ module IndexTank
|
|
7
7
|
|
8
8
|
def initialize(document_url, docid)
|
9
9
|
@docid = docid
|
10
|
-
builder = Proc.new { |builder| builder.use
|
10
|
+
builder = Proc.new { |builder| builder.use DocumentResponseMiddleware }
|
11
11
|
@conn = IndexTank.setup_connection(document_url, &builder)
|
12
12
|
end
|
13
13
|
|
@@ -59,22 +59,9 @@ module IndexTank
|
|
59
59
|
|
60
60
|
resp.status
|
61
61
|
end
|
62
|
-
#private
|
63
|
-
# Handles standard returns status. All methods on documents should return HTTP 200,
|
64
|
-
# and the errors are 'common' for any other value
|
65
|
-
#def handle_return_status(status)
|
66
|
-
# case status
|
67
|
-
# when 400
|
68
|
-
# raise InvalidArgument
|
69
|
-
# when 409
|
70
|
-
# raise IndexInitializing
|
71
|
-
# when 404
|
72
|
-
# raise IndexNotFound
|
73
|
-
# end
|
74
|
-
#end
|
75
62
|
end
|
76
63
|
|
77
|
-
class
|
64
|
+
class DocumentResponseMiddleware < Faraday::Response::Middleware
|
78
65
|
def self.register_on_complete(env)
|
79
66
|
env[:response].on_complete do |finished_env|
|
80
67
|
case finished_env[:status]
|
@@ -85,7 +72,7 @@ module IndexTank
|
|
85
72
|
when 404
|
86
73
|
raise NonExistentIndex
|
87
74
|
when 400
|
88
|
-
raise InvalidArgument
|
75
|
+
raise InvalidArgument, finished_env[:body]
|
89
76
|
end
|
90
77
|
end
|
91
78
|
end
|
data/lib/indextank/function.rb
CHANGED
@@ -8,7 +8,8 @@ module IndexTank
|
|
8
8
|
@uri = "#{function_url}/#{index}"
|
9
9
|
@index = index
|
10
10
|
@definition = definition
|
11
|
-
|
11
|
+
# Function and Document have the same Response statuses .. so borrow DocumentResponseMiddleware
|
12
|
+
builder = Proc.new { |builder| builder.use IndexTank::DocumentResponseMiddleware }
|
12
13
|
@conn = IndexTank.setup_connection(@uri, &builder)
|
13
14
|
end
|
14
15
|
|
@@ -35,25 +36,4 @@ module IndexTank
|
|
35
36
|
self.definition == other.definition
|
36
37
|
end
|
37
38
|
end
|
38
|
-
class ResponseDocument < Faraday::Response::Middleware
|
39
|
-
def self.register_on_complete(env)
|
40
|
-
env[:response].on_complete do |finished_env|
|
41
|
-
case finished_env[:status]
|
42
|
-
when 401
|
43
|
-
raise InvalidApiKey
|
44
|
-
when 409
|
45
|
-
raise IndexInitializing
|
46
|
-
when 404
|
47
|
-
raise NonExistentIndex
|
48
|
-
when 400
|
49
|
-
raise InvalidArgument
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def initialize(app)
|
55
|
-
super
|
56
|
-
@parser = nil
|
57
|
-
end
|
58
|
-
end
|
59
39
|
end
|
data/lib/indextank/index.rb
CHANGED
@@ -69,15 +69,60 @@ module IndexTank
|
|
69
69
|
# for this query
|
70
70
|
# :variables => a hash int => float, with variables that can be later
|
71
71
|
# used in scoring :function
|
72
|
+
# :category_filters => a hash to filter the query based on document categories. Keys represent category names.
|
73
|
+
# see http://indextank.com/documentation/ruby-client#faceting
|
74
|
+
#
|
75
|
+
# Example:
|
76
|
+
# category_filters => {:size => "big", :price => "expensive"}
|
77
|
+
# means that only documents that have "big" as size category and "expensive" as price category
|
78
|
+
# will match the query
|
79
|
+
# :docvar_filters => a hash with int keys and Array values to filter the query based on document variables.
|
80
|
+
# see http://indextank.com/documentation/ruby-client#range_queries
|
81
|
+
#
|
82
|
+
# Example:
|
83
|
+
# docvar_filters = { 1 => [ [2, 3], [5, nil] ]}
|
84
|
+
# means that only documents with document variable number 1 between 2 and 3 or bigger than 5
|
85
|
+
# will match the query.
|
86
|
+
# :function_filters => a hash with int keys and Array values to filter the query based on scoring functions.
|
87
|
+
# see http://indextank.com/documentation/ruby-client#range_queries
|
88
|
+
#
|
89
|
+
# Example:
|
90
|
+
# function_filters = { 3 => [ [nil, 2], [5, 7], [8,14] ]}
|
91
|
+
# means that only documents whose score calculated by scoring function 3 is lower than 2,
|
92
|
+
# between 5 and 7 or between 8 and 14 will match the query.
|
72
93
|
def search(query, options = {})
|
73
94
|
options = {:start => 0, :len => 10 }.merge(options).merge(:q => query)
|
74
95
|
if options[:variables]
|
75
96
|
options[:variables].each_pair { |k, v| options.merge!( :"var#{k}" => v ) }
|
97
|
+
options.delete :variables
|
98
|
+
end
|
99
|
+
|
100
|
+
if options[:docvar_filters]
|
101
|
+
# go from { 3 => [ [1, 3], [5, nil] ]} to filter_docvar3 => 1:3,5:*
|
102
|
+
options[:docvar_filters].each_pair { |k, v|
|
103
|
+
rng = v.map { |val|
|
104
|
+
raise ArgumentError, "using a range with bound count != 2" unless val.length == 2
|
105
|
+
"#{val[0] || '*'}:#{val[1] || '*'}"
|
106
|
+
}.join ","
|
107
|
+
options.merge!( :"filter_docvar#{k}" => rng )
|
108
|
+
}
|
109
|
+
options.delete :docvar_filters
|
110
|
+
end
|
111
|
+
|
112
|
+
if options[:function_filters]
|
113
|
+
# go from { 2 => [ [1 , 3],[5,8] ]} to filter_function2 => 1:3,5:8
|
114
|
+
options[:function_filters].each_pair { |k, v|
|
115
|
+
rng = v.map { |val|
|
116
|
+
raise ArgumentError, "using a range with bound count != 2" unless val.length == 2
|
117
|
+
"#{val[0] || '*'}:#{val[1] || '*'}"
|
118
|
+
}.join ","
|
119
|
+
options.merge!( :"filter_function#{k}" => rng )
|
120
|
+
}
|
121
|
+
options.delete :function_filters
|
76
122
|
end
|
77
123
|
|
78
124
|
if options[:category_filters]
|
79
125
|
options[:category_filters] = options[:category_filters].to_json
|
80
|
-
p options[:category_filters]
|
81
126
|
end
|
82
127
|
|
83
128
|
response = @conn.get do |req|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indextank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 21
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Santiago Perez
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
18
|
+
date: 2011-01-04 00:00:00 -03:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
@@ -27,7 +26,6 @@ dependencies:
|
|
27
26
|
requirements:
|
28
27
|
- - "="
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 7
|
31
29
|
segments:
|
32
30
|
- 1
|
33
31
|
- 4
|
@@ -43,7 +41,6 @@ dependencies:
|
|
43
41
|
requirements:
|
44
42
|
- - ">="
|
45
43
|
- !ruby/object:Gem::Version
|
46
|
-
hash: 62196421
|
47
44
|
segments:
|
48
45
|
- 2
|
49
46
|
- 0
|
@@ -61,7 +58,6 @@ dependencies:
|
|
61
58
|
requirements:
|
62
59
|
- - ">="
|
63
60
|
- !ruby/object:Gem::Version
|
64
|
-
hash: 62196421
|
65
61
|
segments:
|
66
62
|
- 2
|
67
63
|
- 0
|
@@ -79,7 +75,6 @@ dependencies:
|
|
79
75
|
requirements:
|
80
76
|
- - "="
|
81
77
|
- !ruby/object:Gem::Version
|
82
|
-
hash: 33
|
83
78
|
segments:
|
84
79
|
- 0
|
85
80
|
- 10
|
@@ -95,7 +90,6 @@ dependencies:
|
|
95
90
|
requirements:
|
96
91
|
- - "="
|
97
92
|
- !ruby/object:Gem::Version
|
98
|
-
hash: 49
|
99
93
|
segments:
|
100
94
|
- 0
|
101
95
|
- 8
|
@@ -111,7 +105,6 @@ dependencies:
|
|
111
105
|
requirements:
|
112
106
|
- - ">="
|
113
107
|
- !ruby/object:Gem::Version
|
114
|
-
hash: 3
|
115
108
|
segments:
|
116
109
|
- 0
|
117
110
|
version: "0"
|
@@ -125,7 +118,6 @@ dependencies:
|
|
125
118
|
requirements:
|
126
119
|
- - "="
|
127
120
|
- !ruby/object:Gem::Version
|
128
|
-
hash: 17
|
129
121
|
segments:
|
130
122
|
- 0
|
131
123
|
- 3
|
@@ -141,7 +133,6 @@ dependencies:
|
|
141
133
|
requirements:
|
142
134
|
- - ">="
|
143
135
|
- !ruby/object:Gem::Version
|
144
|
-
hash: 3
|
145
136
|
segments:
|
146
137
|
- 0
|
147
138
|
version: "0"
|
@@ -155,7 +146,6 @@ dependencies:
|
|
155
146
|
requirements:
|
156
147
|
- - "="
|
157
148
|
- !ruby/object:Gem::Version
|
158
|
-
hash: 13
|
159
149
|
segments:
|
160
150
|
- 0
|
161
151
|
- 7
|
@@ -171,7 +161,6 @@ dependencies:
|
|
171
161
|
requirements:
|
172
162
|
- - "="
|
173
163
|
- !ruby/object:Gem::Version
|
174
|
-
hash: 11
|
175
164
|
segments:
|
176
165
|
- 1
|
177
166
|
- 4
|
@@ -215,7 +204,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
215
204
|
requirements:
|
216
205
|
- - ">="
|
217
206
|
- !ruby/object:Gem::Version
|
218
|
-
hash: 3
|
219
207
|
segments:
|
220
208
|
- 0
|
221
209
|
version: "0"
|
@@ -224,7 +212,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
212
|
requirements:
|
225
213
|
- - ">="
|
226
214
|
- !ruby/object:Gem::Version
|
227
|
-
hash: 3
|
228
215
|
segments:
|
229
216
|
- 0
|
230
217
|
version: "0"
|