xapit 0.2.2 → 0.2.3

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,12 @@
1
+ *0.2.3* (June 18th, 2009)
2
+
3
+ * adding compatability with Xapit Sync
4
+
5
+ * adding create/update/destroy record methods for modifying a single record in index
6
+
7
+ * allow ranges to be specified in conditions array
8
+
9
+
1
10
  *0.2.2* (June 16th, 2009)
2
11
 
3
12
  * performance improvements
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.2') do |p|
5
+ Echoe.new('xapit', '0.2.3') 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"
@@ -79,18 +79,35 @@ module Xapit
79
79
  end
80
80
  end
81
81
 
82
+ # The Xapian value index position of a sortable attribute
82
83
  def position_of_sortable(sortable_attribute)
83
84
  index = sortable_attributes.map(&:to_s).index(sortable_attribute.to_s)
84
85
  raise "Unable to find indexed sortable attribute \"#{sortable_attribute}\" in #{@member_class} sortable attributes: #{sortable_attributes.inspect}" if index.nil?
85
86
  index + facets.size
86
87
  end
87
88
 
89
+ # The Xapian value index position of a field attribute
88
90
  def position_of_field(field_attribute)
89
91
  index = field_attributes.map(&:to_s).index(field_attribute.to_s)
90
92
  raise "Unable to find indexed field attribute \"#{field_attribute}\" in #{@member_class} field attributes: #{field_attributes.inspect}" if index.nil?
91
93
  index + facets.size + sortable_attributes.size
92
94
  end
93
95
 
96
+ # Add a single record to the index
97
+ def create_record(member_id)
98
+ @indexer.add_member(@member_class.xapit_adapter.find_single(member_id))
99
+ end
100
+
101
+ # Update a single record in the index
102
+ def update_record(member_id)
103
+ @indexer.update_member(@member_class.xapit_adapter.find_single(member_id))
104
+ end
105
+
106
+ # Remove a single record from the index
107
+ def destroy_record(member_id)
108
+ Xapit::Config.writable_database.delete_document("Q#{@member_class}-#{member_id}")
109
+ end
110
+
94
111
  private
95
112
 
96
113
  # Make sure all models are loaded - without reloading any that
@@ -8,6 +8,10 @@ module Xapit
8
8
  database.add_document(document_for(member))
9
9
  end
10
10
 
11
+ def update_member(member)
12
+ database.replace_document("Q#{member.class}-#{member.id}", document_for(member))
13
+ end
14
+
11
15
  def document_for(member)
12
16
  document = Xapian::Document.new
13
17
  document.data = "#{member.class}-#{member.id}"
@@ -47,6 +47,7 @@ module Xapit
47
47
  @xapit_index_blueprint = IndexBlueprint.new(self, *args)
48
48
  yield(@xapit_index_blueprint)
49
49
  include AdditionalMethods
50
+ include XapitSync::Membership if defined? XapitSync
50
51
  end
51
52
  end
52
53
 
@@ -113,9 +113,6 @@ module Xapit
113
113
  conditions.map do |name, value|
114
114
  if value.kind_of? Array
115
115
  Query.new(value.map { |v| condition_term(name, v) }, :or)
116
- elsif value.kind_of?(Range) && @member_class
117
- position = @member_class.xapit_index_blueprint.position_of_field(name)
118
- Xapian::Query.new(Xapian::Query::OP_VALUE_RANGE, position, Xapit.serialize_value(value.begin), Xapit.serialize_value(value.end))
119
116
  else
120
117
  condition_term(name, value)
121
118
  end
@@ -126,12 +123,17 @@ module Xapit
126
123
  end
127
124
 
128
125
  def condition_term(name, value)
129
- if value.kind_of? Time
130
- value = value.to_i
131
- elsif value.kind_of? Date
132
- value = value.to_time.to_i
126
+ if value.kind_of?(Range) && @member_class
127
+ position = @member_class.xapit_index_blueprint.position_of_field(name)
128
+ Xapian::Query.new(Xapian::Query::OP_VALUE_RANGE, position, Xapit.serialize_value(value.begin), Xapit.serialize_value(value.end))
129
+ else
130
+ if value.kind_of? Time
131
+ value = value.to_i
132
+ elsif value.kind_of? Date
133
+ value = value.to_time.to_i
134
+ end
135
+ "X#{name}-#{value.to_s.downcase}"
133
136
  end
134
- "X#{name}-#{value.to_s.downcase}"
135
137
  end
136
138
  end
137
139
  end
@@ -65,4 +65,36 @@ describe Xapit::IndexBlueprint do
65
65
  mock(XapitMember).find_each(:foo, :bar => :blah)
66
66
  index.index_all
67
67
  end
68
+
69
+ it "should add a record from the index" do
70
+ member = XapitMember.new(:name => "New Record!")
71
+ @index.text :name
72
+ @index.create_record(member.id)
73
+ XapitMember.search("New Record").should == [member]
74
+ end
75
+
76
+ it "should remove a record from the index" do
77
+ member = XapitMember.new(:name => "Bad Record!")
78
+ @index.text :name
79
+ @index.index_all
80
+ @index.destroy_record(member.id)
81
+ XapitMember.search("Bad Record").should == []
82
+ end
83
+
84
+ it "should remove a record from the index" do
85
+ member = XapitMember.new(:name => "Bad Record!")
86
+ @index.text :name
87
+ @index.index_all
88
+ @index.destroy_record(member.id)
89
+ XapitMember.search("Bad Record").should == []
90
+ end
91
+
92
+ it "should update a record in the index" do
93
+ member = XapitMember.new(:name => "New Record!")
94
+ @index.text :name
95
+ @index.index_all
96
+ member.update_attribute(:name, "Changed Record!")
97
+ @index.update_record(member.id)
98
+ XapitMember.search("Changed Record").should == [member]
99
+ end
68
100
  end
@@ -38,4 +38,14 @@ describe Xapit::AbstractQueryParser do
38
38
  parser = Xapit::AbstractQueryParser.new(XapitMember, :conditions => { :foo => 2..5 })
39
39
  parser.condition_terms.first.description.should == expected.description
40
40
  end
41
+
42
+ it "should allow range condition to be specified in array." do
43
+ XapitMember.xapit { |i| i.field :foo }
44
+ expected = Xapian::Query.new(Xapian::Query::OP_OR,
45
+ Xapian::Query.new(Xapian::Query::OP_VALUE_RANGE, 0, Xapian.sortable_serialise(2), Xapian.sortable_serialise(5)),
46
+ Xapian::Query.new(Xapian::Query::OP_AND, ["Xfoo-10"])
47
+ )
48
+ parser = Xapit::AbstractQueryParser.new(XapitMember, :conditions => { :foo => [2..5, 10] })
49
+ parser.condition_terms.first.xapian_query.description.should == expected.description
50
+ end
41
51
  end
@@ -40,4 +40,8 @@ class XapitMember
40
40
  super
41
41
  end
42
42
  end
43
+
44
+ def update_attribute(name, value)
45
+ @attributes[name] = value
46
+ end
43
47
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{xapit}
5
- s.version = "0.2.2"
5
+ s.version = "0.2.3"
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-16}
9
+ s.date = %q{2009-06-18}
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.2
4
+ version: 0.2.3
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-16 00:00:00 -07:00
12
+ date: 2009-06-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15