thinking-sphinx 5.0.0 → 5.1.0
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/.circleci/config.yml +150 -0
- data/.travis.yml +4 -4
- data/Appraisals +6 -0
- data/CHANGELOG.markdown +21 -1
- data/README.textile +2 -2
- data/bin/loadsphinx +13 -5
- data/lib/thinking_sphinx.rb +0 -2
- data/lib/thinking_sphinx/active_record.rb +1 -0
- data/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb +1 -1
- data/lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb +21 -0
- data/lib/thinking_sphinx/callbacks/appender.rb +26 -14
- data/lib/thinking_sphinx/connection.rb +4 -0
- data/lib/thinking_sphinx/connection/client.rb +6 -1
- data/lib/thinking_sphinx/errors.rb +1 -1
- data/lib/thinking_sphinx/real_time/index.rb +1 -3
- data/lib/thinking_sphinx/settings.rb +12 -9
- data/spec/acceptance/geosearching_spec.rb +13 -3
- data/spec/acceptance/sql_deltas_spec.rb +12 -0
- data/spec/acceptance/support/sphinx_helpers.rb +4 -4
- data/spec/internal/app/indices/article_index.rb +0 -1
- data/spec/internal/app/indices/colour_index.rb +7 -0
- data/spec/internal/app/models/colour.rb +2 -0
- data/spec/internal/app/models/tee.rb +3 -0
- data/spec/internal/config/database.yml +6 -1
- data/spec/internal/db/schema.rb +1 -0
- data/spec/thinking_sphinx/active_record/sql_source_spec.rb +3 -3
- data/spec/thinking_sphinx/connection/mri_spec.rb +49 -0
- data/thinking-sphinx.gemspec +1 -1
- metadata +11 -7
- data/spec/acceptance/connection_spec.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6245e3b98964aeb5e2540fd59d908458ee5596ed3eb8a1210dee732d95a8e061
|
4
|
+
data.tar.gz: 78e991ec45835c311bba7db38c6c1ba8d2c97fec02c448b6e63a667debeb90d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 043e7a4c5670d5e2371e38c27be22d7dae0c762e16f4f7e9c020c7794200cb9ce5c3f0455e692bfb8dba4fb7a8b4aa47de88a7add179c81f6f4fb294bc4b6d9c
|
7
|
+
data.tar.gz: 6800fe7314fff4316b347f71f216702cb340b7e6ca7df7a609b93b082375b86dba044ea06efcdb56b3f898a1647cedbd486dd833d82ed7ad1a5c8de8625fa81d
|
@@ -0,0 +1,150 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
orbs:
|
4
|
+
ruby: circleci/ruby@1.0
|
5
|
+
|
6
|
+
workflows:
|
7
|
+
test:
|
8
|
+
jobs:
|
9
|
+
- test:
|
10
|
+
name: "Sphinx 2.2.11 with MySQL"
|
11
|
+
database: mysql2
|
12
|
+
sphinx_version: 2.2.11
|
13
|
+
sphinx_engine: sphinx
|
14
|
+
debian: jessie
|
15
|
+
ruby: '2.4.6'
|
16
|
+
- test:
|
17
|
+
name: "Sphinx 2.2.11 with PostgreSQL"
|
18
|
+
database: postgresql
|
19
|
+
sphinx_version: 2.2.11
|
20
|
+
sphinx_engine: sphinx
|
21
|
+
debian: jessie
|
22
|
+
ruby: '2.4.6'
|
23
|
+
- test:
|
24
|
+
name: "Sphinx 3.3.1 with MySQL"
|
25
|
+
database: mysql2
|
26
|
+
sphinx_version: 3.3.1
|
27
|
+
sphinx_engine: sphinx
|
28
|
+
debian: buster
|
29
|
+
matrix:
|
30
|
+
parameters:
|
31
|
+
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
|
32
|
+
# - test:
|
33
|
+
# database: postgresql
|
34
|
+
# sphinx_version: 3.3.1
|
35
|
+
# sphinx_engine: sphinx
|
36
|
+
# matrix:
|
37
|
+
# parameters:
|
38
|
+
# ruby: [ '2.4', '2.5', '2.6', '2.7' ]
|
39
|
+
- test:
|
40
|
+
name: "Manticore 2.8.2 with MySQL"
|
41
|
+
database: mysql2
|
42
|
+
sphinx_version: 2.8.2
|
43
|
+
sphinx_engine: manticore
|
44
|
+
debian: stretch
|
45
|
+
matrix:
|
46
|
+
parameters:
|
47
|
+
ruby: [ '2.4.9', '2.5.8', '2.6.6' ]
|
48
|
+
- test:
|
49
|
+
name: "Manticore 2.8.2 with PostgreSQL"
|
50
|
+
database: postgresql
|
51
|
+
sphinx_version: 2.8.2
|
52
|
+
sphinx_engine: manticore
|
53
|
+
debian: stretch
|
54
|
+
matrix:
|
55
|
+
parameters:
|
56
|
+
ruby: [ '2.4.9', '2.5.8', '2.6.6' ]
|
57
|
+
- test:
|
58
|
+
name: "Manticore 3.5.4 with MySQL"
|
59
|
+
database: mysql2
|
60
|
+
sphinx_version: 3.5.4
|
61
|
+
sphinx_engine: manticore
|
62
|
+
debian: buster
|
63
|
+
matrix:
|
64
|
+
parameters:
|
65
|
+
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
|
66
|
+
- test:
|
67
|
+
name: "Manticore 3.5.4 with PostgreSQL"
|
68
|
+
database: postgresql
|
69
|
+
sphinx_version: 3.5.4
|
70
|
+
sphinx_engine: manticore
|
71
|
+
debian: buster
|
72
|
+
matrix:
|
73
|
+
parameters:
|
74
|
+
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
|
75
|
+
|
76
|
+
jobs:
|
77
|
+
test:
|
78
|
+
parameters:
|
79
|
+
ruby:
|
80
|
+
type: string
|
81
|
+
database:
|
82
|
+
type: string
|
83
|
+
sphinx_version:
|
84
|
+
type: string
|
85
|
+
sphinx_engine:
|
86
|
+
type: string
|
87
|
+
debian:
|
88
|
+
type: string
|
89
|
+
|
90
|
+
docker:
|
91
|
+
- image: circleci/ruby:<< parameters.ruby >>-<< parameters.debian >>
|
92
|
+
|
93
|
+
- image: circleci/postgres:10
|
94
|
+
environment:
|
95
|
+
POSTGRES_USER: postgres
|
96
|
+
POSTGRES_PASSWORD: thinking_sphinx
|
97
|
+
POSTGRES_DB: thinking_sphinx
|
98
|
+
|
99
|
+
- image: circleci/mysql:5.7
|
100
|
+
environment:
|
101
|
+
MYSQL_ROOT_PASSWORD: thinking_sphinx
|
102
|
+
MYSQL_DATABASE: thinking_sphinx
|
103
|
+
|
104
|
+
working_directory: ~/app
|
105
|
+
|
106
|
+
steps:
|
107
|
+
- checkout
|
108
|
+
|
109
|
+
- restore_cache:
|
110
|
+
keys:
|
111
|
+
- v1-dependencies-<< parameters.ruby >>
|
112
|
+
|
113
|
+
- run:
|
114
|
+
name: install bundler
|
115
|
+
command: |
|
116
|
+
if [ "<< parameters.ruby >>" == "2.7.2" ]; then
|
117
|
+
export BUNDLER_VERSION=2.1.4
|
118
|
+
else
|
119
|
+
export BUNDLER_VERSION=1.17.3
|
120
|
+
fi
|
121
|
+
export BUNDLE_PATH=vendor/bundle
|
122
|
+
gem install bundler:$BUNDLER_VERSION
|
123
|
+
|
124
|
+
- run:
|
125
|
+
name: install dependencies
|
126
|
+
command: |
|
127
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
128
|
+
bundle update
|
129
|
+
|
130
|
+
- run:
|
131
|
+
name: set up appraisal
|
132
|
+
command: bundle exec appraisal update
|
133
|
+
|
134
|
+
- save_cache:
|
135
|
+
paths:
|
136
|
+
- ./vendor/bundle
|
137
|
+
key: v1-dependencies-<< parameters.ruby >>
|
138
|
+
|
139
|
+
- run:
|
140
|
+
name: set up sphinx
|
141
|
+
command: "./bin/loadsphinx << parameters.sphinx_version >> << parameters.sphinx_engine >>"
|
142
|
+
|
143
|
+
- run:
|
144
|
+
name: tests
|
145
|
+
environment:
|
146
|
+
CI: "true"
|
147
|
+
DATABASE: << parameters.database >>
|
148
|
+
SPHINX_VERSION: << parameters.sphinx_version >>
|
149
|
+
SPHINX_ENGINE: << parameters.sphinx_engine >>
|
150
|
+
command: bundle exec appraisal rspec
|
data/.travis.yml
CHANGED
@@ -19,12 +19,12 @@ env:
|
|
19
19
|
matrix:
|
20
20
|
- DATABASE=mysql2 SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
|
21
21
|
- DATABASE=postgresql SPHINX_VERSION=2.2.11 SPHINX_ENGINE=sphinx
|
22
|
-
- DATABASE=mysql2 SPHINX_VERSION=3.
|
22
|
+
- DATABASE=mysql2 SPHINX_VERSION=3.3.1 SPHINX_ENGINE=sphinx
|
23
23
|
- DATABASE=mysql2 SPHINX_VERSION=2.8.2 SPHINX_ENGINE=manticore
|
24
24
|
- DATABASE=postgresql SPHINX_VERSION=2.8.2 SPHINX_ENGINE=manticore
|
25
|
-
- DATABASE=mysql2 SPHINX_VERSION=3.
|
26
|
-
- DATABASE=postgresql SPHINX_VERSION=3.
|
27
|
-
# - DATABASE=postgresql SPHINX_VERSION=3.
|
25
|
+
- DATABASE=mysql2 SPHINX_VERSION=3.5.0 SPHINX_ENGINE=manticore
|
26
|
+
- DATABASE=postgresql SPHINX_VERSION=3.5.0 SPHINX_ENGINE=manticore
|
27
|
+
# - DATABASE=postgresql SPHINX_VERSION=3.3.1 SPHINX_ENGINE=sphinx
|
28
28
|
sudo: false
|
29
29
|
addons:
|
30
30
|
postgresql: '9.4'
|
data/Appraisals
CHANGED
@@ -33,3 +33,9 @@ appraise 'rails_6_0' do
|
|
33
33
|
gem 'mysql2', '~> 0.5.0', :platform => :ruby
|
34
34
|
gem 'pg', '~> 1.0', :platform => :ruby
|
35
35
|
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.5
|
36
|
+
|
37
|
+
appraise 'rails_6_1' do
|
38
|
+
gem 'rails', '~> 6.1.0'
|
39
|
+
gem 'mysql2', '~> 0.5.0', :platform => :ruby
|
40
|
+
gem 'pg', '~> 1.0', :platform => :ruby
|
41
|
+
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f >= 2.5
|
data/CHANGELOG.markdown
CHANGED
@@ -2,6 +2,26 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project (at least, from v3.0.0 onwards) are documented in this file.
|
4
4
|
|
5
|
+
## 5.1.0 - 2020-12-28
|
6
|
+
|
7
|
+
[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.1.0)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* Support for Sphinx v3.3 and Manticore v3.5.
|
12
|
+
* Support for Rails 6.1 (via [joiner](https://rubygems.org/gems/joiner) v0.6.0).
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
* `enable_star` is no longer available as a configuration option, as it's been enabled by default in Sphinx since v2.2.2, and is no longer allowed in Sphinx v3.3.1.
|
17
|
+
* All timestamp attributes are now considered plain integer values from Sphinx's perspective. Sphinx was already expecting integers, but since Sphinx v3.3.1 it doesn't recognise timestamps as a data type. There is no functional difference with this change - Thinking Sphinx was always converting times to their UNIX epoch integer values.
|
18
|
+
* Allow configuration of the maximum statement length ([@kalsan](https://github.com/kalsan) in [#1179](https://github.com/pat/thinking-sphinx/pull/1179)).
|
19
|
+
* Respect `:path` values to navigate associations for Thinking Sphinx callbacks on SQL-backed indices. Discussed in [#1182](https://github.com/pat/thinking-sphinx/issues/1182).
|
20
|
+
|
21
|
+
### Fixed
|
22
|
+
|
23
|
+
* Don't attempt to update delta flags on frozen model instances.
|
24
|
+
|
5
25
|
## 5.0.0 - 2020-07-20
|
6
26
|
|
7
27
|
[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.0.0)
|
@@ -20,7 +40,7 @@ All notable changes to this project (at least, from v3.0.0 onwards) are document
|
|
20
40
|
* Remove internal uses of `send`, replaced with `public_send` as that's available in all supported Ruby versions.
|
21
41
|
* Deletion statements are simplified by avoiding the need to calculate document keys/offsets (@njakobsen via [#1134](https://github.com/pat/thinking-sphinx/issues/1134)).
|
22
42
|
* Real-time data is deleted before replacing it, to avoid duplicate data when offsets change (@njakobsen via [#1134](https://github.com/pat/thinking-sphinx/issues/1134)).
|
23
|
-
* Use `reference_name` as per custom `index_set_class` definitions. Previously, the class method was called on `ThinkingSphinx::IndexSet` even if a custom subclass was configured. (As per
|
43
|
+
* Use `reference_name` as per custom `index_set_class` definitions. Previously, the class method was called on `ThinkingSphinx::IndexSet` even if a custom subclass was configured. (As per discussions with @kalsan in [#1172](https://github.com/pat/thinking-sphinx/issues/1172).)
|
24
44
|
|
25
45
|
## 4.4.1 - 2019-08-23
|
26
46
|
|
data/README.textile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
h1. Thinking Sphinx
|
2
2
|
|
3
|
-
Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v5.
|
3
|
+
Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v5.1.0.
|
4
4
|
|
5
5
|
h2. Upgrading
|
6
6
|
|
@@ -14,7 +14,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp
|
|
14
14
|
|
15
15
|
<pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
|
16
16
|
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
|
17
|
-
gem 'thinking-sphinx', '~> 5.
|
17
|
+
gem 'thinking-sphinx', '~> 5.1'</code></pre>
|
18
18
|
|
19
19
|
The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
|
20
20
|
|
data/bin/loadsphinx
CHANGED
@@ -14,7 +14,7 @@ load_sphinx () {
|
|
14
14
|
format="deb"
|
15
15
|
distro="trusty";;
|
16
16
|
2.2.11)
|
17
|
-
url="http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~
|
17
|
+
url="http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~jessie_amd64.deb"
|
18
18
|
format="deb";;
|
19
19
|
3.0.3)
|
20
20
|
url="http://sphinxsearch.com/files/sphinx-3.0.3-facc3fb-linux-amd64.tar.gz"
|
@@ -23,7 +23,10 @@ load_sphinx () {
|
|
23
23
|
url="http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64.tar.gz"
|
24
24
|
format="gz";;
|
25
25
|
3.2.1)
|
26
|
-
url="http://
|
26
|
+
url="http://sphinxsearch.com/files/sphinx-3.2.1-f152e0b-linux-amd64.tar.gz"
|
27
|
+
format="gz";;
|
28
|
+
3.3.1)
|
29
|
+
url="http://sphinxsearch.com/files/sphinx-3.3.1-b72d67b-linux-amd64.tar.gz"
|
27
30
|
format="gz";;
|
28
31
|
*)
|
29
32
|
echo "No Sphinx version $version available"
|
@@ -37,7 +40,9 @@ load_sphinx () {
|
|
37
40
|
|
38
41
|
if [ "$format" == "deb" ]; then
|
39
42
|
curl --location $url -o sphinx.deb
|
40
|
-
sudo apt-get install
|
43
|
+
sudo apt-get install libodbc1
|
44
|
+
sudo dpkg -i ./sphinx.deb
|
45
|
+
sudo apt-get install -f
|
41
46
|
else
|
42
47
|
curl $url -o sphinx.tar.gz
|
43
48
|
tar -zxvf sphinx.tar.gz
|
@@ -54,16 +59,19 @@ load_manticore () {
|
|
54
59
|
2.7.5)
|
55
60
|
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.7.5/manticore_2.7.5-181204-4a31c54-release-stemmer.xenial_amd64-bin.deb";;
|
56
61
|
2.8.2)
|
57
|
-
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-
|
62
|
+
url="https://github.com/manticoresoftware/manticoresearch/releases/download/2.8.2/manticore_2.8.2-190402-4e81114d-release-stemmer.stretch_amd64-bin.deb";;
|
58
63
|
3.4.2)
|
59
64
|
url="https://github.com/manticoresoftware/manticoresearch/releases/download/3.4.2/manticore_3.4.2-200410-6903305-release.xenial_amd64-bin.deb";;
|
65
|
+
3.5.4)
|
66
|
+
url="https://repo.manticoresearch.com/repository/manticoresearch_buster/pool/m/manticore/manticore_3.5.4-201211-13f8d08d_amd64.deb";;
|
60
67
|
*)
|
61
68
|
echo "No Manticore version $version available"
|
62
69
|
exit 1;;
|
63
70
|
esac
|
64
71
|
|
65
72
|
curl --location $url -o manticore.deb
|
66
|
-
sudo
|
73
|
+
sudo dpkg -i ./manticore.deb
|
74
|
+
sudo apt-get install -f
|
67
75
|
}
|
68
76
|
|
69
77
|
if [ "$engine" == "sphinx" ]; then
|
data/lib/thinking_sphinx.rb
CHANGED
@@ -17,8 +17,6 @@ require 'active_support/core_ext/module/delegation'
|
|
17
17
|
require 'active_support/core_ext/module/attribute_accessors'
|
18
18
|
|
19
19
|
module ThinkingSphinx
|
20
|
-
MAXIMUM_STATEMENT_LENGTH = (2 ** 23) - 5
|
21
|
-
|
22
20
|
def self.count(query = '', options = {})
|
23
21
|
search_for_ids(query, options).total_entries
|
24
22
|
end
|
@@ -29,6 +29,7 @@ require 'thinking_sphinx/active_record/source_joins'
|
|
29
29
|
require 'thinking_sphinx/active_record/sql_builder'
|
30
30
|
require 'thinking_sphinx/active_record/sql_source'
|
31
31
|
|
32
|
+
require 'thinking_sphinx/active_record/callbacks/association_delta_callbacks'
|
32
33
|
require 'thinking_sphinx/active_record/callbacks/delete_callbacks'
|
33
34
|
require 'thinking_sphinx/active_record/callbacks/delta_callbacks'
|
34
35
|
require 'thinking_sphinx/active_record/callbacks/update_callbacks'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
|
4
|
+
def initialize(path)
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
def after_commit(instance)
|
9
|
+
Array(objects_for(instance)).each do |object|
|
10
|
+
object.update :delta => true unless object.frozen?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_reader :path
|
17
|
+
|
18
|
+
def objects_for(instance)
|
19
|
+
path.inject(instance) { |object, method| object.send method }
|
20
|
+
end
|
21
|
+
end
|
@@ -13,29 +13,41 @@ class ThinkingSphinx::Callbacks::Appender
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call
|
16
|
+
add_core_callbacks
|
17
|
+
add_delta_callbacks if behaviours.include?(:deltas)
|
18
|
+
add_real_time_callbacks if behaviours.include?(:real_time)
|
19
|
+
add_update_callbacks if behaviours.include?(:updates)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :model, :reference, :options, :block
|
25
|
+
|
26
|
+
def add_core_callbacks
|
16
27
|
model.after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks
|
28
|
+
end
|
17
29
|
|
18
|
-
|
30
|
+
def add_delta_callbacks
|
31
|
+
if path.empty?
|
19
32
|
model.before_save ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
|
20
33
|
model.after_commit ThinkingSphinx::ActiveRecord::Callbacks::DeltaCallbacks
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
reference, path, &block
|
26
|
-
)
|
27
|
-
end
|
28
|
-
|
29
|
-
if behaviours.include?(:updates)
|
30
|
-
model.after_update(
|
31
|
-
ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
|
34
|
+
else
|
35
|
+
model.after_commit(
|
36
|
+
ThinkingSphinx::ActiveRecord::Callbacks::AssociationDeltaCallbacks
|
37
|
+
.new(path)
|
32
38
|
)
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
|
-
|
42
|
+
def add_real_time_callbacks
|
43
|
+
model.after_save ThinkingSphinx::RealTime.callback_for(
|
44
|
+
reference, path, &block
|
45
|
+
)
|
46
|
+
end
|
37
47
|
|
38
|
-
|
48
|
+
def add_update_callbacks
|
49
|
+
model.after_update ThinkingSphinx::ActiveRecord::Callbacks::UpdateCallbacks
|
50
|
+
end
|
39
51
|
|
40
52
|
def behaviours
|
41
53
|
options[:behaviours] || []
|
@@ -39,7 +39,7 @@ class ThinkingSphinx::Connection::Client
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def check(statements)
|
42
|
-
if statements.length >
|
42
|
+
if statements.length > maximum_statement_length
|
43
43
|
exception = ThinkingSphinx::QueryLengthError.new
|
44
44
|
exception.statement = statements
|
45
45
|
raise exception
|
@@ -56,6 +56,11 @@ class ThinkingSphinx::Connection::Client
|
|
56
56
|
@client = nil
|
57
57
|
end
|
58
58
|
|
59
|
+
def maximum_statement_length
|
60
|
+
@maximum_statement_length ||= ThinkingSphinx::Configuration.instance.
|
61
|
+
settings['maximum_statement_length']
|
62
|
+
end
|
63
|
+
|
59
64
|
def perform(statements)
|
60
65
|
results_for statements
|
61
66
|
rescue => error
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
class ThinkingSphinx::QueryLengthError < ThinkingSphinx::SphinxError
|
39
39
|
def message
|
40
40
|
<<-MESSAGE
|
41
|
-
The supplied SphinxQL statement is #{statement.length} characters long. The maximum allowed length is #{ThinkingSphinx::
|
41
|
+
The supplied SphinxQL statement is #{statement.length} characters long. The maximum allowed length is #{ThinkingSphinx::Configuration.instance.settings['maximum_statement_length']}.
|
42
42
|
|
43
43
|
If this error has been raised during real-time index population, it's probably due to overly large batches of records being processed at once. The default is 1000, but you can lower it on a per-environment basis in config/thinking_sphinx.yml:
|
44
44
|
|
@@ -65,12 +65,10 @@ class ThinkingSphinx::RealTime::Index < Riddle::Configuration::RealtimeIndex
|
|
65
65
|
|
66
66
|
def collection_for(attribute)
|
67
67
|
case attribute.type
|
68
|
-
when :integer, :boolean
|
68
|
+
when :integer, :boolean, :timestamp
|
69
69
|
attribute.multi? ? @rt_attr_multi : @rt_attr_uint
|
70
70
|
when :string
|
71
71
|
@rt_attr_string
|
72
|
-
when :timestamp
|
73
|
-
@rt_attr_timestamp
|
74
72
|
when :float
|
75
73
|
@rt_attr_float
|
76
74
|
when :bigint
|
@@ -11,14 +11,15 @@ class ThinkingSphinx::Settings
|
|
11
11
|
lemmatizer_base mysql_ssl_cert mysql_ssl_key mysql_ssl_ca
|
12
12
|
].freeze
|
13
13
|
DEFAULTS = {
|
14
|
-
"configuration_file"
|
15
|
-
"indices_location"
|
16
|
-
"pid_file"
|
17
|
-
"log"
|
18
|
-
"query_log"
|
19
|
-
"binlog_path"
|
20
|
-
"workers"
|
21
|
-
"mysql_encoding"
|
14
|
+
"configuration_file" => "config/ENVIRONMENT.sphinx.conf",
|
15
|
+
"indices_location" => "db/sphinx/ENVIRONMENT",
|
16
|
+
"pid_file" => "log/ENVIRONMENT.sphinx.pid",
|
17
|
+
"log" => "log/ENVIRONMENT.searchd.log",
|
18
|
+
"query_log" => "log/ENVIRONMENT.searchd.query.log",
|
19
|
+
"binlog_path" => "tmp/binlog/ENVIRONMENT",
|
20
|
+
"workers" => "threads",
|
21
|
+
"mysql_encoding" => "utf8",
|
22
|
+
"maximum_statement_length" => (2 ** 23) - 5
|
22
23
|
}.freeze
|
23
24
|
|
24
25
|
def self.call(configuration)
|
@@ -62,7 +63,9 @@ class ThinkingSphinx::Settings
|
|
62
63
|
|
63
64
|
def defaults
|
64
65
|
DEFAULTS.inject({}) do |hash, (key, value)|
|
65
|
-
|
66
|
+
if value.is_a?(String)
|
67
|
+
value = value.gsub("ENVIRONMENT", framework.environment)
|
68
|
+
end
|
66
69
|
|
67
70
|
if FILE_KEYS.include?(key)
|
68
71
|
hash[key] = absolute value
|
@@ -38,10 +38,20 @@ describe 'Searching by latitude and longitude', :live => true do
|
|
38
38
|
expected = {:mysql => 250326.906250, :postgresql => 250331.234375}
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
adapter = nil
|
42
|
+
|
43
|
+
if ActiveRecord::VERSION::STRING.to_f > 6.0
|
44
|
+
adapter = ActiveRecord::Base.configurations.configs_for.first.adapter
|
45
|
+
elsif ActiveRecord::VERSION::STRING.to_f > 5.2
|
46
|
+
adapter = ActiveRecord::Base.configurations.configs_for.first.config["adapter"]
|
47
|
+
else
|
48
|
+
adapter = ActiveRecord::Base.configurations['test']['adapter']
|
49
|
+
end
|
50
|
+
|
51
|
+
if adapter[/postgres/]
|
52
|
+
expect(cities.first.geodist).to be_within(0.01).of(expected[:postgresql])
|
43
53
|
else # mysql
|
44
|
-
expect(cities.first.geodist).to
|
54
|
+
expect(cities.first.geodist).to be_within(0.01).of(expected[:mysql])
|
45
55
|
end
|
46
56
|
end
|
47
57
|
|
@@ -63,4 +63,16 @@ describe 'SQL delta indexing', :live => true do
|
|
63
63
|
|
64
64
|
expect(Book.search('Gaiman').to_a).to eq([book])
|
65
65
|
end
|
66
|
+
|
67
|
+
it "updates associated models" do
|
68
|
+
colour = Colour.create(:name => 'green')
|
69
|
+
sleep 0.25
|
70
|
+
|
71
|
+
expect(Colour.search('green').to_a).to eq([colour])
|
72
|
+
|
73
|
+
tee = colour.tees.create
|
74
|
+
sleep 0.25
|
75
|
+
|
76
|
+
expect(Colour.search(:with => {:tee_ids => tee.id}).to_a).to eq([colour])
|
77
|
+
end
|
66
78
|
end
|
@@ -6,22 +6,22 @@ module SphinxHelpers
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def index(*indices)
|
9
|
-
sleep 0.5 if ENV['
|
9
|
+
sleep 0.5 if ENV['CI']
|
10
10
|
|
11
11
|
yield if block_given?
|
12
12
|
|
13
13
|
sphinx.index *indices
|
14
14
|
sleep 0.25
|
15
|
-
sleep 0.5 if ENV['
|
15
|
+
sleep 0.5 if ENV['CI']
|
16
16
|
end
|
17
17
|
|
18
18
|
def merge
|
19
|
-
sleep 0.5 if ENV['
|
19
|
+
sleep 0.5 if ENV['CI']
|
20
20
|
sleep 0.5
|
21
21
|
|
22
22
|
sphinx.merge
|
23
23
|
sleep 1.5
|
24
|
-
sleep 0.5 if ENV['
|
24
|
+
sleep 0.5 if ENV['CI']
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -10,7 +10,6 @@ ThinkingSphinx::Index.define :article, :with => :active_record do
|
|
10
10
|
has taggings.created_at, :as => :taggings_at, :type => :timestamp
|
11
11
|
|
12
12
|
set_property :min_infix_len => 4
|
13
|
-
set_property :enable_star => true
|
14
13
|
end
|
15
14
|
|
16
15
|
ThinkingSphinx::Index.define :article, :with => :active_record,
|
@@ -1,6 +1,11 @@
|
|
1
1
|
test:
|
2
2
|
adapter: <%= ENV['DATABASE'] || 'mysql2' %>
|
3
3
|
database: thinking_sphinx
|
4
|
-
username: <%= ENV['DATABASE'] == 'postgresql' ?
|
4
|
+
username: <%= ENV['DATABASE'] == 'postgresql' ? 'postgres' : 'root' %>
|
5
|
+
<% if ENV["CI"] %>
|
6
|
+
password: thinking_sphinx
|
7
|
+
host: 127.0.0.1
|
8
|
+
port: <%= ENV['DATABASE'] == 'postgresql' ? 5432 : 3306 %>
|
9
|
+
<% end %>
|
5
10
|
min_messages: warning
|
6
11
|
encoding: utf8
|
data/spec/internal/db/schema.rb
CHANGED
@@ -325,14 +325,14 @@ describe ThinkingSphinx::ActiveRecord::SQLSource do
|
|
325
325
|
expect(source.sql_attr_string).to include('name')
|
326
326
|
end
|
327
327
|
|
328
|
-
it "adds timestamp attributes to
|
328
|
+
it "adds timestamp attributes to sql_attr_uint" do
|
329
329
|
source.attributes << double('attribute')
|
330
330
|
allow(presenter).to receive_messages :declaration => 'created_at',
|
331
|
-
:collection_type => :
|
331
|
+
:collection_type => :uint
|
332
332
|
|
333
333
|
source.render
|
334
334
|
|
335
|
-
expect(source.
|
335
|
+
expect(source.sql_attr_uint).to include('created_at')
|
336
336
|
end
|
337
337
|
|
338
338
|
it "adds float attributes to sql_attr_float" do
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe ThinkingSphinx::Connection::MRI do
|
4
|
+
subject { described_class.new :host => "127.0.0.1", :port => 9306 }
|
5
|
+
|
6
|
+
let(:client) { double :client, :query => "result", :next_result => false }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
allow(Mysql2::Client).to receive(:new).and_return(client)
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
ThinkingSphinx::Configuration.reset
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#execute" do
|
17
|
+
it "sends the query to the client" do
|
18
|
+
subject.execute "SELECT QUERY"
|
19
|
+
|
20
|
+
expect(client).to have_received(:query).with("SELECT QUERY")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns a result" do
|
24
|
+
expect(subject.execute("SELECT QUERY")).to eq("result")
|
25
|
+
end
|
26
|
+
|
27
|
+
context "with long queries" do
|
28
|
+
let(:maximum) { (2 ** 23) - 5 }
|
29
|
+
let(:query) { String.new "SELECT * FROM book_core WHERE MATCH('')" }
|
30
|
+
let(:difference) { maximum - query.length }
|
31
|
+
|
32
|
+
it 'does not allow overly long queries' do
|
33
|
+
expect {
|
34
|
+
subject.execute(query.insert(-3, 'a' * (difference + 5)))
|
35
|
+
}.to raise_error(ThinkingSphinx::QueryLengthError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'does not allow queries longer than specified in the settings' do
|
39
|
+
ThinkingSphinx::Configuration.reset
|
40
|
+
|
41
|
+
write_configuration('maximum_statement_length' => maximum - 5)
|
42
|
+
|
43
|
+
expect {
|
44
|
+
subject.execute(query.insert(-3, 'a' * (difference)))
|
45
|
+
}.to raise_error(ThinkingSphinx::QueryLengthError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end if RUBY_PLATFORM != 'java'
|
data/thinking-sphinx.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -174,6 +174,7 @@ executables:
|
|
174
174
|
extensions: []
|
175
175
|
extra_rdoc_files: []
|
176
176
|
files:
|
177
|
+
- ".circleci/config.yml"
|
177
178
|
- ".gitignore"
|
178
179
|
- ".travis.yml"
|
179
180
|
- Appraisals
|
@@ -197,6 +198,7 @@ files:
|
|
197
198
|
- lib/thinking_sphinx/active_record/attribute/type.rb
|
198
199
|
- lib/thinking_sphinx/active_record/attribute/values.rb
|
199
200
|
- lib/thinking_sphinx/active_record/base.rb
|
201
|
+
- lib/thinking_sphinx/active_record/callbacks/association_delta_callbacks.rb
|
200
202
|
- lib/thinking_sphinx/active_record/callbacks/delete_callbacks.rb
|
201
203
|
- lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb
|
202
204
|
- lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb
|
@@ -356,7 +358,6 @@ files:
|
|
356
358
|
- spec/acceptance/attribute_updates_spec.rb
|
357
359
|
- spec/acceptance/batch_searching_spec.rb
|
358
360
|
- spec/acceptance/big_integers_spec.rb
|
359
|
-
- spec/acceptance/connection_spec.rb
|
360
361
|
- spec/acceptance/excerpts_spec.rb
|
361
362
|
- spec/acceptance/facets_spec.rb
|
362
363
|
- spec/acceptance/geosearching_spec.rb
|
@@ -393,6 +394,7 @@ files:
|
|
393
394
|
- spec/internal/app/indices/book_index.rb
|
394
395
|
- spec/internal/app/indices/car_index.rb
|
395
396
|
- spec/internal/app/indices/city_index.rb
|
397
|
+
- spec/internal/app/indices/colour_index.rb
|
396
398
|
- spec/internal/app/indices/product_index.rb
|
397
399
|
- spec/internal/app/indices/tee_index.rb
|
398
400
|
- spec/internal/app/indices/user_index.rb
|
@@ -461,6 +463,7 @@ files:
|
|
461
463
|
- spec/thinking_sphinx/commands/stop_spec.rb
|
462
464
|
- spec/thinking_sphinx/configuration/minimum_fields_spec.rb
|
463
465
|
- spec/thinking_sphinx/configuration_spec.rb
|
466
|
+
- spec/thinking_sphinx/connection/mri_spec.rb
|
464
467
|
- spec/thinking_sphinx/connection_spec.rb
|
465
468
|
- spec/thinking_sphinx/deletion_spec.rb
|
466
469
|
- spec/thinking_sphinx/deltas/default_delta_spec.rb
|
@@ -508,7 +511,7 @@ homepage: https://pat.github.io/thinking-sphinx/
|
|
508
511
|
licenses:
|
509
512
|
- MIT
|
510
513
|
metadata: {}
|
511
|
-
post_install_message:
|
514
|
+
post_install_message:
|
512
515
|
rdoc_options: []
|
513
516
|
require_paths:
|
514
517
|
- lib
|
@@ -524,7 +527,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
524
527
|
version: '0'
|
525
528
|
requirements: []
|
526
529
|
rubygems_version: 3.0.3
|
527
|
-
signing_key:
|
530
|
+
signing_key:
|
528
531
|
specification_version: 4
|
529
532
|
summary: A smart wrapper over Sphinx for ActiveRecord
|
530
533
|
test_files:
|
@@ -533,7 +536,6 @@ test_files:
|
|
533
536
|
- spec/acceptance/attribute_updates_spec.rb
|
534
537
|
- spec/acceptance/batch_searching_spec.rb
|
535
538
|
- spec/acceptance/big_integers_spec.rb
|
536
|
-
- spec/acceptance/connection_spec.rb
|
537
539
|
- spec/acceptance/excerpts_spec.rb
|
538
540
|
- spec/acceptance/facets_spec.rb
|
539
541
|
- spec/acceptance/geosearching_spec.rb
|
@@ -570,6 +572,7 @@ test_files:
|
|
570
572
|
- spec/internal/app/indices/book_index.rb
|
571
573
|
- spec/internal/app/indices/car_index.rb
|
572
574
|
- spec/internal/app/indices/city_index.rb
|
575
|
+
- spec/internal/app/indices/colour_index.rb
|
573
576
|
- spec/internal/app/indices/product_index.rb
|
574
577
|
- spec/internal/app/indices/tee_index.rb
|
575
578
|
- spec/internal/app/indices/user_index.rb
|
@@ -638,6 +641,7 @@ test_files:
|
|
638
641
|
- spec/thinking_sphinx/commands/stop_spec.rb
|
639
642
|
- spec/thinking_sphinx/configuration/minimum_fields_spec.rb
|
640
643
|
- spec/thinking_sphinx/configuration_spec.rb
|
644
|
+
- spec/thinking_sphinx/connection/mri_spec.rb
|
641
645
|
- spec/thinking_sphinx/connection_spec.rb
|
642
646
|
- spec/thinking_sphinx/deletion_spec.rb
|
643
647
|
- spec/thinking_sphinx/deltas/default_delta_spec.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'acceptance/spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'Connections', :live => true do
|
6
|
-
let(:maximum) { (2 ** 23) - 5 }
|
7
|
-
let(:query) { String.new "SELECT * FROM book_core WHERE MATCH('')" }
|
8
|
-
let(:difference) { maximum - query.length }
|
9
|
-
|
10
|
-
it 'allows normal length queries through' do
|
11
|
-
expect {
|
12
|
-
ThinkingSphinx::Connection.take do |connection|
|
13
|
-
connection.execute query.insert(-3, 'a' * difference)
|
14
|
-
end
|
15
|
-
}.to_not raise_error
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'does not allow overly long queries' do
|
19
|
-
expect {
|
20
|
-
ThinkingSphinx::Connection.take do |connection|
|
21
|
-
connection.execute query.insert(-3, 'a' * (difference + 5))
|
22
|
-
end
|
23
|
-
}.to raise_error(ThinkingSphinx::QueryLengthError)
|
24
|
-
end
|
25
|
-
end
|