xapit 0.2.3 → 0.2.4

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/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.2.4* (June 23rd, 2009)
2
+
3
+ * only create/update record in index if it matches xapit find conditions
4
+
5
+
1
6
  *0.2.3* (June 18th, 2009)
2
7
 
3
8
  * adding compatability with Xapit Sync
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('xapit', '0.2.3') do |p|
5
+ Echoe.new('xapit', '0.2.4') do |p|
6
6
  p.summary = "Ruby library for interacting with Xapian, a full text search engine."
7
7
  p.description = "Ruby library for interacting with Xapian, a full text search engine."
8
8
  p.url = "http://github.com/ryanb/xapit"
@@ -27,7 +27,8 @@ module Xapit
27
27
  end
28
28
 
29
29
  # Fetch a single record by the given id.
30
- def find_single(id)
30
+ # The args are the same as those passed from the XapitMember#xapit call.
31
+ def find_single(id, *args)
31
32
  raise "To be implemented in subclass"
32
33
  end
33
34
 
@@ -5,8 +5,8 @@ module Xapit
5
5
  member_class.ancestors.map(&:to_s).include? "ActiveRecord::Base"
6
6
  end
7
7
 
8
- def find_single(id)
9
- @target.find(id)
8
+ def find_single(id, *args)
9
+ @target.find_by_id(id, *args)
10
10
  end
11
11
 
12
12
  def find_multiple(ids)
@@ -93,17 +93,24 @@ module Xapit
93
93
  index + facets.size + sortable_attributes.size
94
94
  end
95
95
 
96
- # Add a single record to the index
96
+ # Add a single record to the index if it matches the xapit options.
97
97
  def create_record(member_id)
98
- @indexer.add_member(@member_class.xapit_adapter.find_single(member_id))
98
+ member = @member_class.xapit_adapter.find_single(member_id, *@args)
99
+ @indexer.add_member(member) if member
99
100
  end
100
101
 
101
- # Update a single record in the index
102
+ # Update a single record in the index. If the record does not match the xapit
103
+ # conditions then it is removed from the index instead.
102
104
  def update_record(member_id)
103
- @indexer.update_member(@member_class.xapit_adapter.find_single(member_id))
105
+ member = @member_class.xapit_adapter.find_single(member_id, *@args)
106
+ if member
107
+ @indexer.update_member(member)
108
+ else
109
+ destroy_record(member_id)
110
+ end
104
111
  end
105
112
 
106
- # Remove a single record from the index
113
+ # Remove a single record from the index.
107
114
  def destroy_record(member_id)
108
115
  Xapit::Config.writable_database.delete_document("Q#{@member_class}-#{member_id}")
109
116
  end
@@ -10,9 +10,9 @@ describe Xapit::ActiveRecordAdapter do
10
10
 
11
11
  it "should pass find_single to find method to target" do
12
12
  target = Object.new
13
- mock(target).find(1) { :record }
13
+ mock(target).find_by_id(1, :conditions => "foo") { :record }
14
14
  adapter = Xapit::ActiveRecordAdapter.new(target)
15
- adapter.find_single(1).should == :record
15
+ adapter.find_single(1, :conditions => "foo").should == :record
16
16
  end
17
17
 
18
18
  it "should pass find_multiple to find method to target" do
@@ -81,20 +81,32 @@ describe Xapit::IndexBlueprint do
81
81
  XapitMember.search("Bad Record").should == []
82
82
  end
83
83
 
84
- it "should remove a record from the index" do
85
- member = XapitMember.new(:name => "Bad Record!")
84
+ it "should update a record in the index" do
85
+ member = XapitMember.new(:name => "New Record!")
86
86
  @index.text :name
87
87
  @index.index_all
88
- @index.destroy_record(member.id)
89
- XapitMember.search("Bad Record").should == []
88
+ member.update_attribute(:name, "Changed Record!")
89
+ @index.update_record(member.id)
90
+ XapitMember.search("Changed Record").should == [member]
90
91
  end
91
92
 
92
- it "should update a record in the index" do
93
+ it "should not create record index if member isn't found" do
94
+ Xapit::Config.writable_database # make sure the database is built
95
+ member = XapitMember.new(:name => "New Record!")
96
+ stub(XapitMember).find { nil }
97
+ @index.text :name
98
+ @index.create_record(member.id)
99
+ XapitMember.search("New Record").should be_empty
100
+ end
101
+
102
+ it "should remove record from index when updating a member which doesn't exist" do
93
103
  member = XapitMember.new(:name => "New Record!")
94
104
  @index.text :name
95
105
  @index.index_all
106
+ stub(XapitMember).find { nil }
96
107
  member.update_attribute(:name, "Changed Record!")
97
108
  @index.update_record(member.id)
98
- XapitMember.search("Changed Record").should == [member]
109
+ XapitMember.search("New Record").should be_empty
110
+ XapitMember.search("Changed Record").should be_empty
99
111
  end
100
112
  end
@@ -26,6 +26,10 @@ class XapitMember
26
26
  end
27
27
  end
28
28
 
29
+ def self.find_by_id(id)
30
+ find(id)
31
+ end
32
+
29
33
  def initialize(attributes = {})
30
34
  @@records ||= []
31
35
  @id = @@records.size + 1
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{xapit}
5
- s.version = "0.2.3"
5
+ s.version = "0.2.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan Bates"]
9
- s.date = %q{2009-06-18}
9
+ s.date = %q{2009-06-23}
10
10
  s.description = %q{Ruby library for interacting with Xapian, a full text search engine.}
11
11
  s.email = %q{ryan (at) railscasts (dot) com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/xapit/adapters/abstract_adapter.rb", "lib/xapit/adapters/active_record_adapter.rb", "lib/xapit/adapters/data_mapper_adapter.rb", "lib/xapit/collection.rb", "lib/xapit/config.rb", "lib/xapit/facet.rb", "lib/xapit/facet_blueprint.rb", "lib/xapit/facet_option.rb", "lib/xapit/index_blueprint.rb", "lib/xapit/indexers/abstract_indexer.rb", "lib/xapit/indexers/classic_indexer.rb", "lib/xapit/indexers/simple_indexer.rb", "lib/xapit/membership.rb", "lib/xapit/query.rb", "lib/xapit/query_parsers/abstract_query_parser.rb", "lib/xapit/query_parsers/classic_query_parser.rb", "lib/xapit/query_parsers/simple_query_parser.rb", "lib/xapit/rake_tasks.rb", "lib/xapit.rb", "LICENSE", "README.rdoc", "tasks/spec.rb", "tasks/xapit.rake", "TODO"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-18 00:00:00 -07:00
12
+ date: 2009-06-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15