Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'release/v1.5.11'

  • Loading branch information...
commit 5159636daa875520f7c37c770120fa0e8ff225f6 2 parents bfe2c4c + df3e69f
@pat authored
View
14 .travis.yml
@@ -1,20 +1,14 @@
language: ruby
-before_install:
- - sudo apt-get install postgresql-server-dev-9.1 libmysql++-dev -y
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-1.10_x86_64_12.04.deb
- - sudo dpkg -i fs-sphinx-1.10_x86_64_12.04.deb
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.9_x86_64_12.04.deb
- - sudo dpkg -i fs-sphinx-2.0.9_x86_64_12.04.deb
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.1.4_x86_64_12.04.deb
- - sudo dpkg -i fs-sphinx-2.1.4_x86_64_12.04.deb
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
+ - 2.0.0
+ - 2.1.0
- jruby-18mode
env:
- - SPHINX_BIN=/usr/local/sphinx-1.10/bin SPHINX_VERSION=1.10
- SPHINX_BIN=/usr/local/sphinx-2.0.9/bin SPHINX_VERSION=2.0.9
- - SPHINX_BIN=/usr/local/sphinx-2.1.4/bin SPHINX_VERSION=2.1.4
+ - SPHINX_BIN=/usr/local/sphinx-2.1.3/bin SPHINX_VERSION=2.1.3
+ - SPHINX_BIN=/usr/local/sphinx-2.2.1/bin SPHINX_VERSION=2.2.1
before_script: killall searchd; echo ''
after_script: killall searchd; echo ''
View
8 HISTORY
@@ -1,3 +1,11 @@
+1.5.11 - April 19th 2014
+- Riddle::Query.escape covers = and & characters.
+- Hold onto address and port settings when crafting the equivalent listen setting, but don't render them.
+- Allow for Sphinx's common settings section (Trevor Smith). Optional and initially disabled.
+- Allow for multiple attributes in GROUP BY clauses (J. Garcia).
+- Riddle::Query.escape covers < and > characters.
+- The parser should not presume indexer and searchd sections exist.
+
1.5.10 - January 11th 2014
- SELECT values can be prepended as well as the existing append support.
- New settings for Sphinx 2.2.1.
View
8 lib/riddle/0.9.9/configuration/searchd.rb
@@ -3,7 +3,6 @@ class Configuration
class Searchd
def valid?
set_listen
- clear_deprecated
!( @listen.nil? || @listen.empty? || @pid_file.nil? )
end
@@ -23,11 +22,8 @@ def set_listen
@listen.each { |l| l.insert(0, "#{@address}:") } if @address
end
- def clear_deprecated
- return if @listen.nil?
-
- @address = nil
- @port = nil
+ def settings
+ @listen.nil? ? super : super - [:address, :port]
end
end
end
View
2  lib/riddle/auto_version.rb
@@ -10,7 +10,7 @@ def self.configure
require 'riddle/1.10'
when /2.0.[12]/
require 'riddle/2.0.1'
- when /2.0.[^12]/, /2.1.\d/
+ when /2.0.[^12]/, /2.1.\d/, /2.2.\d/
require 'riddle/2.1.0'
end
end
View
6 lib/riddle/configuration.rb
@@ -1,6 +1,7 @@
require 'riddle/configuration/section'
require 'riddle/configuration/index_settings'
+require 'riddle/configuration/common'
require 'riddle/configuration/distributed_index'
require 'riddle/configuration/index'
require 'riddle/configuration/indexer'
@@ -20,7 +21,7 @@ class Configuration
class ConfigurationError < StandardError #:nodoc:
end
- attr_reader :indices, :searchd, :sources
+ attr_reader :common, :indices, :searchd, :sources
attr_accessor :indexer
def self.parse!(input)
@@ -28,6 +29,7 @@ def self.parse!(input)
end
def initialize
+ @common = Riddle::Configuration::Common.new
@indexer = Riddle::Configuration::Indexer.new
@searchd = Riddle::Configuration::Searchd.new
@indices = []
@@ -36,7 +38,7 @@ def initialize
def render
(
- [@indexer.render, @searchd.render] +
+ [@common.render, @indexer.render, @searchd.render] +
@sources.collect { |source| source.render } +
@indices.collect { |index| index.render }
).join("\n")
View
26 lib/riddle/configuration/common.rb
@@ -0,0 +1,26 @@
+module Riddle
+ class Configuration
+ class Common < Riddle::Configuration::Section
+ def self.settings
+ [
+ :lemmatizer_base, :json_autoconv_numbers, :json_autoconv_keynames,
+ :on_json_attr_error, :rlp_root, :rlp_environment, :rlp_max_batch_size,
+ :rlp_max_batch_docs
+ ]
+ end
+
+ attr_accessor :common_sphinx_configuration, *settings
+
+ def render
+ return unless common_sphinx_configuration
+ raise ConfigurationError unless valid?
+
+ (
+ ["common", "{"] +
+ settings_body +
+ ["}", ""]
+ ).join("\n")
+ end
+ end
+ end
+end
View
23 lib/riddle/configuration/indexer.rb
@@ -5,13 +5,19 @@ def self.settings
[
:mem_limit, :max_iops, :max_iosize, :max_xmlpipe2_field,
:write_buffer, :max_file_field_buffer, :on_file_field_error,
- :lemmatizer_base, :lemmatizer_cache, :json_autoconv_numbers,
- :on_json_attr_error, :rlp_root, :rlp_environment,
- :rlp_max_batch_size, :rlp_max_batch_docs
+ :lemmatizer_cache
+ ] + shared_settings
+ end
+
+ def self.shared_settings
+ [
+ :lemmatizer_base, :json_autoconv_numbers, :json_autoconv_keynames,
+ :on_json_attr_error, :rlp_root, :rlp_environment, :rlp_max_batch_size,
+ :rlp_max_batch_docs
]
end
- attr_accessor *self.settings
+ attr_accessor :common_sphinx_configuration, *settings
def render
raise ConfigurationError unless valid?
@@ -22,6 +28,15 @@ def render
["}", ""]
).join("\n")
end
+
+
+ private
+
+ def settings
+ settings = self.class.settings
+ settings -= self.class.shared_settings if common_sphinx_configuration
+ settings
+ end
end
end
end
View
9 lib/riddle/configuration/parser.rb
@@ -24,6 +24,7 @@ def initialize(input)
end
def parse!
+ set_common
set_indexer
set_searchd
set_sources
@@ -65,12 +66,16 @@ def each_with_prefix(prefix)
end
end
+ def set_common
+ set_settings configuration.common, inner['common'] || {}
+ end
+
def set_indexer
- set_settings configuration.indexer, inner['indexer']
+ set_settings configuration.indexer, inner['indexer'] || {}
end
def set_searchd
- set_settings configuration.searchd, inner['searchd']
+ set_settings configuration.searchd, inner['searchd'] || {}
end
def set_sources
View
6 lib/riddle/configuration/section.rb
@@ -12,7 +12,7 @@ def valid?
private
def settings_body
- self.class.settings.select { |setting|
+ settings.select { |setting|
!send(setting).nil?
}.collect { |setting|
if send(setting) == ""
@@ -50,6 +50,10 @@ def rendered_setting(setting)
output
end
+
+ def settings
+ self.class.settings
+ end
end
end
end
View
2  lib/riddle/query.rb
@@ -99,7 +99,7 @@ def self.translate_value(value)
end
def self.escape(string)
- string.gsub(/[\(\)\|\-!@~\/"\/\^\$\\]/) { |match| "\\#{match}" }
+ string.gsub(/[\(\)\|\-!@~\/"\/\^\$\\><&=]/) { |match| "\\#{match}" }
end
def self.quote(string)
View
2  lib/riddle/query/select.rb
@@ -100,7 +100,7 @@ def with_options(options = {})
def to_sql
sql = "SELECT #{ extended_values } FROM #{ @indices.join(', ') }"
sql << " WHERE #{ combined_wheres }" if wheres?
- sql << " #{group_prefix} #{escape_column(@group_by)}" if !@group_by.nil?
+ sql << " #{group_prefix} #{escape_columns(@group_by)}" if !@group_by.nil?
unless @order_within_group_by.nil?
sql << " WITHIN GROUP ORDER BY #{escape_columns(@order_within_group_by)}"
end
View
2  riddle.gemspec
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
Gem::Specification.new do |s|
s.name = 'riddle'
- s.version = '1.5.10'
+ s.version = '1.5.11'
s.platform = Gem::Platform::RUBY
s.authors = ['Pat Allan']
s.email = ['pat@freelancing-gods.com']
View
3  spec/fixtures/sphinx/configuration.erb
@@ -16,6 +16,7 @@ searchd
read_timeout = 5
max_children = 30
pid_file = <%= fixtures_path %>/sphinx/searchd.pid
+ binlog_path = <%= fixtures_path %>/sphinx/binlog/
}
source peoples
@@ -40,4 +41,4 @@ index people
charset_type = utf-8
enable_star = 1
min_prefix_len = 1
-}
View
7 spec/riddle/auto_version_spec.rb
@@ -78,6 +78,13 @@
Riddle::AutoVersion.configure
end
+ it "should require 2.1.0 if 2.2.1 is being used" do
+ Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
+
+ @controller.stub!(:sphinx_version => '2.2.1-beta')
+ Riddle::AutoVersion.configure
+ end
+
it "should require 2.1.0 if that is the known version" do
Riddle::AutoVersion.should_receive(:require).with('riddle/2.1.0')
View
2  spec/riddle/query_spec.rb
@@ -78,7 +78,7 @@
end
describe '.escape' do
- %w(( ) | - ! @ ~ / ^ $ ").each do |reserved|
+ %w(( ) | - ! @ ~ / ^ $ " > <).each do |reserved|
it "escapes #{reserved}" do
Riddle::Query.escape(reserved).should == "\\#{reserved}"
end
View
2  spec/support/sphinx.rb
@@ -79,6 +79,8 @@ def generate_configuration
File.open('spec/fixtures/sphinx/spec.conf', 'w') { |f|
f.puts ERB.new(template).result(binding)
}
+
+ FileUtils.mkdir_p "spec/fixtures/sphinx/binlog"
end
def index
View
60 spec/unit/configuration/common_spec.rb
@@ -0,0 +1,60 @@
+require 'spec_helper'
+
+describe Riddle::Configuration::Common do
+ it "should always be valid" do
+ common = Riddle::Configuration::Common.new
+ common.should be_valid
+ end
+
+ it "should support Sphinx's common settings" do
+ settings = %w( lemmatizer_base on_json_attr_error json_autoconv_numbers
+ json_autoconv_keynames rlp_root rlp_environment rlp_max_batch_size
+ rlp_max_batch_docs )
+ common = Riddle::Configuration::Common.new
+
+ settings.each do |setting|
+ common.should respond_to(setting.to_sym)
+ common.should respond_to("#{setting}=".to_sym)
+ end
+ end
+
+ it "should render a correct configuration" do
+ common = Riddle::Configuration::Common.new
+ common.common_sphinx_configuration = true
+
+ common.render.should == <<-COMMON
+common
+{
+}
+ COMMON
+
+ common.lemmatizer_base = "/tmp"
+ common.render.should == <<-COMMON
+common
+{
+ lemmatizer_base = /tmp
+}
+ COMMON
+ end
+
+ it "should not be present when common_sphinx_configuration is not set" do
+ common = Riddle::Configuration::Common.new
+ common.render.should be_nil
+ end
+
+ it "should not be present when common_sphinx_configuration is false" do
+ common = Riddle::Configuration::Common.new
+ common.common_sphinx_configuration = false
+ common.render.should be_nil
+ end
+
+ it "should render when common_sphinx_configuration is true" do
+ common = Riddle::Configuration::Common.new
+ common.common_sphinx_configuration = true
+ common.render.should == <<-COMMON
+common
+{
+}
+ COMMON
+ end
+end
View
37 spec/unit/configuration/indexer_spec.rb
@@ -33,4 +33,41 @@
}
INDEXER
end
+
+ it "should render shared settings when common_sphinx_configuration is not set" do
+ indexer = Riddle::Configuration::Indexer.new
+ indexer.rlp_root = '/tmp'
+
+ indexer.render.should == <<-INDEXER
+indexer
+{
+ rlp_root = /tmp
+}
+ INDEXER
+ end
+
+ it "should render shared settings when common_sphinx_configuration is false" do
+ indexer = Riddle::Configuration::Indexer.new
+ indexer.common_sphinx_configuration = false
+ indexer.rlp_root = '/tmp'
+
+ indexer.render.should == <<-INDEXER
+indexer
+{
+ rlp_root = /tmp
+}
+ INDEXER
+ end
+
+ it "should not render shared settings when common_sphinx_configuration is true" do
+ indexer = Riddle::Configuration::Indexer.new
+ indexer.common_sphinx_configuration = true
+ indexer.rlp_root = '/tmp'
+
+ indexer.render.should == <<-INDEXER
+indexer
+{
+}
+ INDEXER
+ end
end
View
53 spec/unit/configuration/searchd_spec.rb
@@ -5,17 +5,17 @@
it "should be invalid without a listen or pid_file" do
searchd = Riddle::Configuration::Searchd.new
searchd.should_not be_valid
-
+
searchd.port = 3312
searchd.should_not be_valid
-
+
searchd.pid_file = "file.pid"
searchd.should be_valid
-
+
searchd.port = nil
searchd.listen = nil
searchd.should_not be_valid
-
+
searchd.listen = "localhost:3312"
searchd.should be_valid
end
@@ -34,13 +34,13 @@
searchd.should_not be_valid
end
end
-
+
it "should raise a ConfigurationError if rendering but not valid" do
searchd = Riddle::Configuration::Searchd.new
searchd.should_not be_valid
lambda { searchd.render }.should raise_error(Riddle::Configuration::ConfigurationError)
end
-
+
it "should support Sphinx's searchd settings" do
settings = %w( listen address port log query_log read_timeout
client_timeout max_children pid_file max_matches seamless_rotate
@@ -48,7 +48,7 @@
max_packet_size mva_updates_pool crash_log_path max_filters
max_filter_values )
searchd = Riddle::Configuration::Searchd.new
-
+
settings.each do |setting|
searchd.should respond_to(setting.to_sym)
searchd.should respond_to("#{setting}=".to_sym)
@@ -109,7 +109,7 @@
searchd.port = 3312
searchd.pid_file = 'file.pid'
searchd.client_key = 'secret'
-
+
if Riddle.loaded_version.to_f >= 0.9
searchd.render.should == <<-SEARCHD
searchd
@@ -130,13 +130,13 @@
SEARCHD
end
end
-
+
if Riddle.loaded_version.to_f >= 0.9
it "should render with mysql41 on the default port if true" do
searchd = Riddle::Configuration::Searchd.new
searchd.mysql41 = true
searchd.pid_file = 'file.pid'
-
+
searchd.render.should == <<-SEARCHD
searchd
{
@@ -145,12 +145,12 @@
}
SEARCHD
end
-
+
it "should render with mysql41 on a given port" do
searchd = Riddle::Configuration::Searchd.new
searchd.mysql41 = 9307
searchd.pid_file = 'file.pid'
-
+
searchd.render.should == <<-SEARCHD
searchd
{
@@ -159,13 +159,13 @@
}
SEARCHD
end
-
+
it "allows for both normal and mysql41 connections" do
searchd = Riddle::Configuration::Searchd.new
searchd.mysql41 = true
searchd.port = 9312
searchd.pid_file = 'file.pid'
-
+
searchd.render.should == <<-SEARCHD
searchd
{
@@ -175,13 +175,13 @@
}
SEARCHD
end
-
+
it "uses given address for mysql41 connections" do
searchd = Riddle::Configuration::Searchd.new
searchd.mysql41 = true
searchd.address = '127.0.0.1'
searchd.pid_file = 'file.pid'
-
+
searchd.render.should == <<-SEARCHD
searchd
{
@@ -190,14 +190,14 @@
}
SEARCHD
end
-
+
it "applies the given address to both normal and mysql41 connections" do
searchd = Riddle::Configuration::Searchd.new
searchd.mysql41 = true
searchd.port = 9312
searchd.address = 'sphinx.server.local'
searchd.pid_file = 'file.pid'
-
+
searchd.render.should == <<-SEARCHD
searchd
{
@@ -207,5 +207,22 @@
}
SEARCHD
end
+
+ it 'maintains the address and port settings without rendering them' do
+ searchd = Riddle::Configuration::Searchd.new
+ searchd.port = 9312
+ searchd.address = 'sphinx.server.local'
+ searchd.pid_file = 'file.pid'
+
+ searchd.render.should == <<-SEARCHD
+searchd
+{
+ listen = sphinx.server.local:9312
+ pid_file = file.pid
+}
+ SEARCHD
+ searchd.address.should == 'sphinx.server.local'
+ searchd.port.should == 9312
+ end
end
end
View
17 spec/unit/message_spec.rb
@@ -1,24 +1,25 @@
+# encoding: BINARY
require 'spec_helper'
describe Riddle::Client::Message do
it "should start with an empty string" do
Riddle::Client::Message.new.to_s.should == ""
end
-
+
it "should append raw data correctly" do
data = [1, 2, 3].pack('NNN')
message = Riddle::Client::Message.new
message.append data
message.to_s.should == data
end
-
+
it "should append strings correctly - with length first" do
str = "something to test with"
message = Riddle::Client::Message.new
message.append_string str
message.to_s.should == [str.length].pack('N') + str
end
-
+
it "should append integers correctly - packed with N" do
message = Riddle::Client::Message.new
message.append_int 234
@@ -54,25 +55,25 @@
message.append_64bit_int "234"
message.to_s.should == "\x00\x00\x00\x00\x00\x00\x00\xEA"
end
-
+
it "should append floats correctly - packed with f" do
message = Riddle::Client::Message.new
message.append_float 1.4
message.to_s.should == [1.4].pack('f').unpack('L*').pack('N')
end
-
+
it "should append a collection of integers correctly" do
message = Riddle::Client::Message.new
message.append_ints 1, 2, 3, 4
message.to_s.should == [1, 2, 3, 4].pack('NNNN')
end
-
+
it "should append a collection of floats correctly" do
message = Riddle::Client::Message.new
message.append_floats 1.0, 1.1, 1.2, 1.3
message.to_s.should == [1.0, 1.1, 1.2, 1.3].pack('ffff').unpack('L*L*L*L*').pack('NNNN')
end
-
+
it "should append an array of strings correctly" do
arr = ["a", "bb", "ccc"]
message = Riddle::Client::Message.new
@@ -80,7 +81,7 @@
message.to_s.should == [3, 1].pack('NN') + "a" + [2].pack('N') + "bb" +
[3].pack('N') + "ccc"
end
-
+
it "should append a variety of objects correctly" do
message = Riddle::Client::Message.new
message.append_int 4
Please sign in to comment.
Something went wrong with that request. Please try again.