Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Acts As Indexed

Acts As Indexed

= acts_as_indexed

If you find this plugin useful, please consider a donation to show your support!

http://www.paypal.com/cgi-bin/webscr?cmd=_send-money

Paypal address: mailto:dougal.s@gmail.com

Instructions

This plugin allows boolean-queried fulltext search to be added to any Rails app with no dependencies and minimal setup.

Resources

=== Install ./script/plugin install http://svn.douglasfshearer.com/rails/plugins/acts_as_indexed

Usage = Setup

Add acts_as_indexed to the top of any models you want to index, along with a list of the fields you wish to be indexed.

class Post < ActiveRecord::Base
  acts_as_indexed :fields => [:title, :body]
end
...

The fields are not limited to model fields, but can be any instance method of the current model.

class User < ActiveRecord::Base
  acts_as_indexed :fields => [:address, :fullname]
end
def fullname
      return self.firstname + ' ' + self.lastname
  end
...

Acts_as_indexed automatically filters out query words shorter than 3 characters, for performance sake. This value can be changed by passing min_word_size along with the fields. NOTE: The index files must be rebuilt by deleting the ‘index’ directory in your app’s root directory.

class Post < ActiveRecord::Base
  acts_as_indexed :fields => [:title, :body], :min_word_size => 5
end
...

=== Searching

To search, call the find_with_index method on your model, passing a query as the first argument. The optional ids_only parameter, when set to true, will return only the IDs of any matching records. plugin folder. Then point your browser at /vendor/plugins/acts_as_indexed/rdoc/index.html.

  1. Returns array of Post objects. my_search_results = Post.find_with_index(‘my search query’) # => [#<post:0×314b09c>rake rdoc task in the acts_as_indexed

Alternatively, you can view the rdoc documentation online[http://douglasfshearer.com/rdoc/acts_as_indexed/].

Problems, Comments, Suggestions?

All of the above are most welcome. mailto:dougal.s@gmail.com

Credits

Douglas F Shearer – http:douglasfshearer.com

== Future Releases

Future releases will be looking to add the following features:
  • Optional html scrubbing during indexing.
  • Ranked results based on query term occurences.
  • Ranking affected by field weightings.

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'