pixeltrix-thinking-sphinx 1.1.5 → 1.2.1
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.
- data/README.textile +147 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
- data/lib/thinking_sphinx/active_record/delta.rb +14 -1
- data/lib/thinking_sphinx/active_record/scopes.rb +37 -0
- data/lib/thinking_sphinx/active_record.rb +46 -12
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +9 -1
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +3 -2
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +12 -5
- data/lib/thinking_sphinx/association.rb +20 -0
- data/lib/thinking_sphinx/attribute.rb +187 -116
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +46 -14
- data/lib/thinking_sphinx/core/string.rb +3 -10
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +3 -3
- data/lib/thinking_sphinx/deltas/default_delta.rb +9 -6
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +1 -1
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +4 -2
- data/lib/thinking_sphinx/deltas.rb +14 -6
- data/lib/thinking_sphinx/deploy/capistrano.rb +98 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet.rb +68 -18
- data/lib/thinking_sphinx/facet_search.rb +134 -0
- data/lib/thinking_sphinx/field.rb +7 -97
- data/lib/thinking_sphinx/index/builder.rb +255 -201
- data/lib/thinking_sphinx/index.rb +28 -343
- data/lib/thinking_sphinx/property.rb +160 -0
- data/lib/thinking_sphinx/rails_additions.rb +7 -4
- data/lib/thinking_sphinx/search.rb +593 -587
- data/lib/thinking_sphinx/search_methods.rb +421 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +128 -0
- data/lib/thinking_sphinx/source.rb +150 -0
- data/lib/thinking_sphinx/tasks.rb +45 -11
- data/lib/thinking_sphinx.rb +88 -14
- data/rails/init.rb +14 -0
- data/spec/{unit → lib}/thinking_sphinx/active_record/delta_spec.rb +7 -7
- data/spec/{unit → lib}/thinking_sphinx/active_record/has_many_association_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +92 -0
- data/spec/{unit → lib}/thinking_sphinx/active_record_spec.rb +115 -42
- data/spec/{unit → lib}/thinking_sphinx/association_spec.rb +4 -5
- data/spec/lib/thinking_sphinx/attribute_spec.rb +465 -0
- data/spec/{unit → lib}/thinking_sphinx/configuration_spec.rb +118 -7
- data/spec/{unit → lib}/thinking_sphinx/core/string_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/excerpter_spec.rb +49 -0
- data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/lib/thinking_sphinx/facet_spec.rb +302 -0
- data/spec/{unit → lib}/thinking_sphinx/field_spec.rb +26 -17
- data/spec/lib/thinking_sphinx/index/builder_spec.rb +355 -0
- data/spec/{unit → lib}/thinking_sphinx/index/faux_column_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/index_spec.rb +3 -12
- data/spec/lib/thinking_sphinx/rails_additions_spec.rb +191 -0
- data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/lib/thinking_sphinx/search_spec.rb +887 -0
- data/spec/lib/thinking_sphinx/source_spec.rb +217 -0
- data/spec/{unit → lib}/thinking_sphinx_spec.rb +30 -8
- data/tasks/distribution.rb +20 -1
- data/tasks/testing.rb +7 -15
- data/vendor/after_commit/init.rb +3 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +27 -4
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +1 -1
- data/vendor/after_commit/lib/after_commit.rb +4 -1
- data/vendor/riddle/lib/riddle/client/message.rb +4 -3
- data/vendor/riddle/lib/riddle/client.rb +3 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +8 -2
- data/vendor/riddle/lib/riddle/controller.rb +1 -1
- data/vendor/riddle/lib/riddle.rb +1 -1
- metadata +75 -39
- data/README +0 -107
- data/lib/thinking_sphinx/active_record/search.rb +0 -57
- data/lib/thinking_sphinx/collection.rb +0 -142
- data/lib/thinking_sphinx/facet_collection.rb +0 -44
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +0 -107
- data/spec/unit/thinking_sphinx/attribute_spec.rb +0 -212
- data/spec/unit/thinking_sphinx/collection_spec.rb +0 -14
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +0 -5
- data/spec/unit/thinking_sphinx/search_spec.rb +0 -59
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixeltrix-thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
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: 2009-
|
12
|
+
date: 2009-07-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,16 +22,18 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
+
- rails/init.rb
|
26
|
+
- lib/thinking_sphinx/active_record/attribute_updates.rb
|
25
27
|
- lib/thinking_sphinx/active_record/delta.rb
|
26
28
|
- lib/thinking_sphinx/active_record/has_many_association.rb
|
27
|
-
- lib/thinking_sphinx/active_record/
|
29
|
+
- lib/thinking_sphinx/active_record/scopes.rb
|
28
30
|
- lib/thinking_sphinx/active_record.rb
|
29
31
|
- lib/thinking_sphinx/adapters/abstract_adapter.rb
|
30
32
|
- lib/thinking_sphinx/adapters/mysql_adapter.rb
|
31
33
|
- lib/thinking_sphinx/adapters/postgresql_adapter.rb
|
32
34
|
- lib/thinking_sphinx/association.rb
|
33
35
|
- lib/thinking_sphinx/attribute.rb
|
34
|
-
- lib/thinking_sphinx/
|
36
|
+
- lib/thinking_sphinx/class_facet.rb
|
35
37
|
- lib/thinking_sphinx/configuration.rb
|
36
38
|
- lib/thinking_sphinx/core/string.rb
|
37
39
|
- lib/thinking_sphinx/deltas/datetime_delta.rb
|
@@ -41,21 +43,28 @@ files:
|
|
41
43
|
- lib/thinking_sphinx/deltas/delayed_delta/job.rb
|
42
44
|
- lib/thinking_sphinx/deltas/delayed_delta.rb
|
43
45
|
- lib/thinking_sphinx/deltas.rb
|
46
|
+
- lib/thinking_sphinx/deploy/capistrano.rb
|
47
|
+
- lib/thinking_sphinx/excerpter.rb
|
44
48
|
- lib/thinking_sphinx/facet.rb
|
45
|
-
- lib/thinking_sphinx/
|
49
|
+
- lib/thinking_sphinx/facet_search.rb
|
46
50
|
- lib/thinking_sphinx/field.rb
|
47
51
|
- lib/thinking_sphinx/index/builder.rb
|
48
52
|
- lib/thinking_sphinx/index/faux_column.rb
|
49
53
|
- lib/thinking_sphinx/index.rb
|
54
|
+
- lib/thinking_sphinx/property.rb
|
50
55
|
- lib/thinking_sphinx/rails_additions.rb
|
51
56
|
- lib/thinking_sphinx/search.rb
|
57
|
+
- lib/thinking_sphinx/search_methods.rb
|
58
|
+
- lib/thinking_sphinx/source/internal_properties.rb
|
59
|
+
- lib/thinking_sphinx/source/sql.rb
|
60
|
+
- lib/thinking_sphinx/source.rb
|
52
61
|
- lib/thinking_sphinx/tasks.rb
|
53
62
|
- lib/thinking_sphinx.rb
|
54
63
|
- LICENCE
|
55
|
-
- README
|
64
|
+
- README.textile
|
56
65
|
- tasks/distribution.rb
|
57
|
-
- tasks/rails.rake
|
58
66
|
- tasks/testing.rb
|
67
|
+
- tasks/rails.rake
|
59
68
|
- vendor/after_commit
|
60
69
|
- vendor/after_commit/init.rb
|
61
70
|
- vendor/after_commit/lib
|
@@ -96,24 +105,46 @@ files:
|
|
96
105
|
- vendor/riddle/lib/riddle/configuration.rb
|
97
106
|
- vendor/riddle/lib/riddle/controller.rb
|
98
107
|
- vendor/riddle/lib/riddle.rb
|
99
|
-
- spec/
|
100
|
-
- spec/
|
101
|
-
- spec/
|
102
|
-
- spec/
|
103
|
-
- spec/
|
104
|
-
- spec/
|
105
|
-
- spec/
|
106
|
-
- spec/
|
107
|
-
- spec/
|
108
|
-
- spec/
|
109
|
-
- spec/
|
110
|
-
- spec/
|
111
|
-
- spec/
|
112
|
-
- spec/
|
113
|
-
- spec/
|
108
|
+
- spec/lib/thinking_sphinx/active_record/delta_spec.rb
|
109
|
+
- spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
|
110
|
+
- spec/lib/thinking_sphinx/active_record/scopes_spec.rb
|
111
|
+
- spec/lib/thinking_sphinx/active_record_spec.rb
|
112
|
+
- spec/lib/thinking_sphinx/association_spec.rb
|
113
|
+
- spec/lib/thinking_sphinx/attribute_spec.rb
|
114
|
+
- spec/lib/thinking_sphinx/configuration_spec.rb
|
115
|
+
- spec/lib/thinking_sphinx/core/string_spec.rb
|
116
|
+
- spec/lib/thinking_sphinx/excerpter_spec.rb
|
117
|
+
- spec/lib/thinking_sphinx/facet_search_spec.rb
|
118
|
+
- spec/lib/thinking_sphinx/facet_spec.rb
|
119
|
+
- spec/lib/thinking_sphinx/field_spec.rb
|
120
|
+
- spec/lib/thinking_sphinx/index/builder_spec.rb
|
121
|
+
- spec/lib/thinking_sphinx/index/faux_column_spec.rb
|
122
|
+
- spec/lib/thinking_sphinx/index_spec.rb
|
123
|
+
- spec/lib/thinking_sphinx/rails_additions_spec.rb
|
124
|
+
- spec/lib/thinking_sphinx/search_methods_spec.rb
|
125
|
+
- spec/lib/thinking_sphinx/search_spec.rb
|
126
|
+
- spec/lib/thinking_sphinx/source_spec.rb
|
127
|
+
- spec/lib/thinking_sphinx_spec.rb
|
114
128
|
has_rdoc: true
|
115
129
|
homepage: http://ts.freelancing-gods.com
|
116
|
-
|
130
|
+
licenses:
|
131
|
+
post_install_message: |+
|
132
|
+
With the release of Thinking Sphinx 1.1.18, there is one important change to
|
133
|
+
note: previously, the default morphology for indexing was 'stem_en'. The new
|
134
|
+
default is nil, to avoid any unexpected behavior. If you wish to keep the old
|
135
|
+
value though, you will need to add the following settings to your
|
136
|
+
config/sphinx.yml file:
|
137
|
+
|
138
|
+
development:
|
139
|
+
morphology: stem_en
|
140
|
+
test:
|
141
|
+
morphology: stem_en
|
142
|
+
production:
|
143
|
+
morphology: stem_en
|
144
|
+
|
145
|
+
To understand morphologies/stemmers better, visit the following link:
|
146
|
+
http://www.sphinxsearch.com/docs/manual-0.9.8.html#conf-morphology
|
147
|
+
|
117
148
|
rdoc_options:
|
118
149
|
- --title
|
119
150
|
- Thinking Sphinx -- Rails/Merb Sphinx Plugin
|
@@ -135,23 +166,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
166
|
requirements: []
|
136
167
|
|
137
168
|
rubyforge_project: thinking-sphinx
|
138
|
-
rubygems_version: 1.
|
169
|
+
rubygems_version: 1.3.5
|
139
170
|
signing_key:
|
140
171
|
specification_version: 2
|
141
172
|
summary: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.
|
142
173
|
test_files:
|
143
|
-
- spec/
|
144
|
-
- spec/
|
145
|
-
- spec/
|
146
|
-
- spec/
|
147
|
-
- spec/
|
148
|
-
- spec/
|
149
|
-
- spec/
|
150
|
-
- spec/
|
151
|
-
- spec/
|
152
|
-
- spec/
|
153
|
-
- spec/
|
154
|
-
- spec/
|
155
|
-
- spec/
|
156
|
-
- spec/
|
157
|
-
- spec/
|
174
|
+
- spec/lib/thinking_sphinx/active_record/delta_spec.rb
|
175
|
+
- spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb
|
176
|
+
- spec/lib/thinking_sphinx/active_record/scopes_spec.rb
|
177
|
+
- spec/lib/thinking_sphinx/active_record_spec.rb
|
178
|
+
- spec/lib/thinking_sphinx/association_spec.rb
|
179
|
+
- spec/lib/thinking_sphinx/attribute_spec.rb
|
180
|
+
- spec/lib/thinking_sphinx/configuration_spec.rb
|
181
|
+
- spec/lib/thinking_sphinx/core/string_spec.rb
|
182
|
+
- spec/lib/thinking_sphinx/excerpter_spec.rb
|
183
|
+
- spec/lib/thinking_sphinx/facet_search_spec.rb
|
184
|
+
- spec/lib/thinking_sphinx/facet_spec.rb
|
185
|
+
- spec/lib/thinking_sphinx/field_spec.rb
|
186
|
+
- spec/lib/thinking_sphinx/index/builder_spec.rb
|
187
|
+
- spec/lib/thinking_sphinx/index/faux_column_spec.rb
|
188
|
+
- spec/lib/thinking_sphinx/index_spec.rb
|
189
|
+
- spec/lib/thinking_sphinx/rails_additions_spec.rb
|
190
|
+
- spec/lib/thinking_sphinx/search_methods_spec.rb
|
191
|
+
- spec/lib/thinking_sphinx/search_spec.rb
|
192
|
+
- spec/lib/thinking_sphinx/source_spec.rb
|
193
|
+
- spec/lib/thinking_sphinx_spec.rb
|
data/README
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
= Thinking Sphinx
|
2
|
-
|
3
|
-
== Usage
|
4
|
-
|
5
|
-
First, if you haven't done so already, check out the main usage[http://ts.freelancing-gods.com/usage.html] page. Once you've done that, the next place to look for information is the specific method docs - ThinkingSphinx::Search and ThinkingSphinx::Index::Builder in particular.
|
6
|
-
|
7
|
-
Keep in mind that while Thinking Sphinx works for ActiveRecord with Merb, it doesn't yet support DataMapper (although that is planned).
|
8
|
-
|
9
|
-
== Contributing
|
10
|
-
|
11
|
-
Fork on GitHub and after you've committed tested patches, send a pull request.
|
12
|
-
|
13
|
-
To get the spec suite running, you will need to install the not-a-mock gem if you don't already have it:
|
14
|
-
|
15
|
-
git clone git://github.com/freelancing-god/not-a-mock.git
|
16
|
-
cd not-a-mock
|
17
|
-
rake gem
|
18
|
-
gem install pkg/not_a_mock-1.1.0.gem
|
19
|
-
|
20
|
-
Then install the ginger gem. The steps are the same, except that you might need to sudo the gem install:
|
21
|
-
|
22
|
-
git clone git://github.com/freelancing-god/ginger.git
|
23
|
-
cd ginger
|
24
|
-
rake gem
|
25
|
-
sudo gem install pkg/ginger-1.1.0.gem
|
26
|
-
|
27
|
-
Then set up your database:
|
28
|
-
|
29
|
-
cp spec/fixtures/database.yml.default spec/fixtures/database.yml
|
30
|
-
mysqladmin -u root create thinking_sphinx
|
31
|
-
|
32
|
-
Make sure you don't have another Sphinx daemon (searchd) running. If you do, quit it with "rake ts:stop"
|
33
|
-
in the app root.
|
34
|
-
|
35
|
-
You should now have a passing test suite from which to build your patch on.
|
36
|
-
|
37
|
-
rake spec
|
38
|
-
|
39
|
-
If you get the message "Failed to start searchd daemon", run the spec with sudo:
|
40
|
-
|
41
|
-
sudo rake spec
|
42
|
-
|
43
|
-
If you quit the spec suite before it's completed, you may be left with data in the test
|
44
|
-
database, causing the next run to have failures. Let that run complete and then try again.
|
45
|
-
|
46
|
-
== Contributors
|
47
|
-
|
48
|
-
Since I first released this library, there's been quite a few people who have submitted patches, to my immense gratitude. Others have suggested syntax changes and general improvements. So my thanks to the following people:
|
49
|
-
|
50
|
-
- Joost Hietbrink
|
51
|
-
- Jonathan Conway
|
52
|
-
- Gregory Mirzayantz
|
53
|
-
- Tung Nguyen
|
54
|
-
- Sean Cribbs
|
55
|
-
- Benoit Caccinolo
|
56
|
-
- John Barton
|
57
|
-
- Oliver Beddows
|
58
|
-
- Arthur Zapparoli
|
59
|
-
- Dusty Doris
|
60
|
-
- Marcus Crafter
|
61
|
-
- Patrick Lenz
|
62
|
-
- Björn Andreasson
|
63
|
-
- James Healy
|
64
|
-
- Jae-Jun Hwang
|
65
|
-
- Xavier Shay
|
66
|
-
- Jason Rust
|
67
|
-
- Gopal Patel
|
68
|
-
- Chris Heald
|
69
|
-
- Peter Vandenberk
|
70
|
-
- Josh French
|
71
|
-
- Andrew Bennett
|
72
|
-
- Jordan Fowler
|
73
|
-
- Seth Walker
|
74
|
-
- Joe Noon
|
75
|
-
- Wolfgang Postler
|
76
|
-
- Rick Olson
|
77
|
-
- Killian Murphy
|
78
|
-
- Morten Primdahl
|
79
|
-
- Ryan Bates
|
80
|
-
- David Eisinger
|
81
|
-
- Shay Arnett
|
82
|
-
- Minh Tran
|
83
|
-
- Jeremy Durham
|
84
|
-
- Piotr Sarnacki
|
85
|
-
- Matt Johnson
|
86
|
-
- Nicolas Blanco
|
87
|
-
- Max Lapshin
|
88
|
-
- Josh Natanson
|
89
|
-
- Philip Hallstrom
|
90
|
-
- Christian Rishøj
|
91
|
-
- Mike Flester
|
92
|
-
- Jim Remsik
|
93
|
-
- Kennon Ballou
|
94
|
-
- Henrik Nyh
|
95
|
-
- Emil Tin
|
96
|
-
- Doug Cole
|
97
|
-
- Ed Hickey
|
98
|
-
- Evan Weaver
|
99
|
-
- Thibaut Barrere
|
100
|
-
- Kristopher Chambers
|
101
|
-
- Dmitrij Smalko
|
102
|
-
- Aleksey Yeschenko
|
103
|
-
- Lachie Cox
|
104
|
-
- Lourens Naude
|
105
|
-
- Tom Davies
|
106
|
-
- Dan Pickett
|
107
|
-
- Alex Caudill
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module ThinkingSphinx
|
2
|
-
module ActiveRecord
|
3
|
-
# This module covers the specific model searches - but the syntax is
|
4
|
-
# exactly the same as the core Search class - so use that as your refence
|
5
|
-
# point.
|
6
|
-
#
|
7
|
-
module Search
|
8
|
-
def self.included(base)
|
9
|
-
base.class_eval do
|
10
|
-
class << self
|
11
|
-
# Searches for results that match the parameters provided. Will only
|
12
|
-
# return the ids for the matching objects. See
|
13
|
-
# ThinkingSphinx::Search#search for syntax examples.
|
14
|
-
#
|
15
|
-
def search_for_ids(*args)
|
16
|
-
options = args.extract_options!
|
17
|
-
options[:class] = self
|
18
|
-
args << options
|
19
|
-
ThinkingSphinx::Search.search_for_ids(*args)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Searches for results limited to a single model. See
|
23
|
-
# ThinkingSphinx::Search#search for syntax examples.
|
24
|
-
#
|
25
|
-
def search(*args)
|
26
|
-
options = args.extract_options!
|
27
|
-
options[:class] = self
|
28
|
-
args << options
|
29
|
-
ThinkingSphinx::Search.search(*args)
|
30
|
-
end
|
31
|
-
|
32
|
-
def search_count(*args)
|
33
|
-
options = args.extract_options!
|
34
|
-
options[:class] = self
|
35
|
-
args << options
|
36
|
-
ThinkingSphinx::Search.count(*args)
|
37
|
-
end
|
38
|
-
|
39
|
-
def search_for_id(*args)
|
40
|
-
options = args.extract_options!
|
41
|
-
options[:class] = self
|
42
|
-
args << options
|
43
|
-
ThinkingSphinx::Search.search_for_id(*args)
|
44
|
-
end
|
45
|
-
|
46
|
-
def facets(*args)
|
47
|
-
options = args.extract_options!
|
48
|
-
options[:class] = self
|
49
|
-
args << options
|
50
|
-
ThinkingSphinx::Search.facets(*args)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,142 +0,0 @@
|
|
1
|
-
module ThinkingSphinx
|
2
|
-
class Collection < ::Array
|
3
|
-
attr_reader :total_entries, :total_pages, :current_page, :per_page
|
4
|
-
attr_accessor :results
|
5
|
-
|
6
|
-
# Compatibility with older versions of will_paginate
|
7
|
-
alias_method :page_count, :total_pages
|
8
|
-
|
9
|
-
def initialize(page, per_page, entries, total_entries)
|
10
|
-
@current_page, @per_page, @total_entries = page, per_page, total_entries
|
11
|
-
|
12
|
-
@total_pages = (entries / @per_page.to_f).ceil
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.ids_from_results(results, page, limit, options)
|
16
|
-
collection = self.new(page, limit,
|
17
|
-
results[:total] || 0, results[:total_found] || 0
|
18
|
-
)
|
19
|
-
collection.results = results
|
20
|
-
collection.replace results[:matches].collect { |match|
|
21
|
-
match[:attributes]["sphinx_internal_id"]
|
22
|
-
}
|
23
|
-
return collection
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.create_from_results(results, page, limit, options)
|
27
|
-
collection = self.new(page, limit,
|
28
|
-
results[:total] || 0, results[:total_found] || 0
|
29
|
-
)
|
30
|
-
collection.results = results
|
31
|
-
collection.replace instances_from_matches(results[:matches], options)
|
32
|
-
return collection
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.instances_from_matches(matches, options = {})
|
36
|
-
if klass = options[:class]
|
37
|
-
instances_from_class klass, matches, options
|
38
|
-
else
|
39
|
-
instances_from_classes matches, options
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.instances_from_class(klass, matches, options = {})
|
44
|
-
index_options = klass.sphinx_index_options
|
45
|
-
|
46
|
-
ids = matches.collect { |match| match[:attributes]["sphinx_internal_id"] }
|
47
|
-
instances = ids.length > 0 ? klass.find(
|
48
|
-
:all,
|
49
|
-
:conditions => {klass.primary_key.to_sym => ids},
|
50
|
-
:include => (options[:include] || index_options[:include]),
|
51
|
-
:select => (options[:select] || index_options[:select])
|
52
|
-
) : []
|
53
|
-
|
54
|
-
# Raise an exception if we find records in Sphinx but not in the DB, so
|
55
|
-
# the search method can retry without them. See
|
56
|
-
# ThinkingSphinx::Search.retry_search_on_stale_index.
|
57
|
-
if options[:raise_on_stale] && instances.length < ids.length
|
58
|
-
stale_ids = ids - instances.map {|i| i.id }
|
59
|
-
raise StaleIdsException, stale_ids
|
60
|
-
end
|
61
|
-
|
62
|
-
ids.collect { |obj_id|
|
63
|
-
instances.detect { |obj| obj.id == obj_id }
|
64
|
-
}
|
65
|
-
end
|
66
|
-
|
67
|
-
# Group results by class and call #find(:all) once for each group to reduce
|
68
|
-
# the number of #find's in multi-model searches.
|
69
|
-
#
|
70
|
-
def self.instances_from_classes(matches, options = {})
|
71
|
-
groups = matches.group_by { |match| match[:attributes]["class_crc"] }
|
72
|
-
groups.each do |crc, group|
|
73
|
-
group.replace(
|
74
|
-
instances_from_class(class_from_crc(crc), group, options)
|
75
|
-
)
|
76
|
-
end
|
77
|
-
|
78
|
-
matches.collect do |match|
|
79
|
-
groups.detect { |crc, group|
|
80
|
-
crc == match[:attributes]["class_crc"]
|
81
|
-
}[1].detect { |obj|
|
82
|
-
obj.id == match[:attributes]["sphinx_internal_id"]
|
83
|
-
}
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.class_from_crc(crc)
|
88
|
-
@@models_by_crc ||= ThinkingSphinx.indexed_models.inject({}) do |hash, model|
|
89
|
-
hash[model.constantize.to_crc32] = model
|
90
|
-
model.constantize.subclasses.each { |subclass|
|
91
|
-
hash[subclass.to_crc32] = subclass.name
|
92
|
-
}
|
93
|
-
hash
|
94
|
-
end
|
95
|
-
@@models_by_crc[crc].constantize
|
96
|
-
end
|
97
|
-
|
98
|
-
def previous_page
|
99
|
-
current_page > 1 ? (current_page - 1) : nil
|
100
|
-
end
|
101
|
-
|
102
|
-
def next_page
|
103
|
-
current_page < total_pages ? (current_page + 1): nil
|
104
|
-
end
|
105
|
-
|
106
|
-
def offset
|
107
|
-
(current_page - 1) * @per_page
|
108
|
-
end
|
109
|
-
|
110
|
-
def method_missing(method, *args, &block)
|
111
|
-
super unless method.to_s[/^each_with_.*/]
|
112
|
-
|
113
|
-
each_with_attribute method.to_s.gsub(/^each_with_/, ''), &block
|
114
|
-
end
|
115
|
-
|
116
|
-
def each_with_groupby_and_count(&block)
|
117
|
-
results[:matches].each_with_index do |match, index|
|
118
|
-
yield self[index], match[:attributes]["@groupby"], match[:attributes]["@count"]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def each_with_attribute(attribute, &block)
|
123
|
-
results[:matches].each_with_index do |match, index|
|
124
|
-
yield self[index], (match[:attributes][attribute] || match[:attributes]["@#{attribute}"])
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def each_with_weighting(&block)
|
129
|
-
results[:matches].each_with_index do |match, index|
|
130
|
-
yield self[index], match[:weight]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def inject_with_groupby_and_count(initial = nil, &block)
|
135
|
-
index = -1
|
136
|
-
results[:matches].inject(initial) do |memo, match|
|
137
|
-
index += 1
|
138
|
-
yield memo, self[index], match[:attributes]["@groupby"], match[:attributes]["@count"]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module ThinkingSphinx
|
2
|
-
class FacetCollection < Hash
|
3
|
-
attr_accessor :arguments
|
4
|
-
|
5
|
-
def initialize(arguments)
|
6
|
-
@arguments = arguments.clone
|
7
|
-
@attribute_values = {}
|
8
|
-
@facets = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def add_from_results(facet, results)
|
12
|
-
self[facet.name] = {}
|
13
|
-
@attribute_values[facet.name] = {}
|
14
|
-
@facets << facet
|
15
|
-
|
16
|
-
results.each_with_groupby_and_count { |result, group, count|
|
17
|
-
facet_value = facet.value(result, group)
|
18
|
-
|
19
|
-
self[facet.name][facet_value] = count
|
20
|
-
@attribute_values[facet.name][facet_value] = group
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
def for(hash = {})
|
25
|
-
arguments = @arguments.clone
|
26
|
-
options = arguments.extract_options!
|
27
|
-
options[:with] ||= {}
|
28
|
-
|
29
|
-
hash.each do |key, value|
|
30
|
-
attrib = facet_for_key(key).attribute_name
|
31
|
-
options[:with][attrib] = @attribute_values[key][value]
|
32
|
-
end
|
33
|
-
|
34
|
-
arguments << options
|
35
|
-
ThinkingSphinx::Search.search *arguments
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def facet_for_key(key)
|
41
|
-
@facets.detect { |facet| facet.name == key }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
require 'spec/spec_helper'
|
2
|
-
|
3
|
-
describe "ThinkingSphinx::ActiveRecord::Search" do
|
4
|
-
it "should add search_for_ids to ActiveRecord::Base" do
|
5
|
-
ActiveRecord::Base.methods.should include("search_for_ids")
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should add search_for_ids to ActiveRecord::Base" do
|
9
|
-
ActiveRecord::Base.methods.should include("search")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should add search_count to ActiveRecord::Base" do
|
13
|
-
ActiveRecord::Base.methods.should include("search_count")
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should add search_for_id to ActiveRecord::Base" do
|
17
|
-
ActiveRecord::Base.methods.should include("search_for_id")
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "search_for_ids method" do
|
21
|
-
before :each do
|
22
|
-
ThinkingSphinx::Search.stub_method(:search_for_ids => true)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should call ThinkingSphinx::Search#search_for_ids with the class option set" do
|
26
|
-
Person.search_for_ids("search")
|
27
|
-
|
28
|
-
ThinkingSphinx::Search.should have_received(:search_for_ids).with(
|
29
|
-
"search", :class => Person
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should override the class option" do
|
34
|
-
Person.search_for_ids("search", :class => Friendship)
|
35
|
-
|
36
|
-
ThinkingSphinx::Search.should have_received(:search_for_ids).with(
|
37
|
-
"search", :class => Person
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "search method" do
|
43
|
-
before :each do
|
44
|
-
ThinkingSphinx::Search.stub_method(:search => true)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should call ThinkingSphinx::Search#search with the class option set" do
|
48
|
-
Person.search("search")
|
49
|
-
|
50
|
-
ThinkingSphinx::Search.should have_received(:search).with(
|
51
|
-
"search", :class => Person
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should override the class option" do
|
56
|
-
Person.search("search", :class => Friendship)
|
57
|
-
|
58
|
-
ThinkingSphinx::Search.should have_received(:search).with(
|
59
|
-
"search", :class => Person
|
60
|
-
)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "search_for_id method" do
|
65
|
-
before :each do
|
66
|
-
ThinkingSphinx::Search.stub_method(:search_for_id => true)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should call ThinkingSphinx::Search#search with the class option set" do
|
70
|
-
Person.search_for_id(10)
|
71
|
-
|
72
|
-
ThinkingSphinx::Search.should have_received(:search_for_id).with(
|
73
|
-
10, :class => Person
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should override the class option" do
|
78
|
-
Person.search_for_id(10, :class => Friendship)
|
79
|
-
|
80
|
-
ThinkingSphinx::Search.should have_received(:search_for_id).with(
|
81
|
-
10, :class => Person
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "search_count method" do
|
87
|
-
before :each do
|
88
|
-
ThinkingSphinx::Search.stub_method(:count => true)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should call ThinkingSphinx::Search#search with the class option set" do
|
92
|
-
Person.search_count("search")
|
93
|
-
|
94
|
-
ThinkingSphinx::Search.should have_received(:count).with(
|
95
|
-
"search", :class => Person
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should override the class option" do
|
100
|
-
Person.search_count("search", :class => Friendship)
|
101
|
-
|
102
|
-
ThinkingSphinx::Search.should have_received(:count).with(
|
103
|
-
"search", :class => Person
|
104
|
-
)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|