xapian_db 0.5.2 → 0.5.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.md CHANGED
@@ -1,3 +1,17 @@
1
+ ##0.5.3 (February 15th, 2011)
2
+
3
+ Fixes:
4
+
5
+ - index blueprints can now handle inheritance. If a class does not have its own index blueprint,
6
+ xapian_db uses the index blueprint from its super class (if defined)
7
+ - Added an ignore option to the blueprint definition to filter out objects that should not go into the index
8
+
9
+ ##0.5.2 (January 11th, 2011)
10
+
11
+ Features:
12
+
13
+ - xapian-core and xapian-ruby-bindings sources are now included and will be compiled and installed with the gem
14
+
1
15
  ##0.5.1 (December 22th, 2010)
2
16
 
3
17
  Features:
@@ -29,7 +43,7 @@ Changes:
29
43
 
30
44
  Bugfixes:
31
45
 
32
- - fixed the initialization error in a Rails app ig there is no xapian_db.yml config file
46
+ - fixed the initialization error in a Rails app if there is no xapian_db.yml config file
33
47
  - fixed the fallback to the global language when a model has an unsupported language and a
34
48
  language method is configured in the blueprint
35
49
  - fixed an issue with yaml deserialization of ActiveRecord objects (only the attributes hash
data/README.rdoc CHANGED
@@ -28,33 +28,16 @@ So I started to rethink fulltext indexing again. I looked for something that
28
28
 
29
29
  I tried hard but I couldn't find such a thing so I decided to write it, based on the Xapian library.
30
30
 
31
- == Getting started
32
-
33
- If you want to use xapian_db in a Rails app, you need Rails 3 or newer.
34
-
35
- === Install Xapian if not already installed
31
+ <b>If you found a bug or are looking for a missing feature, please post to the {Google Group}[http://groups.google.com/group/xapian_db]</b>
36
32
 
37
- To use xapian_db, make sure you have the Xapian library and ruby bindings installed. At the time of this writing, the newest release of Xapian was 1.2.4. You might
38
- want to adjust the URLs below to load the most current release of Xapian.
39
- The example code works for OSX. On linux you might want to use wget instead of curl.
33
+ == Requirements
40
34
 
41
- A future release of xapian_db might include the Xapian binaries and make this step obsolete.
35
+ * ruby 1.9.2 or better
36
+ * rails 3.0 or better (if you want to use it with rails)
42
37
 
43
- ==== Install Xapian
44
- curl -O http://oligarchy.co.uk/xapian/1.2.4/xapian-core-1.2.4.tar.gz
45
- tar xzvf xapian-core-1.2.4.tar.gz
46
- cd xapian-core-1.2.4
47
- ./configure --prefix=/usr/local
48
- make
49
- sudo make install
38
+ == Getting started
50
39
 
51
- ==== Install ruby bindings for Xapian
52
- curl -O http://oligarchy.co.uk/xapian/1.2.2/xapian-bindings-1.2.4.tar.gz
53
- tar xzvf xapian-bindings-1.2.4.tar.gz
54
- cd xapian-bindings-1.2.4
55
- ./configure --prefix=/usr/local XAPIAN_CONFIG=/usr/local/bin/xapian-config
56
- make
57
- sudo make install
40
+ If you want to use xapian_db in a Rails app, you need Rails 3 or newer.
58
41
 
59
42
  For a first look, look at the examples in the examples folder. There's the simple ruby script basic.rb that shows the basic
60
43
  usage of XapianDB without rails. In the basic_rails folder you'll find a very simple Rails app unsing XapianDb.
@@ -123,6 +106,14 @@ Use blocks for complex evaluations of attributes or indexed values:
123
106
  end
124
107
  end
125
108
 
109
+ You may add a filter expression to exclude objects from the index. This is handy to skip objects that are not active, for example:
110
+
111
+ XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
112
+ blueprint.attributes :name, :first_name, :profession
113
+ blueprint.index :notes, :remarks, :cv
114
+ blueprint.ignore_if {active == false}
115
+ end
116
+
126
117
  place these configurations either into the corresponding class or - I prefer to have the index configurations outside
127
118
  the models - into the file config/xapian_blueprints.rb.
128
119
 
@@ -267,7 +258,7 @@ The easiest way is to use macports or homebrew:
267
258
 
268
259
  === 4. start the beanstalk daemon
269
260
 
270
- beanstalk -d
261
+ beanstalkd -d
271
262
 
272
263
  === 5. start the beanstalk worker from within your Rails app root directory
273
264
 
@@ -39,7 +39,12 @@ module XapianDb
39
39
 
40
40
  # add the after save logic
41
41
  after_save do
42
- XapianDb::Config.writer.index(self)
42
+ blueprint = XapianDb::DocumentBlueprint.blueprint_for klass
43
+ if blueprint.should_index?(self)
44
+ XapianDb::Config.writer.index(self)
45
+ else
46
+ XapianDb::Config.writer.unindex(self)
47
+ end
43
48
  end
44
49
 
45
50
  # add the after destroy logic
@@ -38,7 +38,12 @@ module XapianDb
38
38
 
39
39
  # add the after save logic
40
40
  after :save do
41
- XapianDb::Config.writer.index(self)
41
+ blueprint = XapianDb::DocumentBlueprint.blueprint_for klass
42
+ if blueprint.should_index?(self)
43
+ XapianDb::Config.writer.index(self)
44
+ else
45
+ XapianDb::Config.writer.unindex(self)
46
+ end
42
47
  end
43
48
 
44
49
  # add the after destroy logic
@@ -32,7 +32,6 @@ module XapianDb
32
32
 
33
33
  # Configure the blueprint for a class.
34
34
  # Available options:
35
- # - language_method (see {#language_method} for details)
36
35
  # - adapter (see {#adapter} for details)
37
36
  # - attribute (see {#attribute} for details)
38
37
  # - index (see {#index} for details)
@@ -49,7 +48,15 @@ module XapianDb
49
48
  # Get the blueprint for a class
50
49
  # @return [DocumentBlueprint]
51
50
  def blueprint_for(klass)
52
- @blueprints[klass] if @blueprints
51
+ if @blueprints
52
+ key = klass
53
+ while key != Object
54
+ return @blueprints[key] unless @blueprints[key].nil?
55
+ key = key.superclass
56
+ end
57
+ raise "Blueprint for class #{klass} is not defined"
58
+ end
59
+ raise "Blueprint for class #{klass} is not defined"
53
60
  end
54
61
 
55
62
  # Return an array of all configured text methods in any blueprint
@@ -116,6 +123,13 @@ module XapianDb
116
123
  @prefixes ||= @indexed_methods_hash.keys
117
124
  end
118
125
 
126
+ # Should the object go into the index? Evaluates an ignore expression,
127
+ # if defined
128
+ def should_index? obj
129
+ return obj.instance_eval(&@ignore_expression) == false if @ignore_expression
130
+ true
131
+ end
132
+
119
133
  # Lazily build and return a module that implements accessors for each field
120
134
  # @return [Module] A module containing all accessor methods
121
135
  def accessors_module
@@ -236,6 +250,11 @@ module XapianDb
236
250
  end
237
251
  end
238
252
 
253
+ # Add a block of code that evaluates if a model should not be indexed
254
+ def ignore_if &block
255
+ @ignore_expression = block
256
+ end
257
+
239
258
  # Options for an indexed method
240
259
  class IndexOptions
241
260
 
@@ -55,8 +55,12 @@ module XapianDb
55
55
  nr_of_batches = (obj_count / 1000) + 1
56
56
  nr_of_batches.times do |batch|
57
57
  klass.all(:offset => batch * 1000, :limit => 1000) .each do |obj|
58
- doc = indexer.build_document_for(obj)
59
- XapianDb.database.store_doc(doc)
58
+ if blueprint.should_index? obj
59
+ doc = indexer.build_document_for(obj)
60
+ XapianDb.database.store_doc(doc)
61
+ else
62
+ XapianDb.database.delete_doc_with_unique_term(obj.xapian_id)
63
+ end
60
64
  pbar.inc if show_progressbar
61
65
  end
62
66
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xapian_db
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 5
8
- - 2
9
- version: 0.5.2
4
+ prerelease:
5
+ version: 0.5.3
10
6
  platform: ruby
11
7
  authors:
12
8
  - Gernot Kogler
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-11 00:00:00 +01:00
13
+ date: 2011-02-15 00:00:00 +01:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 3
31
- - 1
32
24
  version: 2.3.1
33
25
  type: :development
34
26
  version_requirements: *id001
@@ -40,10 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 3
46
- - 7
47
35
  version: 0.3.7
48
36
  type: :development
49
37
  version_requirements: *id002
@@ -55,10 +43,6 @@ dependencies:
55
43
  requirements:
56
44
  - - ">="
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 1
60
- - 1
61
- - 0
62
46
  version: 1.1.0
63
47
  type: :development
64
48
  version_requirements: *id003
@@ -129,23 +113,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
113
  requirements:
130
114
  - - ">="
131
115
  - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
116
  version: "0"
135
117
  required_rubygems_version: !ruby/object:Gem::Requirement
136
118
  none: false
137
119
  requirements:
138
120
  - - ">="
139
121
  - !ruby/object:Gem::Version
140
- segments:
141
- - 1
142
- - 3
143
- - 6
144
122
  version: 1.3.6
145
123
  requirements: []
146
124
 
147
125
  rubyforge_project:
148
- rubygems_version: 1.3.7
126
+ rubygems_version: 1.5.2
149
127
  signing_key:
150
128
  specification_version: 3
151
129
  summary: Ruby library to use a Xapian db as a key/value store with high performance fulltext search