README.rdoc in xapian_db-0.3.3 vs README.rdoc in xapian_db-0.3.4

- old
+ new

@@ -114,54 +114,89 @@ blueprint.language_method :language end The method must return the iso code for the language (:en, :de, ...) as a symbol or a string. Don't worry if you have languages in your database that are not supported by Xapian. If the language is not supported, XapianDb will fall back to the global language configuration or none, if you haven't configured one. +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| + 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| + blueprint.attribute :complex do + if @id == 1 + "One" + else + "Not one" + end + end + end + You can place this configuration anywhere, e.g. in an initializer. === Update the index xapian_db injects some helper methods into your configured model classes that update the index automatically for you when you create, save or destroy models. If you already have models that should now go into the index, use the method <code>rebuild_xapian_index</code>: Person.rebuild_xapian_index +To get info about the reindex process, use the verbose option: + + Person.rebuild_xapian_index :verbose => true + +In verbose mode, XapianDb will use the progressbar gem if available. + === Query the index A simple query looks like this: results = XapianDb.search("Foo") You can use wildcards and boolean operators: - results = XapianDb.search("Fo*" OR "Baz") + results = XapianDb.search("fo* or baz") You can query attributes: results = XapianDb.search("name:Foo") +You can query objects of a specific class: + + results = Person.search("name:Foo") + +If you want to override the default of 10 docs per page, pass the :per_page argument: + + results = Person.search("name:Foo", :per_page => 20) + === Process the results <code>XapianDb.search</code> returns a resultset object. You can access the number of hits directly: results.size # Very fast, does not load the resulting documents If you use a persistent database, the resultset may contain a spelling correction: # Assuming you have at least one document containing "mouse" results = XapianDb.search("moose") - results.corrected_query # "mouse" + results.spelling_suggestion # "mouse" To access the found documents, get a page from the resultset: - page = result.paginate # Get the first page with 10 documents - page = result.paginate(:page => 2, :per_page => 20) # Get the second page page with documents 21-40 + page = result.paginate # Get the first page + page = result.paginate :page => 2 # Get the second page Now you can access the documents: doc = page.first - puts doc.domain_class # Get the type of the indexed object, e.g. "Person" + puts doc.indexed_class # Get the type of the indexed object as a string, e.g. "Person" puts doc.name # We can access the configured attributes person = doc.indexed_object # Access the object behind this doc (lazy loaded) == What to expect from future releases \ No newline at end of file