Acts As Fulltext Indexed plugin

Plugin details

Enable full text search for Mysql InnoDB, just like MyISAM tables.

Websitehttp://blog.antiarc.net/2007/05/01/introducing-acts_as_fulltext_indexed/ Repositoryhttp://svn.digitalsentience.com/svn/rails/acts_as_fulltext_indexed/ Author Chris Heald Tags mysql, innodb, Search LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.digitalsentience.com/svn/rails/acts_as_fulltext_indexed/

Now you can perform the following operations:

# Will return all posts that have words matching "foobar*"
Post.search("foobar")

# Will return all posts that have words matching "foo* AND bar*"
Post.search("foo bar")


If you need more complex indexing - say you want to be able to index association data on the parent - then you need to override build_index_string. In this example, I’m setting the indexed string for the thread to the concatenation of all the bodies of the posts on the thread, as well as the thread title.

class Thread < ActiveRecord::Base
    has_many :posts
    acts_as_fulltext_indexed

    def build_index_string
        self.title + posts.collect {|post| post.body}.join(" ")
    end
end


Now we can perform:

Thread.search("foo bar")


Which will return all Threads that contain posts whose bodies contain “foo* AND bar*“, or whose title matches “foo* AND bar*“.

Search also takes options such as :order, :limit, and :conditions

Thread.search("foo bar", {:include => [:posts], :order => "threads.created_at asc", :limit => 10})


Finally, search() takes a third parameter. A boolean “transform” specifies whether or not to transform your search string into MySQL boolean search syntax. It’s true by default, but you can turn it off if you want to specify a mode complex search.

# Finds all Threads that contain "foo*" but do NOT contain "bar"
Thread.search("+foo* -bar", {:include => [:posts]}, false)

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 7 months ago