sphinx 0.9.10.2122 → 2.1.1.3711

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/.gitignore +5 -2
  2. data/.travis.yml +8 -0
  3. data/CHANGELOG.md +71 -0
  4. data/Gemfile +4 -0
  5. data/README.md +221 -0
  6. data/Rakefile +40 -35
  7. data/lib/sphinx.rb +3 -8
  8. data/lib/sphinx/client.rb +223 -70
  9. data/lib/sphinx/constants.rb +23 -8
  10. data/lib/sphinx/response.rb +6 -6
  11. data/lib/sphinx/timeout.rb +1 -2
  12. data/lib/sphinx/version.rb +3 -0
  13. data/spec/client_response_spec.rb +77 -64
  14. data/spec/client_spec.rb +68 -31
  15. data/spec/client_validations_spec.rb +61 -7
  16. data/spec/fixtures/requests/default_search.dat +0 -0
  17. data/spec/fixtures/requests/default_search_index.dat +0 -0
  18. data/spec/fixtures/requests/excerpt_custom.dat +0 -0
  19. data/spec/fixtures/requests/excerpt_default.dat +0 -0
  20. data/spec/fixtures/requests/excerpt_flags.dat +0 -0
  21. data/spec/fixtures/requests/field_weights.dat +0 -0
  22. data/spec/fixtures/requests/filter.dat +0 -0
  23. data/spec/fixtures/requests/filter_exclude.dat +0 -0
  24. data/spec/fixtures/requests/filter_float_range.dat +0 -0
  25. data/spec/fixtures/requests/filter_float_range_exclude.dat +0 -0
  26. data/spec/fixtures/requests/filter_range.dat +0 -0
  27. data/spec/fixtures/requests/filter_range_exclude.dat +0 -0
  28. data/spec/fixtures/requests/filter_range_int64.dat +0 -0
  29. data/spec/fixtures/requests/filter_ranges.dat +0 -0
  30. data/spec/fixtures/requests/filters.dat +0 -0
  31. data/spec/fixtures/requests/filters_different.dat +0 -0
  32. data/spec/fixtures/requests/geo_anchor.dat +0 -0
  33. data/spec/fixtures/requests/group_by_attr.dat +0 -0
  34. data/spec/fixtures/requests/group_by_attrpair.dat +0 -0
  35. data/spec/fixtures/requests/group_by_day.dat +0 -0
  36. data/spec/fixtures/requests/group_by_day_sort.dat +0 -0
  37. data/spec/fixtures/requests/group_by_month.dat +0 -0
  38. data/spec/fixtures/requests/group_by_week.dat +0 -0
  39. data/spec/fixtures/requests/group_by_year.dat +0 -0
  40. data/spec/fixtures/requests/group_distinct.dat +0 -0
  41. data/spec/fixtures/requests/id_range.dat +0 -0
  42. data/spec/fixtures/requests/id_range64.dat +0 -0
  43. data/spec/fixtures/requests/index_weights.dat +0 -0
  44. data/spec/fixtures/requests/keywords.dat +0 -0
  45. data/spec/fixtures/requests/limits.dat +0 -0
  46. data/spec/fixtures/requests/limits_cutoff.dat +0 -0
  47. data/spec/fixtures/requests/limits_max.dat +0 -0
  48. data/spec/fixtures/requests/limits_max_cutoff.dat +0 -0
  49. data/spec/fixtures/requests/match_all.dat +0 -0
  50. data/spec/fixtures/requests/match_any.dat +0 -0
  51. data/spec/fixtures/requests/match_boolean.dat +0 -0
  52. data/spec/fixtures/requests/match_extended.dat +0 -0
  53. data/spec/fixtures/requests/match_extended2.dat +0 -0
  54. data/spec/fixtures/requests/match_fullscan.dat +0 -0
  55. data/spec/fixtures/requests/match_phrase.dat +0 -0
  56. data/spec/fixtures/requests/max_query_time.dat +0 -0
  57. data/spec/fixtures/requests/miltiple_queries.dat +0 -0
  58. data/spec/fixtures/requests/outer_select.dat +0 -0
  59. data/spec/fixtures/requests/override.dat +0 -0
  60. data/spec/fixtures/{default_search.php → requests/php/default_search.php} +1 -1
  61. data/spec/fixtures/{default_search_index.php → requests/php/default_search_index.php} +1 -1
  62. data/spec/fixtures/{excerpt_custom.php → requests/php/excerpt_custom.php} +1 -1
  63. data/spec/fixtures/{excerpt_default.php → requests/php/excerpt_default.php} +1 -1
  64. data/spec/fixtures/{excerpt_flags.php → requests/php/excerpt_flags.php} +1 -1
  65. data/spec/fixtures/{field_weights.php → requests/php/field_weights.php} +1 -1
  66. data/spec/fixtures/{filter.php → requests/php/filter.php} +1 -1
  67. data/spec/fixtures/{filter_exclude.php → requests/php/filter_exclude.php} +1 -1
  68. data/spec/fixtures/{filter_float_range.php → requests/php/filter_float_range.php} +1 -1
  69. data/spec/fixtures/{filter_float_range_exclude.php → requests/php/filter_float_range_exclude.php} +1 -1
  70. data/spec/fixtures/{filter_range.php → requests/php/filter_range.php} +1 -1
  71. data/spec/fixtures/{filter_range_exclude.php → requests/php/filter_range_exclude.php} +1 -1
  72. data/spec/fixtures/{filter_range_int64.php → requests/php/filter_range_int64.php} +1 -1
  73. data/spec/fixtures/{filter_ranges.php → requests/php/filter_ranges.php} +1 -1
  74. data/spec/fixtures/{filters.php → requests/php/filters.php} +1 -1
  75. data/spec/fixtures/{filters_different.php → requests/php/filters_different.php} +1 -1
  76. data/spec/fixtures/{geo_anchor.php → requests/php/geo_anchor.php} +1 -1
  77. data/spec/fixtures/{group_by_attr.php → requests/php/group_by_attr.php} +1 -1
  78. data/spec/fixtures/{group_by_attrpair.php → requests/php/group_by_attrpair.php} +1 -1
  79. data/spec/fixtures/{group_by_day.php → requests/php/group_by_day.php} +1 -1
  80. data/spec/fixtures/{group_by_day_sort.php → requests/php/group_by_day_sort.php} +1 -1
  81. data/spec/fixtures/{group_by_month.php → requests/php/group_by_month.php} +1 -1
  82. data/spec/fixtures/{group_by_week.php → requests/php/group_by_week.php} +1 -1
  83. data/spec/fixtures/{group_by_year.php → requests/php/group_by_year.php} +1 -1
  84. data/spec/fixtures/{group_distinct.php → requests/php/group_distinct.php} +1 -1
  85. data/spec/fixtures/{id_range.php → requests/php/id_range.php} +1 -1
  86. data/spec/fixtures/{id_range64.php → requests/php/id_range64.php} +1 -1
  87. data/spec/fixtures/{index_weights.php → requests/php/index_weights.php} +1 -1
  88. data/spec/fixtures/{keywords.php → requests/php/keywords.php} +1 -1
  89. data/spec/fixtures/{limits.php → requests/php/limits.php} +1 -1
  90. data/spec/fixtures/{limits_cutoff.php → requests/php/limits_cutoff.php} +1 -1
  91. data/spec/fixtures/{limits_max.php → requests/php/limits_max.php} +1 -1
  92. data/spec/fixtures/{limits_max_cutoff.php → requests/php/limits_max_cutoff.php} +1 -1
  93. data/spec/fixtures/{match_all.php → requests/php/match_all.php} +1 -1
  94. data/spec/fixtures/{match_any.php → requests/php/match_any.php} +1 -1
  95. data/spec/fixtures/{match_boolean.php → requests/php/match_boolean.php} +1 -1
  96. data/spec/fixtures/{match_extended.php → requests/php/match_extended.php} +1 -1
  97. data/spec/fixtures/{match_extended2.php → requests/php/match_extended2.php} +1 -1
  98. data/spec/fixtures/{match_fullscan.php → requests/php/match_fullscan.php} +1 -1
  99. data/spec/fixtures/{match_phrase.php → requests/php/match_phrase.php} +1 -1
  100. data/spec/fixtures/{max_query_time.php → requests/php/max_query_time.php} +1 -1
  101. data/spec/fixtures/{miltiple_queries.php → requests/php/miltiple_queries.php} +1 -1
  102. data/spec/fixtures/requests/php/outer_select.php +9 -0
  103. data/spec/fixtures/{set_override.php → requests/php/override.php} +1 -1
  104. data/spec/fixtures/requests/php/query_flag.php +13 -0
  105. data/spec/fixtures/requests/php/query_flag_after_reset.php +19 -0
  106. data/spec/fixtures/{ranking_bm25.php → requests/php/ranking_bm25.php} +1 -1
  107. data/spec/fixtures/requests/php/ranking_expr.php +9 -0
  108. data/spec/fixtures/{ranking_fieldmask.php → requests/php/ranking_fieldmask.php} +1 -1
  109. data/spec/fixtures/{ranking_matchany.php → requests/php/ranking_matchany.php} +1 -1
  110. data/spec/fixtures/{ranking_none.php → requests/php/ranking_none.php} +1 -1
  111. data/spec/fixtures/{ranking_proximity.php → requests/php/ranking_proximity.php} +1 -1
  112. data/spec/fixtures/{ranking_proximity_bm25.php → requests/php/ranking_proximity_bm25.php} +1 -1
  113. data/spec/fixtures/{ranking_sph04.php → requests/php/ranking_sph04.php} +1 -1
  114. data/spec/fixtures/{ranking_wordcount.php → requests/php/ranking_wordcount.php} +1 -1
  115. data/spec/fixtures/{retries.php → requests/php/retries.php} +1 -1
  116. data/spec/fixtures/{retries_delay.php → requests/php/retries_delay.php} +1 -1
  117. data/spec/fixtures/{select.php → requests/php/select.php} +1 -1
  118. data/spec/fixtures/{sort_attr_asc.php → requests/php/sort_attr_asc.php} +1 -1
  119. data/spec/fixtures/{sort_attr_desc.php → requests/php/sort_attr_desc.php} +1 -1
  120. data/spec/fixtures/{sort_expr.php → requests/php/sort_expr.php} +1 -1
  121. data/spec/fixtures/{sort_extended.php → requests/php/sort_extended.php} +1 -1
  122. data/spec/fixtures/{sort_relevance.php → requests/php/sort_relevance.php} +1 -1
  123. data/spec/fixtures/{sort_time_segments.php → requests/php/sort_time_segments.php} +1 -1
  124. data/spec/fixtures/{update_attributes.php → requests/php/update_attributes.php} +1 -1
  125. data/spec/fixtures/{update_attributes_mva.php → requests/php/update_attributes_mva.php} +1 -1
  126. data/spec/fixtures/{weights.php → requests/php/weights.php} +1 -1
  127. data/spec/fixtures/requests/query_flag.dat +0 -0
  128. data/spec/fixtures/requests/query_flag_after_reset.dat +0 -0
  129. data/spec/fixtures/requests/ranking_bm25.dat +0 -0
  130. data/spec/fixtures/requests/ranking_expr.dat +0 -0
  131. data/spec/fixtures/requests/ranking_fieldmask.dat +0 -0
  132. data/spec/fixtures/requests/ranking_matchany.dat +0 -0
  133. data/spec/fixtures/requests/ranking_none.dat +0 -0
  134. data/spec/fixtures/requests/ranking_proximity.dat +0 -0
  135. data/spec/fixtures/requests/ranking_proximity_bm25.dat +0 -0
  136. data/spec/fixtures/requests/ranking_sph04.dat +0 -0
  137. data/spec/fixtures/requests/ranking_wordcount.dat +0 -0
  138. data/spec/fixtures/requests/retries.dat +0 -0
  139. data/spec/fixtures/requests/retries_delay.dat +0 -0
  140. data/spec/fixtures/requests/select.dat +0 -0
  141. data/spec/fixtures/requests/sort_attr_asc.dat +0 -0
  142. data/spec/fixtures/requests/sort_attr_desc.dat +0 -0
  143. data/spec/fixtures/requests/sort_expr.dat +0 -0
  144. data/spec/fixtures/requests/sort_extended.dat +0 -0
  145. data/spec/fixtures/requests/sort_relevance.dat +0 -0
  146. data/spec/fixtures/requests/sort_time_segments.dat +0 -0
  147. data/spec/fixtures/requests/update_attributes.dat +0 -0
  148. data/spec/fixtures/requests/update_attributes_mva.dat +0 -0
  149. data/spec/fixtures/requests/weights.dat +0 -0
  150. data/spec/fixtures/responses/build_excerpts.dat +0 -0
  151. data/spec/fixtures/responses/build_keywords.dat +0 -0
  152. data/spec/fixtures/responses/flush_attributes.dat +0 -0
  153. data/spec/fixtures/responses/flush_attrs.dat +2 -0
  154. data/spec/fixtures/responses/open.dat +0 -0
  155. data/spec/fixtures/responses/open_twice.dat +0 -0
  156. data/spec/fixtures/responses/php/build_excerpts.php +8 -0
  157. data/spec/fixtures/responses/php/build_keywords.php +8 -0
  158. data/spec/fixtures/responses/php/flush_attributes.php +8 -0
  159. data/spec/fixtures/responses/php/open.php +8 -0
  160. data/spec/fixtures/responses/php/open_twice.php +9 -0
  161. data/spec/fixtures/responses/php/query.php +8 -0
  162. data/spec/fixtures/responses/php/query_error.php +8 -0
  163. data/spec/fixtures/responses/php/query_id64.php +8 -0
  164. data/spec/fixtures/responses/php/run_queries.php +10 -0
  165. data/spec/fixtures/responses/php/run_queries_error.php +9 -0
  166. data/spec/fixtures/responses/php/status.php +8 -0
  167. data/spec/fixtures/responses/php/update_attributes.php +8 -0
  168. data/spec/fixtures/responses/php/update_attributes_mva.php +8 -0
  169. data/spec/fixtures/responses/query.dat +0 -0
  170. data/spec/fixtures/responses/query_error.dat +0 -0
  171. data/spec/fixtures/responses/query_id64.dat +0 -0
  172. data/spec/fixtures/responses/run_queries.dat +0 -0
  173. data/spec/fixtures/responses/run_queries_error.dat +0 -0
  174. data/spec/fixtures/responses/status.dat +0 -0
  175. data/spec/fixtures/responses/update_attributes.dat +0 -0
  176. data/spec/fixtures/responses/update_attributes_mva.dat +0 -0
  177. data/spec/fixtures/sphinxapi.php +217 -45
  178. data/spec/spec_helper.rb +18 -3
  179. data/spec/sphinx/sphinx-id64.conf +6 -6
  180. data/spec/sphinx/sphinx.conf +6 -6
  181. data/sphinx.gemspec +19 -121
  182. metadata +268 -105
  183. data/README.rdoc +0 -243
  184. data/VERSION.yml +0 -5
  185. data/init.rb +0 -1
@@ -1,243 +0,0 @@
1
- = Sphinx Client API
2
-
3
- This document gives an overview of what is Sphinx itself and how to use it
4
- from your Ruby on Rails application. For more information or documentation,
5
- please go to http://www.sphinxsearch.com
6
-
7
- == Sphinx
8
-
9
- Sphinx is a standalone full-text search engine, meant to provide fast,
10
- size-efficient and relevant fulltext search functions to other applications.
11
- Sphinx was specially designed to integrate well with SQL databases and
12
- scripting languages. Currently built-in data sources support fetching data
13
- either via direct connection to MySQL, or from an XML pipe.
14
-
15
- Simplest way to communicate with Sphinx is to use <tt>searchd</tt> —
16
- a daemon to search through full text indexes from external software.
17
-
18
- == Installation
19
-
20
- There are two options when approaching sphinx plugin installation:
21
-
22
- * using the gem (recommended)
23
- * install as a Rails plugin
24
-
25
- To install as a gem, add this to your environment.rb:
26
-
27
- config.gem 'sphinx', :source => 'http://gemcutter.org'
28
-
29
- And then run the command:
30
-
31
- sudo rake gems:install
32
-
33
- To install Sphinx as a Rails plugin use this:
34
-
35
- script/plugin install git://github.com/kpumuk/sphinx.git
36
-
37
- == Documentation
38
-
39
- Complete Sphinx plugin documentation could be found here:
40
- http://kpumuk.github.com/sphinx
41
-
42
- Also you can find documentation on rdoc.info:
43
- http://rdoc.info/projects/kpumuk/sphinx
44
-
45
- You can build the documentation locally by running:
46
-
47
- rake yard
48
-
49
- Please note: you should have yard gem installed on your system:
50
-
51
- sudo gem install yard --source http://gemcutter.org
52
-
53
- Complete Sphinx API documentation could be found on Sphinx Search Engine
54
- site: http://www.sphinxsearch.com/docs/current.html
55
- This plugin is fully compatible with original PHP API implementation.
56
-
57
- == Ruby naming conventions
58
-
59
- Sphinx Client API supports Ruby naming conventions, so every API
60
- method name is in underscored, lowercase form:
61
-
62
- SetServer -> set_server
63
- RunQueries -> run_queries
64
- SetMatchMode -> set_match_mode
65
-
66
- Every method is aliased to a corresponding one from standard Sphinx
67
- API, so you can use both <tt>SetServer</tt> and <tt>set_server</tt>
68
- with no differrence.
69
-
70
- There are three exceptions to this naming rule:
71
-
72
- GetLastError -> last_error
73
- GetLastWarning -> last_warning
74
- IsConnectError -> connect_error?
75
-
76
- Of course, all of them are aliased to the original method names.
77
-
78
- == Using multiple Sphinx servers
79
-
80
- Since we actively use this plugin in our Scribd development workflow,
81
- there are several methods have been added to accommodate our needs.
82
- You can find documentation on Ruby-specific methods in documentation:
83
- http://rdoc.info/projects/kpumuk/sphinx
84
-
85
- First of all, we added support of multiple Sphinx servers to balance
86
- load between them. Also it means that in case of any problems with one
87
- of servers, library will try to fetch the results from another one.
88
- Every consequence request will be executed on the next server in list
89
- (round-robin technique).
90
-
91
- sphinx.set_servers([
92
- { :host => 'browse01.local', :port => 3312 },
93
- { :host => 'browse02.local', :port => 3312 },
94
- { :host => 'browse03.local', :port => 3312 }
95
- ])
96
-
97
- By default library will try to fetch results from a single server, and
98
- fail if it does not respond. To setup number of retries being performed,
99
- you can use second (additional) parameter of the <tt>set_connect_timeout</tt>
100
- and <tt>set_request_timeout</tt> methods:
101
-
102
- sphinx.set_connect_timeout(1, 3)
103
- sphinx.set_request_timeout(1, 3)
104
-
105
- There is a big difference between these two methods. First will affect
106
- only on requests experiencing problems with connection (socket error,
107
- pipe error, etc), second will be used when request is broken somehow
108
- (temporary searchd error, incomplete reply, etc). The workflow looks like
109
- this:
110
-
111
- 1. Increase retries number. If is less or equal to configured value,
112
- try to connect to the next server. Otherwise, raise an error.
113
- 2. In case of connection problem go to 1.
114
- 3. Increase request retries number. If it less or equal to configured
115
- value, try to perform request. Otherwise, raise an error.
116
- 4. In case of connection problem go to 1.
117
- 5. In case of request problem, go to 3.
118
- 6. Parse and return response.
119
-
120
- Withdrawals:
121
-
122
- 1. Request could be performed <tt>connect_retries</tt> * <tt>request_retries</tt>
123
- times. E.g., it could be tried <tt>request_retries</tt> times on each
124
- of <tt>connect_retries</tt> servers (when you have 1 server configured,
125
- but <tt>connect_retries</tt> is 5, library will try to connect to this
126
- server 5 times).
127
- 2. Request could be tried to execute on each server <tt>1..request_retries</tt>
128
- times. In case of connection problem, request will be moved to another
129
- server immediately.
130
-
131
- Usually you will set <tt>connect_retries</tt> equal to servers number,
132
- so you will be sure each failing request will be performed on all servers.
133
- This means that if one of servers is live, but others are dead, you request
134
- will be finally executed successfully.
135
-
136
- == Sphinx constants
137
-
138
- Most Sphinx API methods expecting for special constants will be passed.
139
- For example:
140
-
141
- sphinx.set_match_mode(Sphinx::SPH_MATCH_ANY)
142
-
143
- Please note that these constants defined in a <tt>Sphinx</tt>
144
- module. You can use symbols or strings instead of these awful
145
- constants:
146
-
147
- sphinx.set_match_mode(:any)
148
- sphinx.set_match_mode('any')
149
-
150
- == Setting query filters
151
-
152
- Every <tt>set_</tt> method returns <tt>Sphinx::Client</tt> object itself.
153
- It means that you can chain filtering methods:
154
-
155
- results = Sphinx::Client.new.
156
- set_match_mode(:any).
157
- set_ranking_mode(:bm25).
158
- set_id_range(10, 1000).
159
- query('test')
160
-
161
- There is a handful ability to set query parameters directly in <tt>query</tt>
162
- call. If block does not accept any parameters, it will be eval'ed inside
163
- Sphinx::Client instance:
164
-
165
- results = Sphinx::Client.new.query('test') do
166
- match_mode :any
167
- ranking_mode :bm25
168
- id_range 10, 1000
169
- end
170
-
171
- As you can see, in this case you can omit the <tt>set_</tt> prefix for
172
- this methods. If block accepts a parameter, sphinx instance will be
173
- passed into the block. In this case you should you full method names
174
- including the <tt>set_</tt> prefix:
175
-
176
- results = Sphinx::Client.new.query('test') do |sphinx|
177
- sphinx.set_match_mode :any
178
- sphinx.set_ranking_mode :bm25
179
- sphinx.set_id_range 10, 1000
180
- end
181
-
182
- == Example
183
-
184
- This simple example illustrates base connection establishing,
185
- search results retrieving, and excerpts building. Please note
186
- how does it perform database select using ActiveRecord to
187
- save the order of records established by Sphinx.
188
-
189
- sphinx = Sphinx::Client.new
190
- result = sphinx.query('test')
191
- ids = result['matches'].map { |match| match['id'] }
192
- posts = Post.all :conditions => { :id => ids },
193
- :order => "FIELD(id,#{ids.join(',')})"
194
-
195
- docs = posts.map(&:body)
196
- excerpts = sphinx.build_excerpts(docs, 'index', 'test')
197
-
198
- == Logging
199
-
200
- You can ask Sphinx client API to log it's activity to some log. In
201
- order to do that you can pass a logger object into the <tt>Sphinx::Client</tt>
202
- constructor:
203
-
204
- require 'logger'
205
- Sphinx::Client.new(Logger.new(STDOUT)).query('test')
206
-
207
- Logger object should respond to methods :debug, :info, and :warn, and
208
- accept blocks (this is what standard Ruby <tt>Logger</tt> class does).
209
- Here is what you will see in your log:
210
-
211
- * <tt>DEBUG</tt> -- <tt>query</tt>, <tt>add_query</tt>, <tt>run_queries</tt>
212
- method calls with configured filters.
213
- * <tt>INFO</tt> -- initialization with Sphinx version, servers change,
214
- attempts to re-connect, and all attempts to do an API call with server
215
- where request being performed.
216
- * <tt>WARN</tt> -- various connection and socket errors.
217
-
218
- == Support
219
-
220
- Source code:
221
- http://github.com/kpumuk/sphinx
222
-
223
- To suggest a feature or report a bug:
224
- http://github.com/kpumuk/sphinx/issues
225
-
226
- Project home page:
227
- http://kpumuk.info/projects/ror-plugins/sphinx
228
-
229
- == Credits
230
-
231
- Dmytro Shteflyuk <kpumuk@kpumuk.info> http://kpumuk.info
232
-
233
- Andrew Aksyonoff http://sphinxsearch.com
234
-
235
- Special thanks to Alexey Kovyrin <alexey@kovyrin.net> http://blog.kovyrin.net
236
-
237
- Special thanks to Mike Perham http://www.mikeperham.com for his awesome
238
- memcache-client gem, where latest Sphinx gem got new sockets handling from.
239
-
240
- ==License
241
-
242
- This library is distributed under the terms of the Ruby license.
243
- You can freely distribute/modify this library.
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 0
3
- :minor: 9
4
- :patch: 10
5
- :build: 2122
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + '/lib/sphinx'