dnif 0.0.1.beta.6 → 0.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.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ end
10
10
  require "jeweler"
11
11
 
12
12
  $LOAD_PATH.unshift('lib')
13
- require "dnif"
13
+ require "dnif/version"
14
14
 
15
15
  Jeweler::Tasks.new do |gemspec|
16
16
  gemspec.name = "dnif"
@@ -26,11 +26,5 @@ end
26
26
 
27
27
  Jeweler::GemcutterTasks.new
28
28
 
29
- desc "Generate gemspec and build gem"
30
- task :build_gem do
31
- Rake::Task["gemspec"].invoke
32
- Rake::Task["build"].invoke
33
- end
34
-
35
29
  require "rspec/core/rake_task"
36
30
  RSpec::Core::RakeTask.new(:spec)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dnif}
8
- s.version = "0.0.1.beta.6"
8
+ s.version = "0.1.0"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rafael Souza"]
12
- s.date = %q{2010-09-08}
12
+ s.date = %q{2010-10-21}
13
13
  s.description = %q{dnif is a gem to index data using ActiveRecord finders, letting you index your custom methods and not only your table fields}
14
14
  s.email = %q{me@rafaelss.com}
15
15
  s.extra_rdoc_files = [
@@ -14,7 +14,6 @@ module Dnif
14
14
  autoload :Indexer, "dnif/indexer"
15
15
  autoload :MultiAttribute, "dnif/multi_attribute"
16
16
  autoload :Search, "dnif/search"
17
- autoload :Version, "dnif/version"
18
17
 
19
18
  def root_path
20
19
  @root_path
@@ -66,17 +65,18 @@ module Dnif
66
65
  results = client.query(query, options[:index])
67
66
  raise results[:error] if results[:error]
68
67
 
69
- models = results[:matches].inject({}) do |memo, match|
68
+ models = {}
69
+ results[:matches].each do |match|
70
70
  encoded_class_name = match[:attributes]["class_name"].split(',').flatten
71
71
  class_name = Dnif::MultiAttribute.decode(encoded_class_name)
72
72
 
73
- memo[class_name] ||= []
74
- memo[class_name] << (match[:doc] - encoded_class_name.sum { |c| c.to_i })
75
- memo
73
+ models[class_name] ||= []
74
+ models[class_name] << (match[:doc] - encoded_class_name.sum { |c| c.to_i })
76
75
  end
77
76
 
78
77
  models.map do |class_name, ids|
79
- class_name.constantize.find_all_by_id(ids)
78
+ klass = class_name.constantize
79
+ class_name.constantize.where("#{klass.primary_key} IN (?)", ids)
80
80
  end.flatten
81
81
  end
82
82
 
@@ -53,7 +53,7 @@ module Dnif
53
53
  end
54
54
 
55
55
  def document_id
56
- @object.id + encoded_class_name.split(',').sum { |c| c.to_i }
56
+ @object.send(@object.class.primary_key.to_sym) + encoded_class_name.split(',').sum { |c| c.to_i }
57
57
  end
58
58
 
59
59
  private
@@ -22,8 +22,8 @@ module Dnif
22
22
  @attributes[name] = options[:type]
23
23
  end
24
24
 
25
- def where(conditions)
25
+ def where(*conditions)
26
26
  @conditions = conditions
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -22,8 +22,9 @@ module Dnif
22
22
  schema = Schema.new(self)
23
23
  xml << schema.generate
24
24
 
25
- results = all(:conditions => indexes[self.name].conditions)
26
- results.each do |object|
25
+ results = self
26
+ results = where(*indexes[self.name].conditions) if indexes[self.name].conditions.present?
27
+ results.find_each(:batch_size => 5000) do |object|
27
28
  document = Document.new(object)
28
29
  xml << document.generate
29
30
  end
@@ -64,7 +64,10 @@ namespace :dnif do
64
64
 
65
65
  desc "Stop sphinx daemon"
66
66
  task :stop => :environment do
67
- controller.stop
67
+ while controller.running?
68
+ controller.stop
69
+ sleep(1)
70
+ end
68
71
  puts "\n>> daemon stopped" # TODO show this only whether daemon is really stopped
69
72
  end
70
73
 
@@ -1,9 +1,9 @@
1
1
  module Dnif
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 0
5
- PATCH = 1
6
- BUILD = "beta.6"
4
+ MINOR = 1
5
+ PATCH = 0
6
+ BUILD = nil # "beta.6"
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
9
  end
@@ -72,8 +72,9 @@ describe Dnif do
72
72
  riddle = mock("Riddle")
73
73
  riddle.should_receive(:query).with("my search", "*").and_return(results)
74
74
  Dnif.should_receive(:client).and_return(riddle)
75
- Post.should_receive(:find_all_by_id).once.with([1])
76
- Comment.should_receive(:find_all_by_id).once.with([2])
75
+
76
+ Post.should_receive(:where).with("id IN (?)", [1]).and_return([])
77
+ Comment.should_receive(:where).with("id IN (?)", [2]).and_return([])
77
78
 
78
79
  Dnif.search("my search")
79
80
  end
@@ -90,8 +91,8 @@ describe Dnif do
90
91
  Riddle::Client::Filter.should_receive(:new).with("class_id", [0])
91
92
  Riddle::Client::Filter.should_receive(:new).with("class_id", [1])
92
93
 
93
- Post.should_receive(:find_all_by_id).once.with([1])
94
- Comment.should_receive(:find_all_by_id).once.with([2])
94
+ Post.should_receive(:where).with("id IN (?)", [1]).and_return([])
95
+ Comment.should_receive(:where).with("id IN (?)", [2]).and_return([])
95
96
 
96
97
  Post.search("post")
97
98
  Comment.search("comment")
@@ -106,7 +107,8 @@ describe Dnif do
106
107
  ActiveRecord::Base.should_receive(:indexes).and_return({ "Post" => mock })
107
108
 
108
109
  Riddle::Client::Filter.should_receive(:new).with("class_id", [0])
109
- Post.should_receive(:find_all_by_id).once.with([1])
110
+
111
+ Post.should_receive(:where).with("id IN (?)", [1]).and_return([])
110
112
 
111
113
  Dnif.search("post", :classes => "Post")
112
114
  end
@@ -15,6 +15,6 @@ describe Dnif::Index do
15
15
 
16
16
  it "should define where clause" do
17
17
  index = Dnif::Index.new(&proc { where "field = 'value'" })
18
- index.conditions.should == "field = 'value'"
18
+ index.conditions.should == ["field = 'value'"]
19
19
  end
20
20
  end
@@ -17,7 +17,7 @@ describe Dnif::Indexer do
17
17
 
18
18
  klass.indexes["Klass"].fields.should == [ :a ]
19
19
  klass.indexes["Klass"].attributes.should == { :b => :integer }
20
- klass.indexes["Klass"].conditions.should == "c"
20
+ klass.indexes["Klass"].conditions.should == ["c"]
21
21
 
22
22
  klass.indexes.delete("Klass")
23
23
  end
@@ -1,11 +1,19 @@
1
1
  class Post
2
2
 
3
3
  extend Dnif::Search
4
+
5
+ def self.primary_key
6
+ "id"
7
+ end
4
8
  end
5
9
 
6
10
  class Comment
7
11
 
8
12
  extend Dnif::Search
13
+
14
+ def self.primary_key
15
+ "id"
16
+ end
9
17
  end
10
18
 
11
19
  class User < ActiveRecord::Base
metadata CHANGED
@@ -1,14 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnif
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- - beta
10
- - 6
11
- version: 0.0.1.beta.6
8
+ - 0
9
+ version: 0.1.0
12
10
  platform: ruby
13
11
  authors:
14
12
  - Rafael Souza
@@ -16,7 +14,7 @@ autorequire:
16
14
  bindir: bin
17
15
  cert_chain: []
18
16
 
19
- date: 2010-09-08 00:00:00 -03:00
17
+ date: 2010-10-21 00:00:00 -02:00
20
18
  default_executable:
21
19
  dependencies:
22
20
  - !ruby/object:Gem::Dependency
@@ -212,20 +210,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
210
  requirements:
213
211
  - - ">="
214
212
  - !ruby/object:Gem::Version
215
- hash: -3817415889434215376
213
+ hash: -121134360209263234
216
214
  segments:
217
215
  - 0
218
216
  version: "0"
219
217
  required_rubygems_version: !ruby/object:Gem::Requirement
220
218
  none: false
221
219
  requirements:
222
- - - ">"
220
+ - - ">="
223
221
  - !ruby/object:Gem::Version
224
222
  segments:
225
- - 1
226
- - 3
227
- - 1
228
- version: 1.3.1
223
+ - 0
224
+ version: "0"
229
225
  requirements: []
230
226
 
231
227
  rubyforge_project: