Module: ActiveRecord::Acts::Searchable
- Defined in:
- lib/acts_as_searchable.rb
Overview
Specify this act if you want to provide fulltext search capabilities to your model via Hyper Estraier. This assumes a setup and running Hyper Estraier node accessible through the HTTP API provided by the EstraierPure Ruby module (which is bundled with this plugin).
The act supplies appropriate hooks to insert, update and remove documents from the index when you update your model data, create new objects or remove them from your database. For the initial indexing a convenience class method reindex!
is provided.
Example:
class Article < ActiveRecord::Base
acts_as_searchable
end
Article.reindex!
As soon as your model data has been indexed you can make use of the fulltext_search
class method to search the index and get back instantiated matches.
results = Article.fulltext_search('rails')
results.size # => 3
results.first.class # => Article
results.first.body # => "Ruby on Rails is an open-source web framework"
Connectivity configuration can be either inherited from conventions or setup globally in the Rails database configuration file config/database.yml
.
Example:
development:
adapter: mysql
database: rails_development
host: localhost
user: root
password:
estraier:
host: localhost
user: admin
password: admin
port: 1978
node: development
That way you can configure separate connections for each environment. The values shown above represent the defaults. If you don’t need to change any of these it is safe to not specify the estraier
hash at all.
See ActiveRecord::Acts::Searchable::ClassMethods#acts_as_searchable for per-model configuration options
Defined Under Namespace
Modules: ActMethods, ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/acts_as_searchable.rb', line 79 def self.included(base) #:nodoc: base.extend ClassMethods end |