Acts As Indexed plugin

Plugin details

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

Repositorysvn://svn.douglasfshearer.com/rails/plugins/acts_as_indexed Author Douglas F Shearer Tags Search LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install svn://svn.douglasfshearer.com/rails/plugins/acts_as_indexed

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 table columns, but can be any instance method of the current model.

	class User < ActiveRecord::Base
	  acts_as_indexed :fields => [:address, :fullname]

		def fullname
			return self.firstname + ' ' + self.lastname
		end

	  ...
	end



Acts_as_indexed automatically filters out 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 to search using the index. The optional +ids+ parameter, when set to true, will return only the IDs of any matching records.

	# Returns array of Post objects.
	my_search_results = Post.find_with_index('my search query') # =>  @attributes={"...
	
	# Returns array of IDs.
	my_search_results = Post.find_with_index('my search query',true) # =>  [12,19,33...




== Query Options

The following query operators are supported:

AND - This is the default option. 'cat dog' will find records matching 'cat' AND 'dog'.
NOT - 'cat -dog' will find records matching 'cat' AND NOT 'dog'
"" - Quoted terms are matched as phrases. '"cat dog"' will find records matching the whole phrase.
Quoted terms can be preceded by the NOT operator. 'cat -"big dog"' etc.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (2 older versions) | Last edited by: scott, about 1 year ago