README.rdoc in xapian_db-1.2.2.2 vs README.rdoc in xapian_db-1.2.3
- old
+ new
@@ -82,13 +82,14 @@
If you do not configure settings for an environment in this file, xapian_db applies the defaults.
=== Configure an index blueprint
-In order to get your models indexed, you must configure a document blueprint for each class you want to index:
+In order to get your models indexed, you must configure a document blueprint for each class you want to index. You can pass the class name as a
+symbol or as a string (if the class is namespaced):
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.attribute :name, :weight => 10
blueprint.attribute :first_name
end
The example above assumes that you have a class <code>Person</code> with the methods <code>name</code> and <code>first_name</code>.
@@ -98,20 +99,20 @@
blueprint.index :remarks, :weight => 5
If you want to declare multiple attributes or indexes with default options, you can do this in one statement:
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.attributes :name, :first_name, :profession
blueprint.index :notes, :remarks, :cv
end
Note that you cannot add options using this mass declaration syntax (e.g. <code>blueprint.attributes :name, :weight => 10, :first_name</code> is not valid).
Use blocks for complex evaluations of attributes or indexed values:
- XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:IndexedObject) do |blueprint|
blueprint.attribute :complex do
if @id == 1
"One"
else
"Not one"
@@ -119,47 +120,47 @@
end
end
You may add a filter expression to exclude objects from the index. This is handy to skip objects that are not active, for example:
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.attributes :name, :first_name, :profession
blueprint.index :notes, :remarks, :cv
blueprint.ignore_if {active == false}
end
You can add a type information to an attribute. As of now the special types :string, :date and :number are supported (and required for range queries):
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.attribute :age, :as => :number
blueprint.attribute :date_of_birth, :as => :date
blueprint.attribute :name, :as => :string
end
You can override the global adapter configuration in a specific blueprint. Let's say you use ActiveRecord, but you have
one more class that is not stored in the database, but you want it to be indexed:
- XapianDb::DocumentBlueprint.setup(SpecialClass) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:SpecialClass) do |blueprint|
blueprint.adapter :generic
blueprint.index :some_stuff
end
If you use associations in your blueprints, it might be a good idea to specify a base query to speed up rebuild_xapian_index calls (avoiding 1+n queries):
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.index :addresses
blueprint.base_query Person.includes(:addresses)
end
You can specify a natural sort order for each class using a method symbol or a block. If you don't specify an order expression in your xapian query, the matches
are ordered by relevance and - within the same relevance - by the natural sort order. If you don't specify the natural sort order, it defaults to id. Examples:
- XapianDb::DocumentBlueprint.setup(House) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:House) do |blueprint|
blueprint.natural_sort_order :number
end
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.natural_sort_order do
"#{surname} #{name}"
end
end
@@ -225,10 +226,10 @@
results = Person.search "name:Foo", :order => :first_name
results = Person.search "Fo*", :order => [:name, :first_name], :sort_decending => true
If you define an attribute with a supported type, you can do range searches:
- XapianDb::DocumentBlueprint.setup(Person) do |blueprint|
+ XapianDb::DocumentBlueprint.setup(:Person) do |blueprint|
blueprint.attribute :age, :as => :number
blueprint.attribute :date_of_birth, :as => :date
blueprint.attribute :name, :as => :string
end