thinking-sphinx 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +4 -7
  4. data/HISTORY +27 -0
  5. data/README.textile +38 -218
  6. data/gemfiles/rails_3_2.gemfile +2 -3
  7. data/gemfiles/rails_4_0.gemfile +2 -3
  8. data/gemfiles/rails_4_1.gemfile +2 -3
  9. data/lib/thinking_sphinx.rb +1 -0
  10. data/lib/thinking_sphinx/active_record.rb +1 -0
  11. data/lib/thinking_sphinx/active_record/association_proxy.rb +1 -0
  12. data/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +5 -10
  13. data/lib/thinking_sphinx/active_record/association_proxy/attribute_matcher.rb +38 -0
  14. data/lib/thinking_sphinx/active_record/attribute/type.rb +19 -8
  15. data/lib/thinking_sphinx/active_record/base.rb +3 -1
  16. data/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb +1 -1
  17. data/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +4 -1
  18. data/lib/thinking_sphinx/active_record/index.rb +4 -4
  19. data/lib/thinking_sphinx/active_record/property_query.rb +57 -27
  20. data/lib/thinking_sphinx/active_record/simple_many_query.rb +35 -0
  21. data/lib/thinking_sphinx/capistrano/v3.rb +11 -10
  22. data/lib/thinking_sphinx/configuration.rb +23 -6
  23. data/lib/thinking_sphinx/connection.rb +8 -9
  24. data/lib/thinking_sphinx/errors.rb +7 -2
  25. data/lib/thinking_sphinx/facet.rb +2 -2
  26. data/lib/thinking_sphinx/facet_search.rb +4 -2
  27. data/lib/thinking_sphinx/logger.rb +7 -0
  28. data/lib/thinking_sphinx/masks/group_enumerators_mask.rb +4 -4
  29. data/lib/thinking_sphinx/middlewares/inquirer.rb +2 -2
  30. data/lib/thinking_sphinx/middlewares/sphinxql.rb +6 -2
  31. data/lib/thinking_sphinx/middlewares/stale_id_filter.rb +1 -1
  32. data/lib/thinking_sphinx/real_time/callbacks/real_time_callbacks.rb +6 -1
  33. data/lib/thinking_sphinx/real_time/property.rb +2 -1
  34. data/lib/thinking_sphinx/real_time/transcriber.rb +7 -3
  35. data/lib/thinking_sphinx/search.rb +14 -4
  36. data/lib/thinking_sphinx/search/context.rb +0 -6
  37. data/lib/thinking_sphinx/test.rb +11 -2
  38. data/lib/thinking_sphinx/wildcard.rb +7 -1
  39. data/spec/acceptance/association_scoping_spec.rb +55 -15
  40. data/spec/acceptance/geosearching_spec.rb +8 -2
  41. data/spec/acceptance/real_time_updates_spec.rb +9 -0
  42. data/spec/acceptance/specifying_sql_spec.rb +31 -17
  43. data/spec/internal/app/indices/car_index.rb +5 -0
  44. data/spec/internal/app/models/car.rb +5 -0
  45. data/spec/internal/app/models/category.rb +2 -1
  46. data/spec/internal/app/models/manufacturer.rb +3 -0
  47. data/spec/internal/db/schema.rb +9 -0
  48. data/spec/thinking_sphinx/active_record/attribute/type_spec.rb +7 -0
  49. data/spec/thinking_sphinx/active_record/base_spec.rb +17 -0
  50. data/spec/thinking_sphinx/active_record/callbacks/update_callbacks_spec.rb +2 -1
  51. data/spec/thinking_sphinx/configuration_spec.rb +40 -2
  52. data/spec/thinking_sphinx/errors_spec.rb +21 -0
  53. data/spec/thinking_sphinx/facet_search_spec.rb +6 -6
  54. data/spec/thinking_sphinx/middlewares/inquirer_spec.rb +0 -4
  55. data/spec/thinking_sphinx/middlewares/sphinxql_spec.rb +25 -0
  56. data/spec/thinking_sphinx/middlewares/stale_id_filter_spec.rb +2 -2
  57. data/spec/thinking_sphinx/real_time/callbacks/real_time_callbacks_spec.rb +2 -1
  58. data/spec/thinking_sphinx/search_spec.rb +56 -0
  59. data/spec/thinking_sphinx/wildcard_spec.rb +5 -0
  60. data/thinking-sphinx.gemspec +2 -2
  61. metadata +40 -32
  62. data/sketchpad.rb +0 -58
  63. data/spec/internal/log/.gitignore +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5defbd88cf59aea7a90ef3256c80d41e0c1b351
4
- data.tar.gz: 6a355963b4d9b2e22e47167c5075b592e5e1aef3
3
+ metadata.gz: ff053fbf548b20a5ffe44d2bc171d68d6553dd08
4
+ data.tar.gz: 62849df76201a3ba5c65d7a2dfc6de0d641a7347
5
5
  SHA512:
6
- metadata.gz: 2ed23c4b83609fa9a19ef8d7f2330cd172041d9f193c0fd67bda4abbd1542a90658b6ebcda4942130be414da4ce6037702362a1aa934c5e0768024fcbb331b45
7
- data.tar.gz: dfd43067513b2993a545e15bfc41945d36c84c8b598866818cbff5d348794ab04a4957c4fd44f4fd6c3ef883b1c1af088a21411be929ea73e44f6eba1307a9a5
6
+ metadata.gz: 0c1b3ffb995ccf4588ffc9a3354adfcdc9a5b6eb3feec6ddff4ec791f26fc043557dcfb14e240c47cc80a86202ab6e6d0371b3adca937b6b9e2f9ee740f22370
7
+ data.tar.gz: 63e2df341ccdc388d6227890ddb00073dfdd32611f7427706e886df59dd6483b61530029d16a50c335ad12a7288b43e140701afe4cd69183bd0dc74e21b245c0
data/.gitignore CHANGED
@@ -6,7 +6,8 @@ Gemfile.lock
6
6
  pkg/*
7
7
  spec/internal/config/test.sphinx.conf
8
8
  spec/internal/db/sphinx
9
+ spec/internal/log/*.log
9
10
  !spec/internal/tmp/.gitkeep
10
11
  spec/internal/tmp/*
11
- !spec/internal/tmp/.gitkeep
12
+ tmp
12
13
  _site
@@ -6,19 +6,16 @@ rvm:
6
6
  - jruby-19mode
7
7
  before_install:
8
8
  - gem update --system
9
- - sudo apt-get install postgresql-server-dev-9.1 libmysql++-dev -y
10
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.0.9_x86_64_12.04.deb
11
- - sudo dpkg -i fs-sphinx-2.0.9_x86_64_12.04.deb
12
- - curl -O http://fs-packages.s3.amazonaws.com/fs-sphinx-2.1.4_x86_64_12.04.deb
13
- - sudo dpkg -i fs-sphinx-2.1.4_x86_64_12.04.deb
14
9
  before_script:
15
10
  - "mysql -e 'create database thinking_sphinx;' > /dev/null"
16
11
  - "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null"
17
12
  env:
18
13
  - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.0.9/bin/ SPHINX_VERSION=2.0.9
19
14
  - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.0.9/bin/ SPHINX_VERSION=2.0.9
20
- - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.4/bin/ SPHINX_VERSION=2.1.4
21
- - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.4/bin/ SPHINX_VERSION=2.1.4
15
+ - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.1.3/bin/ SPHINX_VERSION=2.1.3
16
+ - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.1.3/bin/ SPHINX_VERSION=2.1.3
17
+ - DATABASE=mysql2 SPHINX_BIN=/usr/local/sphinx-2.2.1/bin/ SPHINX_VERSION=2.2.1
18
+ - DATABASE=postgresql SPHINX_BIN=/usr/local/sphinx-2.2.1/bin/ SPHINX_VERSION=2.2.1
22
19
  gemfile:
23
20
  - gemfiles/rails_3_2.gemfile
24
21
  - gemfiles/rails_4_0.gemfile
data/HISTORY CHANGED
@@ -1,3 +1,30 @@
1
+ 2014-04-22: 3.1.1
2
+ * [CHANGE] Include full statements when query execution errors are raised (uglier, but more useful when debugging).
3
+ * [FEATURE] Allow for common section in generated Sphinx configuration files for Sphinx 2.2.x (disabled by default, though) (Trevor Smith).
4
+ * [FEATURE] Basic support for HABTM associations and MVAs with query/ranged-query sources.
5
+ * [CHANGE] Connection error messages now mention Sphinx, instead of just MySQL.
6
+ * [FIX] Don't apply attribute-only updates to real-time indices.
7
+ * [FIX] Don't instantiate blank strings (via inheritance type columns) as constants.
8
+ * [FIX] Don't presume all indices for a model have delta pairs, even if one does.
9
+ * [CHANGE] Raise an exception when a referenced column does not exist.
10
+ * [CHANGE] Capistrano tasks use thinking_sphinx_rails_env (defaults to standard environment) (Robert Coleman).
11
+ * [FIX] Always use connection options for connection information.
12
+ * [FIX] respond_to? works reliably with masks (Konstantin Burnaev).
13
+ * [FEATURE] Real-time indices callbacks can be disabled (useful for unit tests).
14
+ * [FEATURE] ThinkingSphinx::Test has a clear method and no-index option for starting for real-time setups.
15
+ * [FIX] Avoid null values in MVA query/ranged-query sources.
16
+ * [CHANGE] Alias group and count columns for easier referencing in other clauses.
17
+ * [FEATURE] Allow disabling of distributed indices.
18
+ * [FIX] Don't send unicode null characters to real-time Sphinx indices.
19
+ * [FIX] :populate option is now respected for single-model searches.
20
+ * [FIX] :thinking_sphinx_roles is now used consistently in Capistrano v3 tasks.
21
+ * [CHANGE] Log real-time index updates (Demian Ferreiro).
22
+ * [FIX] Only expand log directory if it exists.
23
+ * [FIX] Handle JDBC connection errors appropriately (Adam Hutchison).
24
+ * [FIX] Fixing wildcarding of Unicode strings.
25
+ * [CHANGE] All indices now respond to a public attributes method.
26
+ * [FIX] Improved handling of association searches with real-time indices, including via has_many :though associations (Rob Anderton).
27
+
1
28
  2014-01-11: 3.1.0
2
29
  * [CHANGE] Updating Riddle requirement to >= 1.5.10.
3
30
  * [CHANGE] Extracting join generation into its own gem: Joiner.
@@ -1,235 +1,54 @@
1
1
  h1. Thinking Sphinx
2
2
 
3
- Welcome to Thinking Sphinx version 3 - a complete rewrite from past versions. TS v3.0.x will work with Rails 3.1-4.0, and TS v3.1.x will work with Rails 3.2 and newer.
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 v3.1.1.
4
4
 
5
- h2. Installation
6
-
7
- It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby:
8
-
9
- <pre><code>gem 'mysql2', '0.3.13', :platform => :ruby
10
- gem 'jdbc-mysql', '5.1.28', :platform => :jruby
11
- gem 'thinking-sphinx', '3.1.0'</code></pre>
12
-
13
- The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
14
-
15
- As for Sphinx itself, you need to make sure it's compiled with MySQL support, even if you're using PostgreSQL as your database - which is normally the default, but Homebrew can be too smart sometimes. If that's your compiling tool of choice, make sure you install with the @--mysql@ flag:
16
-
17
- <pre><code>brew install sphinx --mysql</code></pre>
18
-
19
- h2. Usage
20
-
21
- Indexes are no longer defined in models - they now live in `app/indices` (which you will need to create yourself). Each index should get its own file, and look something like this:
22
-
23
- <pre><code># app/indices/article_index.rb
24
- ThinkingSphinx::Index.define :article, :with => :active_record do
25
- indexes title, content
26
- indexes user.name, :as => :user
27
- indexes user.articles.title, :as => :related_titles
28
-
29
- has published
30
- end</code></pre>
31
-
32
- You'll notice the first argument is the model name downcased and as a symbol, and we are specifying the processor - @:active_record@. Everything inside the block is just like previous versions of Thinking Sphinx. Same goes for most settings in @config/thinking_sphinx.yml@ (formerly @config/sphinx.yml@) unless noted below.
33
-
34
- When you're defining indices for namespaced models, use a lowercase string with /'s for namespacing as the model reference:
35
-
36
- <pre><code># For a model named Blog::Article:
37
- ThinkingSphinx::Index.define 'blog/article', :with => :active_record</code></pre>
38
-
39
- Other changes:
40
- * SphinxQL is now used instead of the old socket connections (hence the dependency on the @mysql2@ gem).
41
- * Specifying a different port for Sphinx to use (in @config/thinking_sphinx.yml@) should be done with the mysql41 setting, not the port setting.
42
- * The searchd_log and searchd_query_log settings are now log and query_log (matching their Sphinx names).
43
- * searchd_file_path is now indices_location.
44
- * config_file is now configuration_file.
45
- * You'll need to include @ThinkingSphinx::Scopes@ into your models if you want to use Sphinx scopes. Default scopes can be set as follows:
46
-
47
- <pre><code>class Person < ActiveRecord::Base
48
- include ThinkingSphinx::Scopes
49
-
50
- sphinx_scope(:date_order) { {:order => :created_at} }
51
- default_sphinx_scope :date_order
52
- # ...
53
- end</code></pre>
54
-
55
- * The match mode is always extended - SphinxQL doesn't know any other way.
56
- * ActiveRecord::Base.set_sphinx_primary_key is now an option in the index definition (alongside @:with@ in the above example): @:primary_key@ - and therefore is no longer inheritable between models.
57
- * If you're explicitly setting a time attribute's type, instead of @:datetime@ it should now be @:timestamp@.
58
- * Delta arguments are passed in as an option of the @define@ call, not within the block:
59
-
60
- <pre><code>ThinkingSphinx::Index.define :article, :with => :active_record, :delta => true do
61
- # ...
62
- end</code></pre>
63
-
64
- * Suspended deltas are no longer called from the model, but like so instead:
65
-
66
- <pre><code>ThinkingSphinx::Deltas.suspend :article do
67
- article.update_attributes(:title => 'pancakes')
68
- end</code></pre>
69
-
70
- * Excerpts through search results behaves the same way, provided you add ExcerptsPane into the mix (read the section below on search results, glazes and panes). Excerpt options (like @:before_match@, @:after_match@ and @:chunk_separator@) can be passed through when searching under the @:excerpts@ option:
71
-
72
- <pre><code>ThinkingSphinx.search 'foo',
73
- :excerpts => {:chunk_separator => ' -- '}</code></pre>
74
-
75
- * When indexing models on classes that are using single-table inheritance (STI), make sure you have a database index on the @type@ column. Thinking Sphinx will need to determine which subclasses are available, and we can't rely on Rails having loaded all models at any given point, so it queries the database. If you don't want this to happen, set :skip_sti to true in your search call, and ensure that the :classes option holds all classes that could be returned.
76
-
77
- <pre><code>ThinkingSphinx.search 'pancakes',
78
- :skip_sti => true,
79
- :classes => [User, AdminUser, SupportUser]</code></pre>
80
-
81
- * The option @:rank_mode@ has now become @:ranker@ - and the options (as strings or symbols) are as follows: proximity_bm25, bm25, none, wordcount, proximity, matchany, fieldmask, sph04 and expr.
82
- * There are no explicit sorting modes - all sorting must be on attributes followed by ASC or DESC. For example: <code>:order => '@weight DESC, created_at ASC'</code>.
83
- * If you specify just an attribute name as a symbol for the @:order@ option, it will be given the ascending direction by default. So, @:order => :created_at@ is equivalent to @:order => 'created_at ASC'@.
84
- * If you want to use a calculated expression for sorting, you must specify the expression as a new attribute, then use that attribute in your @:order@ option. This is done using the @:select@ option to specify extra columns available in the underlying SphinxQL (_not_ ActiveRecord/SQL) query.
85
-
86
- <pre><code>ThinkingSphinx.search(
87
- :select => '@weight * 10 + document_boost as custom_weight',
88
- :order => :custom_weight
89
- )</code></pre>
90
-
91
- * Support for latitude and longitude attributes named something other than 'lat' and 'lng' or 'latitude' and 'longitude' has been removed. May add it back in if requested, but would be surprised if it's a necessary feature.
92
- * Set INDEX_ONLY to true in your shell for the index task to re-index without regenerating the configuration file.
93
- * If you want to pass the old-style @:include@, @:joins@, @:select@ or @:order@ parameters through to the underlying ActiveRecord SQL queries for instantiating search results, they should go in a hash within the search option @:sql@:
94
-
95
- <pre><code>Article.search :sql => {:include => :user}</code></pre>
96
-
97
- * SphinxQL only supports grouping by single attributes - but these attributes may be generated on the fly within the select statement (see the @:select@ option above). A grouped search uses the @:group_by@ option, and you can pass in the attribute name as either a symbol or a string:
98
-
99
- <pre><code>Article.search :group_by => :user_id</code></pre>
5
+ h2. Upgrading
100
6
 
101
- * If you want to change the order of which result appears for each group, that can be done via the @:order_group_by@ option - which behaves just like @:order@ does:
7
+ Please refer to the release notes for any changes you need to make when upgrading:
102
8
 
103
- <pre><code>Article.search(
104
- :group_by => :user_id,
105
- :order_group_by => 'created_at DESC'
106
- )</code></pre>
9
+ * "v3.1.1":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.1
10
+ * "v3.1.0":https://github.com/pat/thinking-sphinx/releases/tag/v3.1.0
11
+ * "v3.0.6":https://github.com/pat/thinking-sphinx/releases/tag/v3.0.6
107
12
 
108
- * The @each_with_group@, @each_with_count@ and @each_with_group_and_count@ enumerators are available when using the @:group_by@ option (but are otherwise not available to search objects). Please note the spelling - older versions of Thinking Sphinx allowed for groupby and group, this is no longer the case.
109
- * @each_with_weight@ (again, note that it's weight, not weighting) is available, but not by default. Here's an example of how to have it part of the search object:
13
+ If you're upgrading from pre-v3, then the documentation has "pretty extensive notes":http://pat.github.io/thinking-sphinx/upgrading.html on what's changed.
110
14
 
111
- <pre><code>search = Article.search('pancakes', :select => '*, @weight')
112
- search.masks << ThinkingSphinx::Masks::WeightEnumeratorMask
113
-
114
- search.each_with_weight do |article, weight|
115
- # ...
116
- end</code></pre>
117
-
118
- You'll also note here that I'm specifying the internal weight attribute. This is necessary for edge Sphinx post 2.0.5.
119
-
120
- * Batched/Bulk searches are done pretty similarly as in the past - here's a code sample that'll only hit Sphinx once:
121
-
122
- <pre><code>batch = ThinkingSphinx::BatchedSearch.new
123
- batch.searches << Article.search('foo')
124
- batch.searches << Article.search(:conditions => {:name => 'bar'})
125
- batch.searches << Article.search_for_ids('baz')
126
-
127
- # When you call batch#populate, the searches are all populated with a single
128
- # Sphinx call.
129
- batch.populate
130
-
131
- batch.searches #=> [[foo results], [bar results], [baz results]]</code></pre>
132
-
133
- * To search on specific indices, use the @:indices@ option, which expects an array of index names (including the @_core@ or @_delta@ suffixes).
134
- * @:without_any@ has become @:without_all@ - and is implemented, but Sphinx doesn't yet support the required logic.
135
- * If you're creating a multi-value attribute manually (using a SQL snippet), then in the definition pass in @:multi => true@, but @:type@ should be set as well, to one of the MVA types that Sphinx supports (@:integer@, @:timestamp@, or @:boolean@).
136
- * Automatic updates of non-string attributes are still limited to those from columns on the model in question, and is disabled by default. To enable it, just set attribute_updates to true in your @config/thinking_sphinx.yml@.
137
- * Search result helper methods are no longer injected into the actual result objects. Read the section below on search results, glazes and panes.
138
- * If you're using string facets, make sure they're defined as fields, not strings. There is currently no support for multi-value string facets.
139
- * To have fine-grained control over when deltas are invoked, create a sub-class of your chosen delta class (the standard is @ThinkingSphinx::Deltas::DefaultDelta@) and customise the @toggle@ and @toggled?@ methods, both of which accept a single parameter being the ActiveRecord instance.
140
-
141
- <pre><code>class OccasionalDeltas < ThinkingSphinx::Deltas::DefaultDelta
142
- # Invoked via a before_save callback. The default behaviour is to set the
143
- # delta column to true.
144
- def toggle(instance)
145
- super unless instance.title_changed?
146
- end
147
-
148
- # Invoked via an after_commit callback. The default behaviour is to check
149
- # whether the delta column is set to true. If this method returns true, the
150
- # indexer is fired.
151
- def toggled?(instance)
152
- return false unless instance.title_changed?
153
-
154
- super
155
- end
156
- end
157
-
158
- # And in your index definition:
159
- ThinkingSphinx::Index.define :article, :with => :active_record, :delta => OccasionalDeltas do
160
- # ...
161
- end</code></pre>
162
-
163
- * Polymorphic associations used within index definitions must be declared with the corresponding models. This is much better than the old approach of querying the database on the *_type column to determine what models to join against.
164
-
165
- <pre><code>indexes events.eventable.name
166
-
167
- polymorphs events.eventable, :to => %w(Page Post User)</code></pre>
168
-
169
- h2. Search Middleware
170
-
171
- This section needs information - go hunting in the source for the moment if you're keen on adding a layer around querying/result population process.
172
-
173
- h2. Search results, Glazes and Panes
174
-
175
- In versions of Thinking Sphinx prior to v3, each search result object had many methods inserted into it - for direct access to the weight, distance, sphinx attributes and excerpts. This is no longer the case, but there is a more modular approach available.
176
-
177
- Search results may now have a glaze object placed around them, which can then delegate methods to any number of panes the glaze has available. By default, there are no panes added (and thus, no glazing), but this can be modified:
178
-
179
- <pre><code># For every search
180
- ThinkingSphinx::Configuration::Defaults::PANES << ThinkingSphinx::Panes::WeightPane
181
-
182
- # Or for specific searches:
183
- search = ThinkingSphinx.search('pancakes')
184
- search.context[:panes] << ThinkingSphinx::Panes::WeightPane</code></pre>
185
-
186
- The available panes are as follows:
187
-
188
- * @WeightPane@ (methods: @weight@)
189
- * @DistancePane@ (methods: @distance@, @geodist@)
190
- * @AttributesPane@ (methods: @sphinx_attributes@)
191
- * @ExcerptsPane@ (methods: @excerpts@)
192
-
193
- All panes namespaced to @ThinkingSphinx::Panes@, and the @DistancePane@ is automatically added when you provide latitude/longitude values via the @:geo@ option.
15
+ h2. Installation
194
16
 
195
- If you wish to add your own panes, go ahead. The only requirement is that the initializer must accept three arguments: the search context, the underlying search result object, and a hash of the raw values from Sphinx.
17
+ It's a gem, so install it like you would any other gem. You will also need to specify the mysql2 gem if you're using MRI, or jdbc-mysql if you're using JRuby:
196
18
 
197
- h2. Deployment with Capistrano
19
+ <pre><code>gem 'mysql2', '~> 0.3.13', :platform => :ruby
20
+ gem 'jdbc-mysql', '~> 5.1.28', :platform => :jruby
21
+ gem 'thinking-sphinx', '~> 3.1.1'</code></pre>
198
22
 
199
- Thinking Sphinx comes with several Capistrano tasks to help ease deployment of your applications. Just require the recipes:
23
+ The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
200
24
 
201
- <pre><code># config/deploy.rb
202
- require 'thinking_sphinx/capistrano'</code></pre>
25
+ You'll also need to install Sphinx - this is covered in "the extended documentation":http://pat.github.io/thinking-sphinx/installing_sphinx.html.
203
26
 
204
- When running @cap deploy:setup@ to get your server ready for deployments, Thinking Sphinx will also set up a shared folder for your indexes. Before finalizing a deployment, these indexes will be symlinked into the release path for use. When you deploy your application for the first time using @cap deploy:cold@, your indexes will be built for you and the search daemon will be started. Run @cap -T@ to see all of the deployment tasks.
27
+ h2. Usage
205
28
 
206
- h2. Limitations
29
+ Begin by reading the "quick-start guide":http://pat.github.io/thinking-sphinx/quickstart.html, and beyond that, "the documentation":http://pat.github.io/thinking-sphinx/ should serve you pretty well.
207
30
 
208
- Almost all functionality from v2 releases are implemented, though it's worth noting that some settings haven't yet been brought across, and a handful of the smaller features don't yet exist either. Some may actually not return... we'll see.
31
+ h3. Extending with Middleware, Glazes and Panes
209
32
 
210
- May or may not be added:
33
+ These are covered in "a blog post":http://freelancing-gods.com/posts/rewriting_thinking_sphinx_middleware_glazes_and_panes.
211
34
 
212
- * Datetime Deltas
213
- * Bitmask weighting helper
214
- * Timezone support (for databases not using UTC)
215
- * Abstract Inheritance support (maybe - not sure this is something many of people want).
216
- * Facet support for arrays of strings.
35
+ h2. Requirements
217
36
 
218
- h3. Sphinx Versions
37
+ h3. Sphinx
219
38
 
220
- TS 3 is built for Sphinx 2.0.5 or newer. You cannot use 1.10-beta, 0.9.9 or anything earlier than that.
39
+ Thinking Sphinx v3 is currently built for Sphinx 2.0.5 or newer, and releases since v3.1.0 expect Sphinx 2.1.2 or newer by default.
221
40
 
222
- h3. Rails Versions
41
+ h3. Rails and ActiveRecord
223
42
 
224
- Currently TS 3 is built to support Rails/ActiveRecord 3.1 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
43
+ Currently Thinking Sphinx 3 is built to support Rails/ActiveRecord 3.2 or newer. If you're using Sinatra and ActiveRecord instead of Rails, that's fine - just make sure you add the @:require => 'thinking_sphinx/sinatra'@ option when listing @thinking-sphinx@ in your Gemfile.
225
44
 
226
- TS 3 does not support Rails 3.0, Rails 2.x or earlier, or Merb - please refer to the TS 1.x and 2.x releases in those situations.
45
+ If you want ActiveRecord 3.1 support, then refer to the 3.0.x releases of Thinking Sphinx. Anything older than that, then you're stuck with Thinking Sphinx v2.x (for Rails/ActiveRecord 3.0) or v1.x (Rails 2.3). Please note that these older versions are no longer actively supported.
227
46
 
228
- h3. Ruby Versions
47
+ h3. Ruby
229
48
 
230
- Built on MRI 1.9.3 and tested against MRI 1.9.2 as well. No plans to support MRI 1.8, but would like to support Rubinius and JRuby (the one catch with the latter is the different MySQL interfaces).
49
+ You'll need either the standard Ruby (v1.9.3 or newer) or JRuby (1.7.9 or newer). I'm open to patches to improve Rubinius support (if required - it may work with it right now).
231
50
 
232
- There's also the complication that Sphinx 2.0.x releases don't work with JDBC (as JDBC sends several MySQL-specific commands through when initializing a connection). So, JRuby support won't appear until there's a stable Sphinx release that can interact with JDBC.
51
+ JRuby is only supported as of Thinking Sphinx v3.1.0, and requires Sphinx 2.1.2 or newer.
233
52
 
234
53
  h3. Database Versions
235
54
 
@@ -237,22 +56,23 @@ MySQL 5.x and Postgres 8.4 or better are supported.
237
56
 
238
57
  h2. Contributing
239
58
 
240
- You're brave! To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design.
59
+ To contribute, clone this repository and have a good look through the specs - you'll notice the distinction between acceptance tests that actually use Sphinx and go through the full stack, and unit tests (everything else) which use liberal test doubles to ensure they're only testing the behaviour of the class in question. I've found this leads to far better code design.
241
60
 
242
- In order to run the specs, you'll need to create a MySQL database named @thinking_sphinx@:
243
- <pre><code># Fire up a MySQL console connection:
61
+ All development is done on the @develop@ branch; please base any pull requests off of that branch. Please write the tests and then the code to get them passing, and send through a pull request.
62
+
63
+ In order to run the tests, you'll need to create a database named @thinking_sphinx@:
64
+
65
+ <pre><code># Either fire up a MySQL console:
244
66
  mysql -u root
67
+ # OR a PostgreSQL console:
68
+ psql
245
69
  # In that console, create the database:
246
70
  CREATE DATABASE thinking_sphinx;</code></pre>
247
71
 
248
- You can then run the unit tests with @rake spec:unit@, the acceptance tests with @rake spec:acceptance@, or all of the tests with just @rake@.
249
-
250
- All development is done on the @develop@ branch; please base any pull requests off of that branch.
251
-
252
- If you're still interested in helping evolve this, then write the tests and then the code to get them passing, and send through a pull request. No promises on merging anything, but we shall see!
72
+ You can then run the unit tests with @rake spec:unit@, the acceptance tests with @rake spec:acceptance@, or all of the tests with just @rake@. To run these with PostgreSQL, you'll need to set the @DATABASE@ environment variable accordingly:
253
73
 
254
- For some ideas behind my current approach, have a look through @sketchpad.rb@ in the root of this project. If you can make sense of that, you're doing very well indeed.
74
+ <pre><code>DATABASE=postgresql rake</code></pre>
255
75
 
256
76
  h2. Licence
257
77
 
258
- Copyright (c) 2007-2012, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
78
+ Copyright (c) 2007-2014, Thinking Sphinx is developed and maintained by Pat Allan, and is released under the open MIT Licence. Many thanks to "all who have contributed patches":https://github.com/pat/thinking-sphinx/contributors.
@@ -4,9 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
6
  gem "pg", "~> 0.16.0", :platform=>:ruby
7
- gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
- gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
- gem "riddle", :git=>"git://github.com/pat/riddle.git", :branch=>"develop"
7
+ gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
8
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
10
9
  gem "rails", "~> 3.2.0"
11
10
 
12
11
  gemspec :path=>"../"
@@ -4,9 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
6
  gem "pg", "~> 0.16.0", :platform=>:ruby
7
- gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
- gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
- gem "riddle", :git=>"git://github.com/pat/riddle.git", :branch=>"develop"
7
+ gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
8
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
10
9
  gem "rails", "~> 4.0.2"
11
10
 
12
11
  gemspec :path=>"../"
@@ -4,9 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "mysql2", "~> 0.3.12b4", :platform=>:ruby
6
6
  gem "pg", "~> 0.16.0", :platform=>:ruby
7
- gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
8
- gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
9
- gem "riddle", :git=>"git://github.com/pat/riddle.git", :branch=>"develop"
7
+ gem "activerecord-jdbcmysql-adapter", "~> 1.3.4", :platform=>:jruby
8
+ gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.4", :platform=>:jruby
10
9
  gem "rails", "~> 4.1.0.beta1"
11
10
 
12
11
  gemspec :path=>"../"
@@ -73,6 +73,7 @@ require 'thinking_sphinx/wildcard'
73
73
  require 'thinking_sphinx/active_record'
74
74
  require 'thinking_sphinx/deltas'
75
75
  require 'thinking_sphinx/distributed'
76
+ require 'thinking_sphinx/logger'
76
77
  require 'thinking_sphinx/real_time'
77
78
 
78
79
  require 'thinking_sphinx/railtie' if defined?(Rails)
@@ -21,6 +21,7 @@ require 'thinking_sphinx/active_record/log_subscriber'
21
21
  require 'thinking_sphinx/active_record/polymorpher'
22
22
  require 'thinking_sphinx/active_record/property_query'
23
23
  require 'thinking_sphinx/active_record/property_sql_presenter'
24
+ require 'thinking_sphinx/active_record/simple_many_query'
24
25
  require 'thinking_sphinx/active_record/sql_builder'
25
26
  require 'thinking_sphinx/active_record/sql_source'
26
27
 
@@ -30,3 +30,4 @@ module ThinkingSphinx::ActiveRecord::AssociationProxy
30
30
  end
31
31
 
32
32
  require 'thinking_sphinx/active_record/association_proxy/attribute_finder'
33
+ require 'thinking_sphinx/active_record/association_proxy/attribute_matcher'
@@ -5,17 +5,16 @@ class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
5
5
 
6
6
  def attribute
7
7
  attributes.detect { |attribute|
8
- # Don't bother with attributes built from multiple columns
9
- next if attribute.columns.many?
10
-
11
- attribute.columns.first.__name == foreign_key.to_sym ||
12
- attribute.name == foreign_key.to_s
8
+ ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeMatcher.new(
9
+ attribute, foreign_key
10
+ ).matches?
13
11
  } or raise "Missing Attribute for Foreign Key #{foreign_key}"
14
12
  end
15
13
 
16
14
  private
15
+
17
16
  def attributes
18
- sources.collect(&:attributes).flatten
17
+ indices.collect(&:attributes).flatten
19
18
  end
20
19
 
21
20
  def configuration
@@ -40,8 +39,4 @@ class ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder
40
39
  target = target.through_reflection if target.through_reflection
41
40
  target
42
41
  end
43
-
44
- def sources
45
- indices.collect(&:sources).flatten
46
- end
47
42
  end