riddle 1.5.9 → 1.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +7 -6
- data/HISTORY +13 -0
- data/README.textile +6 -0
- data/lib/riddle/configuration.rb +2 -0
- data/lib/riddle/configuration/index_settings.rb +3 -2
- data/lib/riddle/configuration/indexer.rb +2 -1
- data/lib/riddle/configuration/parser.rb +4 -2
- data/lib/riddle/configuration/searchd.rb +2 -1
- data/lib/riddle/configuration/template_index.rb +36 -0
- data/lib/riddle/configuration/tsv_source.rb +19 -0
- data/lib/riddle/query/select.rb +52 -12
- data/riddle.gemspec +3 -2
- data/spec/riddle/query/select_spec.rb +45 -2
- data/spec/unit/configuration/template_index_spec.rb +91 -0
- data/spec/unit/configuration/tsv_source_spec.rb +53 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: 578f59b9c3e4a970c9ae4ec47b013ddfd711d41d
|
4
|
+
data.tar.gz: ebc01eb587ca1383302ea8d12731dfc86376de61
|
5
5
|
SHA512:
|
6
|
-
|
7
|
-
|
6
|
+
metadata.gz: a834cb93a23175cd949ead321b44e492e051c1c306b60959581a5db38dfccd0986a8b2b24a9578f908559123cfae7a242d6867213730f39d14ad4234c966c95a
|
7
|
+
data.tar.gz: e3a2e3abbb56f56bcbf8ed4e3086df21e4b903c98abb1dadc186ea939dfb0ab63c6dff5b25c3917a06b9398b304d360f56ee7c9f4b3f1898ea33b8fd1c8e9e4a
|
data/.travis.yml
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
before_install:
|
3
|
+
- sudo apt-get install postgresql-server-dev-9.1 libmysql++-dev -y
|
3
4
|
- curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-1.10_x86_64_12.04.deb
|
4
5
|
- sudo dpkg -i fs-sphinx-1.10_x86_64_12.04.deb
|
5
|
-
- curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.
|
6
|
-
- sudo dpkg -i fs-sphinx-2.0.
|
7
|
-
- curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.
|
8
|
-
- sudo dpkg -i fs-sphinx-2.
|
6
|
+
- curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.9_x86_64_12.04.deb
|
7
|
+
- sudo dpkg -i fs-sphinx-2.0.9_x86_64_12.04.deb
|
8
|
+
- curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.1.4_x86_64_12.04.deb
|
9
|
+
- sudo dpkg -i fs-sphinx-2.1.4_x86_64_12.04.deb
|
9
10
|
rvm:
|
10
11
|
- 1.8.7
|
11
12
|
- 1.9.2
|
@@ -13,7 +14,7 @@ rvm:
|
|
13
14
|
- jruby-18mode
|
14
15
|
env:
|
15
16
|
- SPHINX_BIN=/usr/local/sphinx-1.10/bin SPHINX_VERSION=1.10
|
16
|
-
- SPHINX_BIN=/usr/local/sphinx-2.0.
|
17
|
-
- SPHINX_BIN=/usr/local/sphinx-2.
|
17
|
+
- SPHINX_BIN=/usr/local/sphinx-2.0.9/bin SPHINX_VERSION=2.0.9
|
18
|
+
- SPHINX_BIN=/usr/local/sphinx-2.1.4/bin SPHINX_VERSION=2.1.4
|
18
19
|
before_script: killall searchd; echo ''
|
19
20
|
after_script: killall searchd; echo ''
|
data/HISTORY
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
1.5.10 - January 11th 2014
|
2
|
+
- SELECT values can be prepended as well as the existing append support.
|
3
|
+
- New settings for Sphinx 2.2.1.
|
4
|
+
- Template index type for Sphinx 2.2.1.
|
5
|
+
- TSV source types for Sphinx 2.2.1.
|
6
|
+
- Support for HAVING, GROUP-n-BEST in SELECT statements.
|
7
|
+
- Dates in filters are converted to (UTC) timestamp integers.
|
8
|
+
- Default to * in SELECT queries only if nothing else is supplied.
|
9
|
+
- Fix licence, URL in gemspec (Ken Dreyer).
|
10
|
+
- Handle empty arrays for filter elegantly (Bryan Ricker).
|
11
|
+
- Add a contributing section to the README (Ken Dreyer).
|
12
|
+
- Don't automatically escape function references in SphinxQL ORDER clauses.
|
13
|
+
|
1
14
|
1.5.9 - October 20th 2013
|
2
15
|
- Adding all known Sphinx settings to configuration classes as of Sphinx 2.1.2, including JSON settings.
|
3
16
|
- Convert date objects in INSERT/REPLACE queries to timestamps, just like time objects.
|
data/README.textile
CHANGED
@@ -55,6 +55,12 @@ total number of matches (which may be greater than the maximum available), and t
|
|
55
55
|
|
56
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
57
|
|
58
|
+
h2. Contributing
|
59
|
+
|
60
|
+
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.)
|
61
|
+
|
62
|
+
When submitting a patch to riddle, please submit your pull request against the "develop" branch.
|
63
|
+
|
58
64
|
h2. Contributors
|
59
65
|
|
60
66
|
Thanks to the following people who have contributed to Riddle in some shape or form:
|
data/lib/riddle/configuration.rb
CHANGED
@@ -9,6 +9,8 @@ require 'riddle/configuration/remote_index'
|
|
9
9
|
require 'riddle/configuration/searchd'
|
10
10
|
require 'riddle/configuration/source'
|
11
11
|
require 'riddle/configuration/sql_source'
|
12
|
+
require 'riddle/configuration/template_index'
|
13
|
+
require 'riddle/configuration/tsv_source'
|
12
14
|
require 'riddle/configuration/xml_source'
|
13
15
|
|
14
16
|
require 'riddle/configuration/parser'
|
@@ -15,7 +15,8 @@ module Riddle
|
|
15
15
|
:inplace_reloc_factor, :inplace_write_factor, :index_exact_words,
|
16
16
|
:overshort_step, :stopwords_step, :hitless_words, :ha_strategy,
|
17
17
|
:bigram_freq_words, :bigram_index, :index_field_lengths,
|
18
|
-
:regexp_filter, :stopwords_unstemmed, :global_idf
|
18
|
+
:regexp_filter, :stopwords_unstemmed, :global_idf, :rlp_context,
|
19
|
+
:ondisk_attrs
|
19
20
|
]
|
20
21
|
end
|
21
22
|
|
@@ -32,7 +33,7 @@ module Riddle
|
|
32
33
|
:inplace_write_factor, :index_exact_words, :overshort_step,
|
33
34
|
:stopwords_step, :hitless_words, :ha_strategy, :bigram_freq_words,
|
34
35
|
:bigram_index, :index_field_lengths, :regexp_filter,
|
35
|
-
:stopwords_unstemmed, :global_idf
|
36
|
+
:stopwords_unstemmed, :global_idf, :rlp_context, :ondisk_attrs
|
36
37
|
|
37
38
|
def initialize_settings
|
38
39
|
@morphologies = []
|
@@ -6,7 +6,8 @@ module Riddle
|
|
6
6
|
:mem_limit, :max_iops, :max_iosize, :max_xmlpipe2_field,
|
7
7
|
:write_buffer, :max_file_field_buffer, :on_file_field_error,
|
8
8
|
:lemmatizer_base, :lemmatizer_cache, :json_autoconv_numbers,
|
9
|
-
:on_json_attr_error
|
9
|
+
:on_json_attr_error, :rlp_root, :rlp_environment,
|
10
|
+
:rlp_max_batch_size, :rlp_max_batch_docs
|
10
11
|
]
|
11
12
|
end
|
12
13
|
|
@@ -8,13 +8,15 @@ class Riddle::Configuration::Parser
|
|
8
8
|
'mssql' => Riddle::Configuration::SQLSource,
|
9
9
|
'xmlpipe' => Riddle::Configuration::XMLSource,
|
10
10
|
'xmlpipe2' => Riddle::Configuration::XMLSource,
|
11
|
-
'odbc' => Riddle::Configuration::SQLSource
|
11
|
+
'odbc' => Riddle::Configuration::SQLSource,
|
12
|
+
'tsvpipe' => Riddle::Configuration::TSVSource
|
12
13
|
}
|
13
14
|
|
14
15
|
INDEX_CLASSES = {
|
15
16
|
'plain' => Riddle::Configuration::Index,
|
16
17
|
'distributed' => Riddle::Configuration::DistributedIndex,
|
17
|
-
'rt' => Riddle::Configuration::RealtimeIndex
|
18
|
+
'rt' => Riddle::Configuration::RealtimeIndex,
|
19
|
+
'template' => Riddle::Configuration::TemplateIndex
|
18
20
|
}
|
19
21
|
|
20
22
|
def initialize(input)
|
@@ -17,7 +17,8 @@ module Riddle
|
|
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
|
-
:predicted_time_costs, :snippets_file_prefix, :
|
20
|
+
:predicted_time_costs, :snippets_file_prefix, :shutdown_timeout,
|
21
|
+
:ondisk_attrs_default, :client_key
|
21
22
|
]
|
22
23
|
end
|
23
24
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class TemplateIndex < Riddle::Configuration::Section
|
4
|
+
include Riddle::Configuration::IndexSettings
|
5
|
+
|
6
|
+
def self.settings
|
7
|
+
Riddle::Configuration::IndexSettings.settings
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_accessor :parent
|
11
|
+
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
@type = 'template'
|
15
|
+
|
16
|
+
initialize_settings
|
17
|
+
end
|
18
|
+
|
19
|
+
def render
|
20
|
+
raise ConfigurationError, "#{@name} #{@parent}" unless valid?
|
21
|
+
|
22
|
+
inherited_name = "#{name}"
|
23
|
+
inherited_name << " : #{parent}" if parent
|
24
|
+
(
|
25
|
+
["index #{inherited_name}", "{"] +
|
26
|
+
settings_body +
|
27
|
+
["}", ""]
|
28
|
+
).join("\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid?
|
32
|
+
@name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class TSVSource < Riddle::Configuration::Source
|
4
|
+
def self.settings
|
5
|
+
[:type, :tsvpipe_command, :tsvpipe_attr_field, :tsvpipe_attr_multi]
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor *self.settings
|
9
|
+
|
10
|
+
def initialize(name, type = 'tsvpipe')
|
11
|
+
@name, @type = name, type
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
super && (@tsvpipe_command || @parent)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/riddle/query/select.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Riddle::Query::Select
|
2
2
|
def initialize
|
3
|
-
@values = [
|
3
|
+
@values = []
|
4
4
|
@indices = []
|
5
5
|
@matching = nil
|
6
6
|
@wheres = {}
|
@@ -8,6 +8,8 @@ class Riddle::Query::Select
|
|
8
8
|
@where_nots = {}
|
9
9
|
@where_not_alls = {}
|
10
10
|
@group_by = nil
|
11
|
+
@group_best = nil
|
12
|
+
@having = []
|
11
13
|
@order_by = nil
|
12
14
|
@order_within_group_by = nil
|
13
15
|
@offset = nil
|
@@ -20,6 +22,11 @@ class Riddle::Query::Select
|
|
20
22
|
self
|
21
23
|
end
|
22
24
|
|
25
|
+
def prepend_values(*values)
|
26
|
+
@values.insert 0, *values
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
23
30
|
def from(*indices)
|
24
31
|
@indices += indices
|
25
32
|
self
|
@@ -55,6 +62,16 @@ class Riddle::Query::Select
|
|
55
62
|
self
|
56
63
|
end
|
57
64
|
|
65
|
+
def group_best(count)
|
66
|
+
@group_best = count
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def having(*conditions)
|
71
|
+
@having += conditions
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
58
75
|
def order_by(order)
|
59
76
|
@order_by = order
|
60
77
|
self
|
@@ -81,13 +98,14 @@ class Riddle::Query::Select
|
|
81
98
|
end
|
82
99
|
|
83
100
|
def to_sql
|
84
|
-
sql = "SELECT #{
|
101
|
+
sql = "SELECT #{ extended_values } FROM #{ @indices.join(', ') }"
|
85
102
|
sql << " WHERE #{ combined_wheres }" if wheres?
|
86
|
-
sql << "
|
103
|
+
sql << " #{group_prefix} #{escape_column(@group_by)}" if !@group_by.nil?
|
87
104
|
unless @order_within_group_by.nil?
|
88
|
-
sql << " WITHIN GROUP ORDER BY #{
|
105
|
+
sql << " WITHIN GROUP ORDER BY #{escape_columns(@order_within_group_by)}"
|
89
106
|
end
|
90
|
-
sql << "
|
107
|
+
sql << " HAVING #{@having.join(' AND ')}" unless @having.empty?
|
108
|
+
sql << " ORDER BY #{escape_columns(@order_by)}" if !@order_by.nil?
|
91
109
|
sql << " #{limit_clause}" unless @limit.nil? && @offset.nil?
|
92
110
|
sql << " #{options_clause}" unless @options.empty?
|
93
111
|
|
@@ -96,17 +114,27 @@ class Riddle::Query::Select
|
|
96
114
|
|
97
115
|
private
|
98
116
|
|
117
|
+
def extended_values
|
118
|
+
@values.empty? ? '*' : @values.join(', ')
|
119
|
+
end
|
120
|
+
|
121
|
+
def group_prefix
|
122
|
+
['GROUP', @group_best, 'BY'].compact.join(' ')
|
123
|
+
end
|
124
|
+
|
99
125
|
def wheres?
|
100
126
|
!(@wheres.empty? && @where_alls.empty? && @where_nots.empty? && @where_not_alls.empty? && @matching.nil?)
|
101
127
|
end
|
102
128
|
|
103
129
|
def combined_wheres
|
130
|
+
wheres = wheres_to_s
|
131
|
+
|
104
132
|
if @matching.nil?
|
105
|
-
|
106
|
-
elsif
|
133
|
+
wheres
|
134
|
+
elsif wheres.empty?
|
107
135
|
"MATCH(#{Riddle::Query.quote @matching})"
|
108
136
|
else
|
109
|
-
"MATCH(#{Riddle::Query.quote @matching}) AND #{
|
137
|
+
"MATCH(#{Riddle::Query.quote @matching}) AND #{wheres}"
|
110
138
|
end
|
111
139
|
end
|
112
140
|
|
@@ -128,13 +156,15 @@ class Riddle::Query::Select
|
|
128
156
|
exclusive_filter_comparison_and_value key, value
|
129
157
|
}.join(' OR ') + ')'
|
130
158
|
}
|
131
|
-
).flatten.join(' AND ')
|
159
|
+
).flatten.compact.join(' AND ')
|
132
160
|
end
|
133
161
|
|
134
162
|
def filter_comparison_and_value(attribute, value)
|
135
163
|
case value
|
136
164
|
when Array
|
137
|
-
|
165
|
+
if !value.flatten.empty?
|
166
|
+
"#{escape_column(attribute)} IN (#{value.collect { |val| filter_value(val) }.join(', ')})"
|
167
|
+
end
|
138
168
|
when Range
|
139
169
|
"#{escape_column(attribute)} BETWEEN #{filter_value(value.first)} AND #{filter_value(value.last)}"
|
140
170
|
else
|
@@ -145,7 +175,9 @@ class Riddle::Query::Select
|
|
145
175
|
def exclusive_filter_comparison_and_value(attribute, value)
|
146
176
|
case value
|
147
177
|
when Array
|
148
|
-
|
178
|
+
if !value.flatten.empty?
|
179
|
+
"#{escape_column(attribute)} NOT IN (#{value.collect { |val| filter_value(val) }.join(', ')})"
|
180
|
+
end
|
149
181
|
when Range
|
150
182
|
"#{escape_column(attribute)} < #{filter_value(value.first)} OR #{attribute} > #{filter_value(value.last)}"
|
151
183
|
else
|
@@ -161,6 +193,8 @@ class Riddle::Query::Select
|
|
161
193
|
0
|
162
194
|
when Time
|
163
195
|
value.to_i
|
196
|
+
when Date
|
197
|
+
Time.utc(value.year, value.month, value.day).to_i
|
164
198
|
else
|
165
199
|
value
|
166
200
|
end
|
@@ -190,11 +224,17 @@ class Riddle::Query::Select
|
|
190
224
|
end
|
191
225
|
|
192
226
|
def escape_column(column)
|
193
|
-
if column.to_s
|
227
|
+
if column.to_s[/\A[`@]/] || column.to_s[/\A\w+\(/]
|
194
228
|
column
|
195
229
|
else
|
196
230
|
column_name, *extra = column.to_s.split(' ')
|
197
231
|
extra.unshift("`#{column_name}`").compact.join(' ')
|
198
232
|
end
|
199
233
|
end
|
234
|
+
|
235
|
+
def escape_columns(columns)
|
236
|
+
columns.to_s.split(/,\s*/).collect { |column|
|
237
|
+
escape_column(column)
|
238
|
+
}.join(', ')
|
239
|
+
end
|
200
240
|
end
|
data/riddle.gemspec
CHANGED
@@ -3,13 +3,14 @@ $:.push File.expand_path('../lib', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'riddle'
|
6
|
-
s.version = '1.5.
|
6
|
+
s.version = '1.5.10'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ['Pat Allan']
|
9
9
|
s.email = ['pat@freelancing-gods.com']
|
10
|
-
s.homepage = 'http://pat.github.
|
10
|
+
s.homepage = 'http://pat.github.io/riddle/'
|
11
11
|
s.summary = %q{An API for Sphinx, written in and for Ruby.}
|
12
12
|
s.description = %q{A Ruby API and configuration helper for the Sphinx search service.}
|
13
|
+
s.license = 'MIT'
|
13
14
|
|
14
15
|
s.rubyforge_project = 'riddle'
|
15
16
|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'date'
|
3
|
+
require 'time'
|
2
4
|
|
3
5
|
describe Riddle::Query::Select do
|
4
6
|
let(:query) { Riddle::Query::Select.new }
|
@@ -19,14 +21,19 @@ describe Riddle::Query::Select do
|
|
19
21
|
|
20
22
|
it "handles custom select values" do
|
21
23
|
query.values('@weight').from('foo_core').to_sql.
|
22
|
-
should == 'SELECT
|
24
|
+
should == 'SELECT @weight FROM foo_core'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can prepend select values" do
|
28
|
+
query.values('@weight').prepend_values('foo').from('foo_core').to_sql.
|
29
|
+
should == 'SELECT foo, @weight FROM foo_core'
|
23
30
|
end
|
24
31
|
|
25
32
|
it 'handles basic queries with a search term' do
|
26
33
|
query.from('foo_core').matching('foo').to_sql.
|
27
34
|
should == "SELECT * FROM foo_core WHERE MATCH('foo')"
|
28
35
|
end
|
29
|
-
|
36
|
+
|
30
37
|
it "escapes single quotes in the search terms" do
|
31
38
|
query.from('foo_core').matching("fo'o").to_sql.
|
32
39
|
should == "SELECT * FROM foo_core WHERE MATCH('fo\\'o')"
|
@@ -67,17 +74,33 @@ describe Riddle::Query::Select do
|
|
67
74
|
should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bars` IN (1, 2)"
|
68
75
|
end
|
69
76
|
|
77
|
+
it "ignores filters with empty arrays" do
|
78
|
+
query.from('foo_core').matching('foo').where(:bars => []).to_sql.
|
79
|
+
should == "SELECT * FROM foo_core WHERE MATCH('foo')"
|
80
|
+
end
|
81
|
+
|
70
82
|
it "handles exclusive filters with arrays" do
|
71
83
|
query.from('foo_core').matching('foo').where_not(:bars => [1, 2]).to_sql.
|
72
84
|
should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bars` NOT IN (1, 2)"
|
73
85
|
end
|
74
86
|
|
87
|
+
it "ignores exclusive filters with empty arrays" do
|
88
|
+
query.from('foo_core').matching('foo').where_not(:bars => []).to_sql.
|
89
|
+
should == "SELECT * FROM foo_core WHERE MATCH('foo')"
|
90
|
+
end
|
91
|
+
|
75
92
|
it "handles filters with timestamps" do
|
76
93
|
time = Time.now
|
77
94
|
query.from('foo_core').matching('foo').where(:created_at => time).to_sql.
|
78
95
|
should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `created_at` = #{time.to_i}"
|
79
96
|
end
|
80
97
|
|
98
|
+
it "handles filters with dates" do
|
99
|
+
date = Date.new 2014, 1, 1
|
100
|
+
query.from('foo_core').matching('foo').where(:created_at => date).to_sql.
|
101
|
+
should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `created_at` = #{Time.utc(2014, 1, 1).to_i}"
|
102
|
+
end
|
103
|
+
|
81
104
|
it "handles exclusive filters with timestamps" do
|
82
105
|
time = Time.now
|
83
106
|
query.from('foo_core').matching('foo').where_not(:created_at => time).
|
@@ -94,6 +117,11 @@ describe Riddle::Query::Select do
|
|
94
117
|
should == "SELECT * FROM foo_core WHERE `bars` = 1 AND `bars` = 2"
|
95
118
|
end
|
96
119
|
|
120
|
+
it "handles filters expecting matches on all combinations of values" do
|
121
|
+
query.from('foo_core').where_all(:bars => [[1,2], 3]).to_sql.
|
122
|
+
should == "SELECT * FROM foo_core WHERE `bars` IN (1, 2) AND `bars` = 3"
|
123
|
+
end
|
124
|
+
|
97
125
|
it "handles exclusive filters expecting matches on none of the values" do
|
98
126
|
query.from('foo_core').where_not_all(:bars => [1, 2]).to_sql.
|
99
127
|
should == "SELECT * FROM foo_core WHERE (`bars` <> 1 OR `bars` <> 2)"
|
@@ -104,6 +132,16 @@ describe Riddle::Query::Select do
|
|
104
132
|
should == "SELECT * FROM foo_core GROUP BY `bar_id`"
|
105
133
|
end
|
106
134
|
|
135
|
+
it "handles grouping n-best results" do
|
136
|
+
query.from('foo_core').group_by('bar_id').group_best(3).to_sql.
|
137
|
+
should == "SELECT * FROM foo_core GROUP 3 BY `bar_id`"
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'handles having conditions' do
|
141
|
+
query.from('foo_core').group_by('bar_id').having('bar_id > 10').to_sql.
|
142
|
+
should == "SELECT * FROM foo_core GROUP BY `bar_id` HAVING bar_id > 10"
|
143
|
+
end
|
144
|
+
|
107
145
|
it 'handles ordering' do
|
108
146
|
query.from('foo_core').order_by('bar_id ASC').to_sql.
|
109
147
|
should == 'SELECT * FROM foo_core ORDER BY `bar_id` ASC'
|
@@ -124,6 +162,11 @@ describe Riddle::Query::Select do
|
|
124
162
|
should == 'SELECT * FROM foo_core ORDER BY @weight DESC'
|
125
163
|
end
|
126
164
|
|
165
|
+
it "handles ordering when a sphinx function is passed in" do
|
166
|
+
query.from('foo_core').order_by('weight() DESC').to_sql.
|
167
|
+
should == 'SELECT * FROM foo_core ORDER BY weight() DESC'
|
168
|
+
end
|
169
|
+
|
127
170
|
it 'handles group ordering' do
|
128
171
|
query.from('foo_core').order_within_group_by('bar_id ASC').to_sql.
|
129
172
|
should == 'SELECT * FROM foo_core WITHIN GROUP ORDER BY `bar_id` ASC'
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riddle::Configuration::TemplateIndex do
|
4
|
+
it "should be invalid without a name" do
|
5
|
+
index = Riddle::Configuration::TemplateIndex.new(nil)
|
6
|
+
index.should_not be_valid
|
7
|
+
|
8
|
+
index.name = "test1"
|
9
|
+
index.should be_valid
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise a ConfigurationError if rendering when not valid" do
|
13
|
+
index = Riddle::Configuration::TemplateIndex.new(nil)
|
14
|
+
lambda {
|
15
|
+
index.render
|
16
|
+
}.should raise_error(Riddle::Configuration::ConfigurationError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should render correctly if supplied settings are valid" do
|
20
|
+
index = Riddle::Configuration::TemplateIndex.new("test1")
|
21
|
+
index.docinfo = "extern"
|
22
|
+
index.mlock = 0
|
23
|
+
index.morphologies << "stem_en" << "stem_ru" << "soundex"
|
24
|
+
index.min_stemming_len = 1
|
25
|
+
index.stopword_files << "/var/data/stopwords.txt" << "/var/data/stopwords2.txt"
|
26
|
+
index.wordform_files << "/var/data/wordforms.txt"
|
27
|
+
index.exception_files << "/var/data/exceptions.txt"
|
28
|
+
index.min_word_len = 1
|
29
|
+
index.charset_type = "utf-8"
|
30
|
+
index.charset_table = "0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F"
|
31
|
+
index.ignore_characters << "U+00AD"
|
32
|
+
index.min_prefix_len = 0
|
33
|
+
index.min_infix_len = 0
|
34
|
+
index.prefix_field_names << "filename"
|
35
|
+
index.infix_field_names << "url" << "domain"
|
36
|
+
index.enable_star = true
|
37
|
+
index.ngram_len = 1
|
38
|
+
index.ngram_characters << "U+3000..U+2FA1F"
|
39
|
+
index.phrase_boundaries << "." << "?" << "!" << "U+2026"
|
40
|
+
index.phrase_boundary_step = 100
|
41
|
+
index.html_strip = 0
|
42
|
+
index.html_index_attrs = "img=alt,title; a=title"
|
43
|
+
index.html_remove_element_tags << "style" << "script"
|
44
|
+
index.preopen = 1
|
45
|
+
index.ondisk_dict = 1
|
46
|
+
index.inplace_enable = 1
|
47
|
+
index.inplace_hit_gap = 0
|
48
|
+
index.inplace_docinfo_gap = 0
|
49
|
+
index.inplace_reloc_factor = 0.1
|
50
|
+
index.inplace_write_factor = 0.1
|
51
|
+
index.index_exact_words = 1
|
52
|
+
|
53
|
+
index.render.should == <<-INDEX
|
54
|
+
index test1
|
55
|
+
{
|
56
|
+
type = template
|
57
|
+
docinfo = extern
|
58
|
+
mlock = 0
|
59
|
+
morphology = stem_en, stem_ru, soundex
|
60
|
+
min_stemming_len = 1
|
61
|
+
stopwords = /var/data/stopwords.txt /var/data/stopwords2.txt
|
62
|
+
wordforms = /var/data/wordforms.txt
|
63
|
+
exceptions = /var/data/exceptions.txt
|
64
|
+
min_word_len = 1
|
65
|
+
charset_type = utf-8
|
66
|
+
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
|
67
|
+
ignore_chars = U+00AD
|
68
|
+
min_prefix_len = 0
|
69
|
+
min_infix_len = 0
|
70
|
+
prefix_fields = filename
|
71
|
+
infix_fields = url, domain
|
72
|
+
enable_star = 1
|
73
|
+
ngram_len = 1
|
74
|
+
ngram_chars = U+3000..U+2FA1F
|
75
|
+
phrase_boundary = ., ?, !, U+2026
|
76
|
+
phrase_boundary_step = 100
|
77
|
+
html_strip = 0
|
78
|
+
html_index_attrs = img=alt,title; a=title
|
79
|
+
html_remove_elements = style, script
|
80
|
+
preopen = 1
|
81
|
+
ondisk_dict = 1
|
82
|
+
inplace_enable = 1
|
83
|
+
inplace_hit_gap = 0
|
84
|
+
inplace_docinfo_gap = 0
|
85
|
+
inplace_reloc_factor = 0.1
|
86
|
+
inplace_write_factor = 0.1
|
87
|
+
index_exact_words = 1
|
88
|
+
}
|
89
|
+
INDEX
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Riddle::Configuration::TSVSource do
|
4
|
+
it "should be invalid without an tsvpipe command, name and type if there's no parent" do
|
5
|
+
source = Riddle::Configuration::TSVSource.new("tsv1")
|
6
|
+
source.should_not be_valid
|
7
|
+
|
8
|
+
source.tsvpipe_command = "ls /var/null"
|
9
|
+
source.should be_valid
|
10
|
+
|
11
|
+
source.name = nil
|
12
|
+
source.should_not be_valid
|
13
|
+
|
14
|
+
source.name = "tsv1"
|
15
|
+
source.type = nil
|
16
|
+
source.should_not be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be invalid without only a name and type if there is a parent" do
|
20
|
+
source = Riddle::Configuration::TSVSource.new("tsv1")
|
21
|
+
source.should_not be_valid
|
22
|
+
|
23
|
+
source.parent = "tsvparent"
|
24
|
+
source.should be_valid
|
25
|
+
|
26
|
+
source.name = nil
|
27
|
+
source.should_not be_valid
|
28
|
+
|
29
|
+
source.name = "tsv1"
|
30
|
+
source.type = nil
|
31
|
+
source.should_not be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise a ConfigurationError if rendering when not valid" do
|
35
|
+
source = Riddle::Configuration::TSVSource.new("tsv1")
|
36
|
+
lambda {
|
37
|
+
source.render
|
38
|
+
}.should raise_error(Riddle::Configuration::ConfigurationError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should render correctly when valid" do
|
42
|
+
source = Riddle::Configuration::TSVSource.new("tsv1")
|
43
|
+
source.tsvpipe_command = "ls /var/null"
|
44
|
+
|
45
|
+
source.render.should == <<-TSVSOURCE
|
46
|
+
source tsv1
|
47
|
+
{
|
48
|
+
type = tsvpipe
|
49
|
+
tsvpipe_command = ls /var/null
|
50
|
+
}
|
51
|
+
TSVSOURCE
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2014-01-11 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- lib/riddle/configuration/section.rb
|
87
87
|
- lib/riddle/configuration/source.rb
|
88
88
|
- lib/riddle/configuration/sql_source.rb
|
89
|
+
- lib/riddle/configuration/template_index.rb
|
90
|
+
- lib/riddle/configuration/tsv_source.rb
|
89
91
|
- lib/riddle/configuration/xml_source.rb
|
90
92
|
- lib/riddle/controller.rb
|
91
93
|
- lib/riddle/query.rb
|
@@ -246,15 +248,17 @@ files:
|
|
246
248
|
- spec/unit/configuration/searchd_spec.rb
|
247
249
|
- spec/unit/configuration/source_spec.rb
|
248
250
|
- spec/unit/configuration/sql_source_spec.rb
|
251
|
+
- spec/unit/configuration/template_index_spec.rb
|
252
|
+
- spec/unit/configuration/tsv_source_spec.rb
|
249
253
|
- spec/unit/configuration/xml_source_spec.rb
|
250
254
|
- spec/unit/configuration_spec.rb
|
251
255
|
- spec/unit/filter_spec.rb
|
252
256
|
- spec/unit/message_spec.rb
|
253
257
|
- spec/unit/response_spec.rb
|
254
258
|
- spec/unit/riddle_spec.rb
|
255
|
-
homepage: http://pat.github.
|
256
|
-
licenses:
|
257
|
-
|
259
|
+
homepage: http://pat.github.io/riddle/
|
260
|
+
licenses:
|
261
|
+
- MIT
|
258
262
|
metadata: {}
|
259
263
|
|
260
264
|
post_install_message:
|
@@ -432,6 +436,8 @@ test_files:
|
|
432
436
|
- spec/unit/configuration/searchd_spec.rb
|
433
437
|
- spec/unit/configuration/source_spec.rb
|
434
438
|
- spec/unit/configuration/sql_source_spec.rb
|
439
|
+
- spec/unit/configuration/template_index_spec.rb
|
440
|
+
- spec/unit/configuration/tsv_source_spec.rb
|
435
441
|
- spec/unit/configuration/xml_source_spec.rb
|
436
442
|
- spec/unit/configuration_spec.rb
|
437
443
|
- spec/unit/filter_spec.rb
|