riddle 1.5.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +5 -8
- data/Gemfile +2 -2
- data/HISTORY +10 -0
- data/README.markdown +192 -0
- data/lib/riddle.rb +3 -0
- data/lib/riddle/auto_version.rb +1 -1
- data/lib/riddle/client.rb +17 -15
- data/lib/riddle/command_failed_error.rb +3 -0
- data/lib/riddle/command_result.rb +14 -0
- data/lib/riddle/configuration/common.rb +1 -1
- data/lib/riddle/configuration/searchd.rb +4 -2
- data/lib/riddle/controller.rb +23 -32
- data/lib/riddle/execute_command.rb +45 -0
- data/riddle.gemspec +1 -1
- metadata +58 -80
- data/README.textile +0 -101
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0743ec72ebf70708fe0cbdbfb63d44c307e7c798
|
4
|
+
data.tar.gz: a46b1a68d1104d21d7d63b52d712e313e6b48c6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6df640330c4c08a437e831de9c2a78c0d0fe55618bdad21ad36e80ef0b908f0f8f6445533c2a395122a0121cdc298dacb723ca98712d277f86ab2e72df8af9ea
|
7
|
+
data.tar.gz: 097f533203b245d59c2cdaccc52cca61bfefacb551e0c58e974e9a777d97b01e45c4ed843095d7119dc9889d6d83591926d0f5437ad330229d74fbeb6a81416e
|
data/.travis.yml
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.8.7
|
4
|
-
- 1.9.2
|
5
|
-
- 1.9.3
|
6
|
-
- 2.0.0
|
7
3
|
- 2.1
|
8
|
-
-
|
4
|
+
- 2.2
|
9
5
|
env:
|
10
|
-
- SPHINX_BIN=/usr/local/sphinx-2.0.
|
11
|
-
- SPHINX_BIN=/usr/local/sphinx-2.1.
|
12
|
-
- SPHINX_BIN=/usr/local/sphinx-2.2.
|
6
|
+
- SPHINX_BIN=/usr/local/sphinx-2.0.10/bin SPHINX_VERSION=2.0.10
|
7
|
+
- SPHINX_BIN=/usr/local/sphinx-2.1.9/bin SPHINX_VERSION=2.1.9
|
8
|
+
- SPHINX_BIN=/usr/local/sphinx-2.2.6/bin SPHINX_VERSION=2.2.6
|
13
9
|
before_script: killall searchd; echo ''
|
14
10
|
after_script: killall searchd; echo ''
|
11
|
+
sudo: false
|
data/Gemfile
CHANGED
data/HISTORY
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2.0.0 - September 25th 2016
|
2
|
+
- Start and stop commands now accept a verbose option.
|
3
|
+
- Failed commands (as determined by a non-zero status code) raise a Riddle::CommandFailedError exception.
|
4
|
+
- A missing configuration file when running the start and stop commands now raises a Riddle::NoConfigurationFileError instance instead of a generic RuntimeError instance.
|
5
|
+
- Riddle::Controller now returns Riddle::CommandResult instances for indexing, start and stop commands, which includes status code and (non-verbose) output.
|
6
|
+
- Handle group_concat attribute types (@crazyshot, @bibendi).
|
7
|
+
- Additional searchd settings: query_log_min_msec, agent_conect_timeout, agent_query_timeout, agent_retry_count, agent_retry_delay.
|
8
|
+
- Default to 2.1.0 or newer support.
|
9
|
+
- Move plugin_dir option from searchd to common.
|
10
|
+
|
1
11
|
1.5.12 - June 1st 2015
|
2
12
|
- Adding ? as an escaped character (Alexey Nikitin).
|
3
13
|
- Adding contributor code of conduct.
|
data/README.markdown
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
# Riddle
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/pat/riddle.svg?branch=develop)](https://travis-ci.org/pat/riddle)
|
4
|
+
|
5
|
+
Riddle is a Ruby library interfacing with the [Sphinx](http://sphinxsearch.com/) full-text search tool. It is written by [Pat Allan](http://freelancing-gods.com), and has been influenced by both Dmytro Shteflyuk's Ruby client and the original PHP client. It can be used for interactions with Sphinx's command-line tools `searchd` and `indexer`, sending search queries via the binary protocol, and programmatically generating Sphinx configuration files.
|
6
|
+
|
7
|
+
The syntax here, while closer to a usual Ruby approach than the PHP client, is quite old (Riddle was first published in 2007). While it would be nice to re-work things, it's really not a priority, given the bulk of Riddle's code is for Sphinx's deprecated binary protocol.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Riddle is available as a gem, so you can install it directly:
|
12
|
+
|
13
|
+
gem install riddle
|
14
|
+
|
15
|
+
Or include it in a Gemfile:
|
16
|
+
|
17
|
+
gem 'riddle', '~> 1.5.12'
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
As of version 1.0.0, Riddle supports multiple versions of Sphinx in the one gem - you'll need to require your specific version after a normal require, though. The latest distinct version is `2.1.0`:
|
22
|
+
|
23
|
+
require 'riddle'
|
24
|
+
require 'riddle/2.1.0'
|
25
|
+
|
26
|
+
The full list of versions available are `0.9.8` (the initial base), `0.9.9`, `1.10`, `2.0.1`, and `2.1.0`. If you're using something more modern than 2.1.0, then just require that, and the rest should be fine (changes to the binary protocol since then are minimal).
|
27
|
+
|
28
|
+
### Configuration
|
29
|
+
|
30
|
+
Riddle's structure for generating Sphinx configuration is very direct mapping to Sphinx's configuration options. First, create an instance of `Riddle::Configuration`:
|
31
|
+
|
32
|
+
config = Riddle::Configuration.new
|
33
|
+
|
34
|
+
This configuration instance has methods `indexer`, `searchd` and `common`, which return separate inner-configuration objects with methods mapping to the equivalent [Sphinx settings](http://sphinxsearch.com/docs/current.html#conf-reference). So, you may want to do the following:
|
35
|
+
|
36
|
+
config.indexer.mem_limit = '128M'
|
37
|
+
config.searchd.log = '/my/log/file.log'
|
38
|
+
|
39
|
+
Similarly, there are two further methods `indices` and `sources`, which are arrays meant to hold instances of index and source inner-configuration objects respectively (all of which have methods matching their Sphinx settings). The available index classes are:
|
40
|
+
|
41
|
+
* `Riddle::Configuration::DistributedIndex`
|
42
|
+
* `Riddle::Configuration::Index`
|
43
|
+
* `Riddle::Configuration::RealtimeIndex`
|
44
|
+
* `Riddle::Configuration::RemoteIndex`
|
45
|
+
* `Riddle::Configuration::TemplateIndex`
|
46
|
+
|
47
|
+
All of these index classes should be initialised with their name, and in the case of plain indices, their source objects. Remote indices take an address, port and name as their initialiser parameters.
|
48
|
+
|
49
|
+
index = Riddle::Configuration::Index.new 'articles', article_source_a, article_source_b
|
50
|
+
index.path = '/path/to/index/files"
|
51
|
+
index.docinfo = 'external'
|
52
|
+
|
53
|
+
The available source classes are:
|
54
|
+
|
55
|
+
* `Riddle::Configuration::SQLSource`
|
56
|
+
* `Riddle::Configuration::TSVSource`
|
57
|
+
* `Riddle::Configuration::XMLSource`
|
58
|
+
|
59
|
+
The initialising parameters are the name of the source, and the type of source:
|
60
|
+
|
61
|
+
source = Riddle::Configuration::SQLSource.new 'article_source', 'mysql'
|
62
|
+
source.sql_query = "SELECT id, title, body FROM articles"
|
63
|
+
source.sql_host = "127.0.0.1"
|
64
|
+
|
65
|
+
Once you have created your configuration object tree, you can then generate the string representation and perhaps save it to a file:
|
66
|
+
|
67
|
+
File.write "sphinx.conf", configuration.render
|
68
|
+
|
69
|
+
It's also possible to parse an existing Sphinx configuration file into a configuration option tree:
|
70
|
+
|
71
|
+
configuration = Riddle::Configuration.parse! File.read('sphinx.conf')
|
72
|
+
|
73
|
+
### Indexing and Starting/Stopping the Daemon
|
74
|
+
|
75
|
+
using Sphinx's command-line tools `indexer` and `searchd` via Riddle is all done via an instance of `Riddle::Controller`:
|
76
|
+
|
77
|
+
configuration_file = "/path/to/sphinx.conf"
|
78
|
+
configuration = Riddle::Configuration.parse! File.read(configuration_file)
|
79
|
+
controller = Riddle::Controller.new configuration, configuration_file
|
80
|
+
|
81
|
+
# set the path where the indexer and searchd binaries are located:
|
82
|
+
controller.bin_path = '/usr/local/bin'
|
83
|
+
|
84
|
+
# set different binary names if you're running a custom Sphinx installation:
|
85
|
+
controller.searchd_binary_name = 'sphinxsearchd'
|
86
|
+
controller.indexer_binary_name = 'sphinxindexer'
|
87
|
+
|
88
|
+
# process all indices:
|
89
|
+
controller.index
|
90
|
+
# process specific indices:
|
91
|
+
controller.index 'articles', 'books'
|
92
|
+
# rotate old index files out for the new ones:
|
93
|
+
controller.rotate
|
94
|
+
|
95
|
+
# start the daemon:
|
96
|
+
controller.start
|
97
|
+
# start the daemon and do not detach the process:
|
98
|
+
controller.start :nodetach => true
|
99
|
+
# stop the daemon:
|
100
|
+
controller.stop
|
101
|
+
|
102
|
+
The index, start and stop methods all accept a hash of options, and the :verbose option is respected in each case.
|
103
|
+
|
104
|
+
Each of these methods will return an instance of `Riddle::CommandResult` - or, if the command fails (as judged by the process status code), a `Riddle::CommandFailedError` exception is raised. These exceptions respond to the `command_result` method with the corresponding details.
|
105
|
+
|
106
|
+
### SphinxQL Queries
|
107
|
+
|
108
|
+
Riddle does not have any code to send SphinxQL queries and commands to Sphinx. Because Sphinx uses the mysql41 protocol (thus, mimicing a MySQL database server), I recommend using the [mysql2](https://github.com/brianmario/mysql2) gem instead. The [connection code](https://github.com/pat/thinking-sphinx/blob/develop/lib/thinking_sphinx/connection.rb) in Thinking Sphinx may provide some inspiration on this.
|
109
|
+
|
110
|
+
### Binary Protocol Searching
|
111
|
+
|
112
|
+
Sphinx's legacy binary protocol does not have many of the more recent Sphinx features - such as real-time indices - as these are only available in the SphinxQL/mysql41 protocol. However, Riddle can still be used for the binary protocol if you wish.
|
113
|
+
|
114
|
+
To get started, just instantiate a Client object:
|
115
|
+
|
116
|
+
client = Riddle::Client.new # defaults to localhost and port 9312
|
117
|
+
client = Riddle::Client.new "sphinxserver.domain.tld", 3333 # custom settings
|
118
|
+
|
119
|
+
And then set the parameters to what you want, before running a query:
|
120
|
+
|
121
|
+
client.match_mode = :extended
|
122
|
+
client.query "Pat Allan @state Victoria"
|
123
|
+
|
124
|
+
The results from a query are similar to the other clients - but here's the details. It's a hash with
|
125
|
+
the following keys:
|
126
|
+
|
127
|
+
* `:matches`
|
128
|
+
* `:fields`
|
129
|
+
* `:attributes`
|
130
|
+
* `:attribute_names`
|
131
|
+
* `:words`
|
132
|
+
* `:total`
|
133
|
+
* `:total_found`
|
134
|
+
* `:time`
|
135
|
+
* `:status`
|
136
|
+
* `:warning` (if appropriate)
|
137
|
+
* `:error` (if appropriate)
|
138
|
+
|
139
|
+
The key `:matches` returns an array of hashes - the actual search results. Each hash has the document id (`:doc`), the result weighting (`:weight`), and a hash of the attributes for the document (`:attributes`).
|
140
|
+
|
141
|
+
The `:fields` and `:attribute_names` keys return list of fields and attributes for the documents. The key `:attributes` will return a hash of attribute name and type pairs, and `:words` returns a hash of hashes representing the words from the search, with the number of documents and hits for each, along the lines of:
|
142
|
+
|
143
|
+
results[:words]["Pat"] #=> {:docs => 12, :hits => 15}
|
144
|
+
|
145
|
+
`:total`, `:total_found` and `:time` return the number of matches available, the total number of matches (which may be greater than the maximum available), and the time in milliseconds that the query took to run.
|
146
|
+
|
147
|
+
`:status` is the error code for the query - and if there was a related warning, it will be under the `:warning` key. Fatal errors will be described under `:error`.
|
148
|
+
|
149
|
+
## Contributing
|
150
|
+
|
151
|
+
Please note that this project has a [Contributor Code of Conduct](http://contributor-covenant.org/version/1/0/0/). By participating in this project you agree to abide by its terms.
|
152
|
+
|
153
|
+
Riddle uses the [git-flow](http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/) process for development. The `master` branch is the latest released code (in a gem). The `develop` branch is what's coming in the next release. (There may be occasional feature and hotfix branches, although these are generally not pushed to GitHub.)
|
154
|
+
|
155
|
+
When submitting a patch to Riddle, please submit your pull request against the `develop` branch.
|
156
|
+
|
157
|
+
## Contributors
|
158
|
+
|
159
|
+
Thanks to the following people who have contributed to Riddle in some shape or form:
|
160
|
+
|
161
|
+
* Andrew Aksyonoff
|
162
|
+
* Brad Greenlee
|
163
|
+
* Lachie Cox
|
164
|
+
* Jeremy Seitz
|
165
|
+
* Mark Lane
|
166
|
+
* Xavier Noria
|
167
|
+
* Henrik Nye
|
168
|
+
* Kristopher Chambers
|
169
|
+
* Rob Anderton
|
170
|
+
* Dylan Egan
|
171
|
+
* Jerry Vos
|
172
|
+
* Piotr Sarnacki
|
173
|
+
* Tim Preston
|
174
|
+
* Amir Yalon
|
175
|
+
* Sam Goldstein
|
176
|
+
* Matt Todd
|
177
|
+
* Paco Guzmán
|
178
|
+
* Greg Weber
|
179
|
+
* Enrico Thierbach
|
180
|
+
* Jason Lambert
|
181
|
+
* Saberma
|
182
|
+
* James Cook
|
183
|
+
* Alexey Artamonov
|
184
|
+
* Paul Gibler
|
185
|
+
* Ngan Pham
|
186
|
+
* Aaron Gilbralter
|
187
|
+
* Steven Bristol
|
188
|
+
* Ilia Lobsanov
|
189
|
+
* Aleksey Morozov
|
190
|
+
* S\. Christoffer Eliesen
|
191
|
+
* Rob Golkosky
|
192
|
+
* Darcy Brown
|
data/lib/riddle.rb
CHANGED
@@ -67,8 +67,11 @@ end
|
|
67
67
|
|
68
68
|
require 'riddle/auto_version'
|
69
69
|
require 'riddle/client'
|
70
|
+
require 'riddle/command_failed_error'
|
71
|
+
require 'riddle/command_result'
|
70
72
|
require 'riddle/configuration'
|
71
73
|
require 'riddle/controller'
|
74
|
+
require 'riddle/execute_command'
|
72
75
|
require 'riddle/query'
|
73
76
|
|
74
77
|
Riddle.loaded_version = nil
|
data/lib/riddle/auto_version.rb
CHANGED
data/lib/riddle/client.rb
CHANGED
@@ -92,14 +92,15 @@ module Riddle
|
|
92
92
|
}
|
93
93
|
|
94
94
|
AttributeTypes = {
|
95
|
-
:integer
|
96
|
-
:timestamp
|
97
|
-
:ordinal
|
98
|
-
:bool
|
99
|
-
:float
|
100
|
-
:bigint
|
101
|
-
:string
|
102
|
-
:
|
95
|
+
:integer => 1, # SPH_ATTR_INTEGER
|
96
|
+
:timestamp => 2, # SPH_ATTR_TIMESTAMP
|
97
|
+
:ordinal => 3, # SPH_ATTR_ORDINAL
|
98
|
+
:bool => 4, # SPH_ATTR_BOOL
|
99
|
+
:float => 5, # SPH_ATTR_FLOAT
|
100
|
+
:bigint => 6, # SPH_ATTR_BIGINT
|
101
|
+
:string => 7, # SPH_ATTR_STRING
|
102
|
+
:group_concat => 10,
|
103
|
+
:multi => 0x40000000 # SPH_ATTR_MULTI
|
103
104
|
}
|
104
105
|
|
105
106
|
GroupFunctions = {
|
@@ -830,13 +831,14 @@ module Riddle
|
|
830
831
|
end
|
831
832
|
|
832
833
|
AttributeHandlers = {
|
833
|
-
AttributeTypes[:integer]
|
834
|
-
AttributeTypes[:timestamp]
|
835
|
-
AttributeTypes[:ordinal]
|
836
|
-
AttributeTypes[:bool]
|
837
|
-
AttributeTypes[:float]
|
838
|
-
AttributeTypes[:bigint]
|
839
|
-
AttributeTypes[:string]
|
834
|
+
AttributeTypes[:integer] => :next_int,
|
835
|
+
AttributeTypes[:timestamp] => :next_int,
|
836
|
+
AttributeTypes[:ordinal] => :next_int,
|
837
|
+
AttributeTypes[:bool] => :next_int,
|
838
|
+
AttributeTypes[:float] => :next_float,
|
839
|
+
AttributeTypes[:bigint] => :next_64bit_int,
|
840
|
+
AttributeTypes[:string] => :next,
|
841
|
+
AttributeTypes[:group_concat] => :next,
|
840
842
|
AttributeTypes[:multi] + AttributeTypes[:integer] => :next_int_array
|
841
843
|
}
|
842
844
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Riddle::CommandResult
|
2
|
+
attr_reader :command, :status, :output
|
3
|
+
attr_accessor :successful
|
4
|
+
|
5
|
+
def initialize(command, status, output = nil, successful = nil)
|
6
|
+
@command, @status, @output = command, status, output
|
7
|
+
|
8
|
+
if successful.nil?
|
9
|
+
@successful = (@status == 0)
|
10
|
+
else
|
11
|
+
@successful = successful
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -12,13 +12,15 @@ module Riddle
|
|
12
12
|
:max_batch_queries, :subtree_docs_cache, :subtree_hits_cache,
|
13
13
|
:workers, :dist_threads, :binlog_path, :binlog_flush,
|
14
14
|
:binlog_max_log_size, :snippets_file_prefix, :collation_server,
|
15
|
-
:collation_libc_locale, :
|
15
|
+
:collation_libc_locale, :mysql_version_string,
|
16
16
|
:rt_flush_period, :thread_stack, :expansion_limit,
|
17
17
|
:compat_sphinxql_magics, :watchdog, :prefork_rotation_throttle,
|
18
18
|
:sphinxql_state, :ha_ping_interval, :ha_period_karma,
|
19
19
|
:persistent_connections_limit, :rt_merge_iops, :rt_merge_maxiosize,
|
20
20
|
:predicted_time_costs, :snippets_file_prefix, :shutdown_timeout,
|
21
|
-
:ondisk_attrs_default, :
|
21
|
+
:ondisk_attrs_default, :query_log_min_msec, :agent_connect_timeout,
|
22
|
+
:agent_query_timeout, :agent_retry_count, :agenty_retry_delay,
|
23
|
+
:client_key
|
22
24
|
]
|
23
25
|
end
|
24
26
|
|
data/lib/riddle/controller.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module Riddle
|
2
|
+
NoConfigurationFileError = Class.new StandardError
|
3
|
+
|
2
4
|
class Controller
|
3
5
|
attr_accessor :path, :bin_path, :searchd_binary_name, :indexer_binary_name
|
4
6
|
|
@@ -21,55 +23,41 @@ module Riddle
|
|
21
23
|
options = indices.last.is_a?(Hash) ? indices.pop : {}
|
22
24
|
indices << '--all' if indices.empty?
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
command = "#{indexer} --config \"#{@path}\" #{indices.join(' ')}"
|
27
|
+
command << " --rotate" if running?
|
28
|
+
|
29
|
+
Riddle::ExecuteCommand.call command, options[:verbose]
|
27
30
|
end
|
28
31
|
|
29
|
-
def start(options={})
|
32
|
+
def start(options = {})
|
30
33
|
return if running?
|
31
34
|
check_for_configuration_file
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if options[:nodetach]
|
37
|
-
exec(cmd)
|
38
|
-
elsif RUBY_PLATFORM =~ /mswin|mingw/
|
39
|
-
output = system("start /B #{cmd} 1> NUL 2>&1")
|
40
|
-
else
|
41
|
-
output = `#{cmd}`
|
42
|
-
end
|
36
|
+
command = "#{searchd} --pidfile --config \"#{@path}\""
|
37
|
+
command << " --nodetach" if options[:nodetach]
|
43
38
|
|
44
|
-
|
39
|
+
exec(command) if options[:nodetach]
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
output
|
41
|
+
# Code does not get here if nodetach is true.
|
42
|
+
Riddle::ExecuteCommand.call command, options[:verbose]
|
51
43
|
end
|
52
44
|
|
53
|
-
def stop
|
45
|
+
def stop(options = {})
|
54
46
|
return true unless running?
|
55
47
|
check_for_configuration_file
|
56
48
|
|
57
49
|
stop_flag = 'stopwait'
|
58
50
|
stop_flag = 'stop' if Riddle.loaded_version.split('.').first == '0'
|
59
|
-
|
51
|
+
command = %(#{searchd} --pidfile --config "#{@path}" --#{stop_flag})
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
`#{cmd}`
|
65
|
-
end
|
66
|
-
|
67
|
-
!running?
|
53
|
+
result = Riddle::ExecuteCommand.call command, options[:verbose]
|
54
|
+
result.successful = !running?
|
55
|
+
result
|
68
56
|
end
|
69
57
|
|
70
58
|
def pid
|
71
|
-
if File.exists?(
|
72
|
-
File.read(
|
59
|
+
if File.exists?(configuration.searchd.pid_file)
|
60
|
+
File.read(configuration.searchd.pid_file)[/\d+/]
|
73
61
|
else
|
74
62
|
nil
|
75
63
|
end
|
@@ -87,6 +75,8 @@ module Riddle
|
|
87
75
|
|
88
76
|
private
|
89
77
|
|
78
|
+
attr_reader :configuration
|
79
|
+
|
90
80
|
def indexer
|
91
81
|
"#{bin_path}#{indexer_binary_name}"
|
92
82
|
end
|
@@ -97,7 +87,8 @@ module Riddle
|
|
97
87
|
|
98
88
|
def check_for_configuration_file
|
99
89
|
return if File.exist?(@path)
|
100
|
-
|
90
|
+
|
91
|
+
raise Riddle::NoConfigurationFileError, "'#{@path}' does not exist"
|
101
92
|
end
|
102
93
|
end
|
103
94
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Riddle::ExecuteCommand
|
2
|
+
WINDOWS = (RUBY_PLATFORM =~ /mswin|mingw/)
|
3
|
+
|
4
|
+
def self.call(command, verbose = true)
|
5
|
+
new(command, verbose).call
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(command, verbose)
|
9
|
+
@command, @verbose = command, verbose
|
10
|
+
|
11
|
+
return unless WINDOWS
|
12
|
+
|
13
|
+
@command = "start /B #{@command} 1> NUL 2>&1"
|
14
|
+
@verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
result = verbose? ? result_from_system : result_from_backticks
|
19
|
+
return result if result.status == 0
|
20
|
+
|
21
|
+
error = Riddle::CommandFailedError.new "Sphinx command failed to execute"
|
22
|
+
error.command_result = result
|
23
|
+
raise error
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :command, :verbose
|
29
|
+
|
30
|
+
def result_from_backticks
|
31
|
+
output = `#{command}`
|
32
|
+
|
33
|
+
Riddle::CommandResult.new command, $?.exitstatus, output
|
34
|
+
end
|
35
|
+
|
36
|
+
def result_from_system
|
37
|
+
system command
|
38
|
+
|
39
|
+
Riddle::CommandResult.new command, $?.exitstatus
|
40
|
+
end
|
41
|
+
|
42
|
+
def verbose?
|
43
|
+
verbose
|
44
|
+
end
|
45
|
+
end
|
data/riddle.gemspec
CHANGED
metadata
CHANGED
@@ -1,86 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: riddle
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 12
|
10
|
-
version: 1.5.12
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Pat Allan
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2016-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: rake
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
25
17
|
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
hash: 63
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 9
|
31
|
-
- 2
|
18
|
+
- !ruby/object:Gem::Version
|
32
19
|
version: 0.9.2
|
33
|
-
prerelease: false
|
34
20
|
type: :development
|
35
|
-
|
36
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
37
28
|
name: rspec
|
38
|
-
|
39
|
-
|
40
|
-
requirements:
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 27
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 5
|
47
|
-
- 0
|
32
|
+
- !ruby/object:Gem::Version
|
48
33
|
version: 2.5.0
|
49
|
-
prerelease: false
|
50
34
|
type: :development
|
51
|
-
|
52
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
53
42
|
name: yard
|
54
|
-
|
55
|
-
|
56
|
-
requirements:
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
57
45
|
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 7
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
- 7
|
63
|
-
- 2
|
46
|
+
- !ruby/object:Gem::Version
|
64
47
|
version: 0.7.2
|
65
|
-
prerelease: false
|
66
48
|
type: :development
|
67
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.2
|
68
55
|
description: A Ruby API and configuration helper for the Sphinx search service.
|
69
|
-
email:
|
56
|
+
email:
|
70
57
|
- pat@freelancing-gods.com
|
71
58
|
executables: []
|
72
|
-
|
73
59
|
extensions: []
|
74
|
-
|
75
60
|
extra_rdoc_files: []
|
76
|
-
|
77
|
-
|
78
|
-
- .
|
79
|
-
- .travis.yml
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
80
64
|
- Gemfile
|
81
65
|
- HISTORY
|
82
66
|
- LICENCE
|
83
|
-
- README.
|
67
|
+
- README.markdown
|
84
68
|
- Rakefile
|
85
69
|
- lib/riddle.rb
|
86
70
|
- lib/riddle/0.9.8.rb
|
@@ -98,6 +82,8 @@ files:
|
|
98
82
|
- lib/riddle/client/filter.rb
|
99
83
|
- lib/riddle/client/message.rb
|
100
84
|
- lib/riddle/client/response.rb
|
85
|
+
- lib/riddle/command_failed_error.rb
|
86
|
+
- lib/riddle/command_result.rb
|
101
87
|
- lib/riddle/configuration.rb
|
102
88
|
- lib/riddle/configuration/common.rb
|
103
89
|
- lib/riddle/configuration/distributed_index.rb
|
@@ -115,6 +101,7 @@ files:
|
|
115
101
|
- lib/riddle/configuration/tsv_source.rb
|
116
102
|
- lib/riddle/configuration/xml_source.rb
|
117
103
|
- lib/riddle/controller.rb
|
104
|
+
- lib/riddle/execute_command.rb
|
118
105
|
- lib/riddle/query.rb
|
119
106
|
- lib/riddle/query/delete.rb
|
120
107
|
- lib/riddle/query/insert.rb
|
@@ -283,39 +270,30 @@ files:
|
|
283
270
|
- spec/unit/response_spec.rb
|
284
271
|
- spec/unit/riddle_spec.rb
|
285
272
|
homepage: http://pat.github.io/riddle/
|
286
|
-
licenses:
|
273
|
+
licenses:
|
287
274
|
- MIT
|
275
|
+
metadata: {}
|
288
276
|
post_install_message:
|
289
277
|
rdoc_options: []
|
290
|
-
|
291
|
-
require_paths:
|
278
|
+
require_paths:
|
292
279
|
- lib
|
293
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
294
|
-
|
295
|
-
requirements:
|
280
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
281
|
+
requirements:
|
296
282
|
- - ">="
|
297
|
-
- !ruby/object:Gem::Version
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
version: "0"
|
302
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
303
|
-
none: false
|
304
|
-
requirements:
|
283
|
+
- !ruby/object:Gem::Version
|
284
|
+
version: '0'
|
285
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
286
|
+
requirements:
|
305
287
|
- - ">="
|
306
|
-
- !ruby/object:Gem::Version
|
307
|
-
|
308
|
-
segments:
|
309
|
-
- 0
|
310
|
-
version: "0"
|
288
|
+
- !ruby/object:Gem::Version
|
289
|
+
version: '0'
|
311
290
|
requirements: []
|
312
|
-
|
313
291
|
rubyforge_project: riddle
|
314
|
-
rubygems_version:
|
292
|
+
rubygems_version: 2.4.8
|
315
293
|
signing_key:
|
316
|
-
specification_version:
|
294
|
+
specification_version: 4
|
317
295
|
summary: An API for Sphinx, written in and for Ruby.
|
318
|
-
test_files:
|
296
|
+
test_files:
|
319
297
|
- spec/fixtures/.gitignore
|
320
298
|
- spec/fixtures/data/0.9.9/anchor.bin
|
321
299
|
- spec/fixtures/data/0.9.9/any.bin
|
data/README.textile
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
h1. Riddle
|
2
|
-
|
3
|
-
"!https://secure.travis-ci.org/pat/riddle.png!":http://travis-ci.org/pat/riddle
|
4
|
-
|
5
|
-
This client has been written to interface with "Sphinx":http://sphinxsearch.com/. It is written by "Pat Allan":http://freelancing-gods.com, and has been influenced by both Dmytro Shteflyuk's Ruby client and the original PHP client - credit where credit's due, after all.
|
6
|
-
|
7
|
-
It does not follow the same syntax as those two, though (not much point writing this otherwise) - opting for a more Ruby-like structure.
|
8
|
-
|
9
|
-
h2. Installation
|
10
|
-
|
11
|
-
<pre><code>sudo gem install riddle</code></pre>
|
12
|
-
|
13
|
-
h3. Usage
|
14
|
-
|
15
|
-
As of version 1.0.0, Riddle now supports multiple versions of Sphinx in the one gem - you'll need to require your specific version after a normal require, though.
|
16
|
-
|
17
|
-
<pre><code>require 'riddle'
|
18
|
-
require 'riddle/0.9.9'</code></pre>
|
19
|
-
|
20
|
-
To get started, just instantiate a Client object:
|
21
|
-
|
22
|
-
<pre><code>client = Riddle::Client.new # defaults to localhost and port 9312
|
23
|
-
client = Riddle::Client.new "sphinxserver.domain.tld", 3333 # custom settings</code></pre>
|
24
|
-
|
25
|
-
And then set the parameters to what you want, before running a query:
|
26
|
-
|
27
|
-
<pre><code>client.match_mode = :extended
|
28
|
-
client.query "Pat Allan @state Victoria"</code></pre>
|
29
|
-
|
30
|
-
The results from a query are similar to the other clients - but here's the details. It's a hash with
|
31
|
-
the following keys:
|
32
|
-
|
33
|
-
* @:matches@
|
34
|
-
* @:fields@
|
35
|
-
* @:attributes@
|
36
|
-
* @:attribute_names@
|
37
|
-
* @:words@
|
38
|
-
* @:total@
|
39
|
-
* @:total_found@
|
40
|
-
* @:time@
|
41
|
-
* @:status@
|
42
|
-
* @:warning@ (if appropriate)
|
43
|
-
* @:error@ (if appropriate)
|
44
|
-
|
45
|
-
The key @:matches@ returns an array of hashes - the actual search results. Each hash has the document id (@:doc@), the result weighting (@:weight@), and a hash of the attributes for the document (@:attributes@).
|
46
|
-
|
47
|
-
The @:fields@ and @:attribute_names@ keys return list of fields and attributes for the documents. The key @:attributes@ will return a hash of attribute name and type pairs, and @:words@ returns a hash of hashes representing the words from the search, with the number of documents and hits for each, along the lines of:
|
48
|
-
|
49
|
-
<pre><code>results[:words]["Pat"] #=> {:docs => 12, :hits => 15}</code></pre>
|
50
|
-
|
51
|
-
@:total@, @:total_found@ and @:time@ return the number of matches available, the
|
52
|
-
total number of matches (which may be greater than the maximum available), and the time in milliseconds that the query took to run.
|
53
|
-
|
54
|
-
@:status@ is the error code for the query - and if there was a related warning, it will be under the @:warning@ key. Fatal errors will be described under @:error@.
|
55
|
-
|
56
|
-
If you've installed the gem and wondering why there's no tests - check out the git version. I've kept the specs out of the gem as I have a decent amount of test data in there, which really isn't needed unless you want to submit patches.
|
57
|
-
|
58
|
-
h2. Contributing
|
59
|
-
|
60
|
-
Please note that this project now has a "Contributor Code of Conduct":http://contributor-covenant.org/version/1/0/0/. By participating in this project you agree to abide by its terms.
|
61
|
-
|
62
|
-
Riddle uses the "git-flow":http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/ process for development. The "master" branch is the latest released code (in a gem). The "develop" branch is what's coming in the next release. (There may be occasional feature and hotfix branches, although these are generally not pushed to GitHub.)
|
63
|
-
|
64
|
-
When submitting a patch to riddle, please submit your pull request against the "develop" branch.
|
65
|
-
|
66
|
-
h2. Contributors
|
67
|
-
|
68
|
-
Thanks to the following people who have contributed to Riddle in some shape or form:
|
69
|
-
|
70
|
-
* Andrew Aksyonoff
|
71
|
-
* Brad Greenlee
|
72
|
-
* Lachie Cox
|
73
|
-
* Jeremy Seitz
|
74
|
-
* Mark Lane
|
75
|
-
* Xavier Noria
|
76
|
-
* Henrik Nye
|
77
|
-
* Kristopher Chambers
|
78
|
-
* Rob Anderton
|
79
|
-
* Dylan Egan
|
80
|
-
* Jerry Vos
|
81
|
-
* Piotr Sarnacki
|
82
|
-
* Tim Preston
|
83
|
-
* Amir Yalon
|
84
|
-
* Sam Goldstein
|
85
|
-
* Matt Todd
|
86
|
-
* Paco Guzmán
|
87
|
-
* Greg Weber
|
88
|
-
* Enrico Thierbach
|
89
|
-
* Jason Lambert
|
90
|
-
* Saberma
|
91
|
-
* James Cook
|
92
|
-
* Alexey Artamonov
|
93
|
-
* Paul Gibler
|
94
|
-
* Ngan Pham
|
95
|
-
* Aaron Gilbralter
|
96
|
-
* Steven Bristol
|
97
|
-
* Ilia Lobsanov
|
98
|
-
* Aleksey Morozov
|
99
|
-
* S. Christoffer Eliesen
|
100
|
-
* Rob Golkosky
|
101
|
-
* Darcy Brown
|