sphinx_for_dm 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sphinx_for_dm.rb +5 -5
- metadata +2 -2
data/lib/sphinx_for_dm.rb
CHANGED
@@ -3,7 +3,7 @@ require "sphinx"
|
|
3
3
|
module SphinxForDataMapper
|
4
4
|
module ClassMethods
|
5
5
|
def acts_as_sphinx(options = {})
|
6
|
-
default_options = {:host => 'localhost', :port => 3312, :index =>
|
6
|
+
default_options = {:host => 'localhost', :port => 3312, :index => Inflector.tableize(name)}
|
7
7
|
write_inheritable_attribute 'sphinx_options', default_options.merge(options)
|
8
8
|
extend SphinxClassMethods
|
9
9
|
end
|
@@ -26,7 +26,7 @@ module SphinxForDataMapper
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def ask_sphinx(query, options = {})
|
29
|
-
default_options = {:offset => 0, :limit =>
|
29
|
+
default_options = {:offset => 0, :limit => 1000}
|
30
30
|
default_options.merge! sphinx_options
|
31
31
|
options = default_options.merge! options
|
32
32
|
|
@@ -72,9 +72,9 @@ module SphinxForDataMapper
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def all_with_sphinx(query, options = {})
|
75
|
-
result = ask_sphinx(query, options
|
76
|
-
records = result[:matches].empty? ? [] : all(({ :id.in => result[:matches].keys }).merge(options))
|
77
|
-
records = records.sort_by{|r| -result[:matches][r.id][:weight] }
|
75
|
+
result = ask_sphinx(query, options)
|
76
|
+
records = result[:matches].empty? ? [] : all(({ :id.in => result[:matches].keys }).merge(options).merge({:offset => 0}))
|
77
|
+
records = records.sort_by{|r| - result[:matches][r.id][:weight] }
|
78
78
|
%w[total total_found time].map(&:to_sym).each do |method|
|
79
79
|
class << records; self end.send(:define_method, method) {result[method]}
|
80
80
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sphinx_for_dm
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2008-02-
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2008-02-27 00:00:00 -05:00
|
8
8
|
summary: Acts_as_sphinx for DataMapper
|
9
9
|
require_paths:
|
10
10
|
- lib
|