riddle 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0743ec72ebf70708fe0cbdbfb63d44c307e7c798
4
- data.tar.gz: a46b1a68d1104d21d7d63b52d712e313e6b48c6a
3
+ metadata.gz: 9703ab2715784c618307e9081ebf69b2bea0ed08
4
+ data.tar.gz: 9570d8929bbb278985a468570c34ddc6cf702502
5
5
  SHA512:
6
- metadata.gz: 6df640330c4c08a437e831de9c2a78c0d0fe55618bdad21ad36e80ef0b908f0f8f6445533c2a395122a0121cdc298dacb723ca98712d277f86ab2e72df8af9ea
7
- data.tar.gz: 097f533203b245d59c2cdaccc52cca61bfefacb551e0c58e974e9a777d97b01e45c4ed843095d7119dc9889d6d83591926d0f5437ad330229d74fbeb6a81416e
6
+ metadata.gz: 0d097ac478f457a842116c00ba098ebc0d70b19e5fad881b53aa7721ac2058d75e3c63a05647185e9c58931bfa06adce4e5c8405018197f0bf6cdce11794dfe2
7
+ data.tar.gz: 2375a83b6ff035108262bc185483ecbe7a13a7abedf676fb2df20ab293b52eefa4fee4df1b9d003b642600b0109461e9d75e6bf715718d1bbc0d2a8b30bda69b
data/.travis.yml CHANGED
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1
4
4
  - 2.2
5
+ - 2.3.3
6
+ - 2.4.0
5
7
  env:
6
8
  - SPHINX_BIN=/usr/local/sphinx-2.0.10/bin SPHINX_VERSION=2.0.10
7
9
  - SPHINX_BIN=/usr/local/sphinx-2.1.9/bin SPHINX_VERSION=2.1.9
data/HISTORY CHANGED
@@ -1,3 +1,9 @@
1
+ 2.1.0 - January 5th 2017
2
+ - Wrap string attribute filter values in single quotes.
3
+ - Remove direct references to FixNum to avoid MRI 2.4 warnings.
4
+ - Remove escaped line-endings while parsing.
5
+ - Escape word-operators like MAYBE, NEAR etc (Jonathan del Strother)
6
+
1
7
  2.0.0 - September 25th 2016
2
8
  - Start and stop commands now accept a verbose option.
3
9
  - Failed commands (as determined by a non-zero status code) raise a Riddle::CommandFailedError exception.
data/README.markdown CHANGED
@@ -14,7 +14,7 @@ Riddle is available as a gem, so you can install it directly:
14
14
 
15
15
  Or include it in a Gemfile:
16
16
 
17
- gem 'riddle', '~> 1.5.12'
17
+ gem 'riddle', '~> 2.1.0'
18
18
 
19
19
  ## Usage
20
20
 
@@ -1,6 +1,8 @@
1
1
  module Riddle
2
2
  class Configuration
3
3
  class Searchd
4
+ NUMBER = 1.class
5
+
4
6
  def valid?
5
7
  set_listen
6
8
 
@@ -10,14 +12,14 @@ module Riddle
10
12
  private
11
13
 
12
14
  def set_listen
13
- @listen = @listen.to_s if @listen.is_a?(Fixnum)
15
+ @listen = @listen.to_s if @listen.is_a?(NUMBER)
14
16
 
15
17
  return unless @listen.nil? || @listen.empty?
16
18
 
17
19
  @listen = []
18
20
  @listen << @port.to_s if @port
19
21
  @listen << "9306:mysql41" if @mysql41.is_a?(TrueClass)
20
- @listen << "#{@mysql41}:mysql41" if @mysql41.is_a?(Fixnum)
22
+ @listen << "#{@mysql41}:mysql41" if @mysql41.is_a?(NUMBER)
21
23
 
22
24
  @listen.each { |l| l.insert(0, "#{@address}:") } if @address
23
25
  end
@@ -132,7 +132,7 @@ class Riddle::Configuration::Parser
132
132
  SETTING_PATTERN = /^(\w+)\s*=\s*(.*)$/
133
133
 
134
134
  def initialize(input)
135
- @stream = StringIO.new(input)
135
+ @stream = StringIO.new(input.gsub("\\\n", ''))
136
136
  @sections = {}
137
137
  end
138
138
 
data/lib/riddle/query.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  module Riddle::Query
2
+ ESCAPE_CHARACTERS = /[\(\)\|\-!@~\/"\/\^\$\\><&=\?]/
3
+ # http://sphinxsearch.com/docs/current/extended-syntax.html
4
+ ESCAPE_WORDS = /\b(?:MAYBE|NEAR|PARAGRAPH|SENTENCE|ZONE|ZONESPAN)\b/
5
+
2
6
  def self.connection(address = '127.0.0.1', port = 9312)
3
7
  require 'mysql2'
4
8
 
@@ -99,7 +103,8 @@ module Riddle::Query
99
103
  end
100
104
 
101
105
  def self.escape(string)
102
- string.gsub(/[\(\)\|\-!@~\/"\/\^\$\\><&=\?]/) { |match| "\\#{match}" }
106
+ string.gsub(ESCAPE_CHARACTERS) { |match| "\\#{match}" }
107
+ .gsub(ESCAPE_WORDS) { |word| "\\#{word}" }
103
108
  end
104
109
 
105
110
  def self.quote(string)
@@ -195,6 +195,8 @@ class Riddle::Query::Select
195
195
  value.to_i
196
196
  when Date
197
197
  Time.utc(value.year, value.month, value.day).to_i
198
+ when String
199
+ "'#{value.gsub("'", "\\'")}'"
198
200
  else
199
201
  value
200
202
  end
data/riddle.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'riddle'
6
- s.version = '2.0.0'
6
+ s.version = '2.1.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Pat Allan']
9
9
  s.email = ['pat@freelancing-gods.com']
@@ -122,6 +122,11 @@ describe Riddle::Query::Select do
122
122
  should == "SELECT * FROM foo_core WHERE MATCH('foo') AND `bar` BETWEEN 1 AND 5"
123
123
  end
124
124
 
125
+ it "handles filters with strings" do
126
+ query.from('foo_core').where(:bar => 'baz').to_sql.
127
+ should == "SELECT * FROM foo_core WHERE `bar` = 'baz'"
128
+ end
129
+
125
130
  it "handles filters expecting matches on all values" do
126
131
  query.from('foo_core').where_all(:bars => [1, 2]).to_sql.
127
132
  should == "SELECT * FROM foo_core WHERE `bars` = 1 AND `bars` = 2"
@@ -83,5 +83,15 @@ describe Riddle::Query do
83
83
  Riddle::Query.escape(reserved).should == "\\#{reserved}"
84
84
  end
85
85
  end
86
+
87
+ it "escapes word-operators correctly" do
88
+ operators = ['MAYBE', 'NEAR', 'PARAGRAPH', 'SENTENCE', 'ZONE', 'ZONESPAN']
89
+ operators.each do |operator|
90
+ base = "string with #{operator} operator"
91
+ Riddle::Query.escape(base).should == base.gsub(operator, "\\#{operator}")
92
+ end
93
+
94
+ Riddle::Query.escape("FIND THE ZONES").should == "FIND THE ZONES"
95
+ end
86
96
  end
87
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  version: '0'
290
290
  requirements: []
291
291
  rubyforge_project: riddle
292
- rubygems_version: 2.4.8
292
+ rubygems_version: 2.6.8
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: An API for Sphinx, written in and for Ruby.