✓ I'm available for hire! Check out my open source work on Github or drop me an email

Douglas F Shearer

Posts Tagged with search

There are 7 matching posts.

Acts_As_indexed v0.5.0 Released

My Acts_as_indexed plugin has been updated to version 0.5.0.

New in this version is:

  • Ruby 1.9 and Rails 2.3 compatibility.
  • Index location can now be set. Provides Heroku compatibility.
  • Better errors on bad options.
  • ActiveRecord order argument overrides ranking returned by find_by_index.
  • Various test environment improvements
  • Various Bugfixes

Get it on Github or view the RDoc.

 
 

Acts_As_Indexed now on GitHub

A few people had been requesting that I moved my Acts_as_indexed plugin to GitHub.

See the original post for the new install details.

Pagination

The pagination for this plugin has now been rolled into the release version, no more separate plugin.

 
 

Acts_As_indexed v0.2.1 Released

My Acts_as_indexed plugin has been updated to version 0.2.1.

New in this version is:

  • Search now accepts all the standard Active Record find options.
 
 

Acts_As_indexed v0.2 Released

My Acts_as_indexed plugin has been updated to version 0.2.0.

New in this version is:

  • Major performance improvements.
  • Segmentation of the index can now be tuned.
 
 

Rails Plugin: Acts_As_Indexed

Version 0.4.4 released 04 February 2008 – Fixed some minor AR bugs

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

Install

./script/plugin install git://github.com/dougal/acts_as_indexed.git

If you don’t have git installed, you can download the plugin from the GitHub page and unpack it into the vendor/plugins directory of your rails app.

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

Searching

To search, call the find_with_index method on your model to search using the index. The optional ids_only 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') # =>  [#<Post:0x314b09c @attributes={"...
	
	# Pass any of the ActiveRecord find options to the search.
	my_search_results = Post.find_with_index('my search query',{:limit => 10}) # return the first 10 matches.
	
	# Returns array of IDs.
	my_search_results = Post.find_with_index('my search query',{},{:ids_only => true}) # =>  [12,19,33...

h4. Boolean 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’
  • INCLUDE – “cat +me” will find records matching “cat” and “me”, even if “me” is smaller than the min_word_size.
  • "" – 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.

Pagination

Pagination is supported via the paginate_search method whose first argument is the search query, followed all the standard will_paginate arguments.


@images = Image.paginate_search 'girl', :page => 1, :per_page => 5

Other Stuff

Full Documentation

You can either build the rdoc by running rake rdoc in the acts_as_indexed directory, or look at the latest version online.

Problems, Comments, Suggestions?

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

Credits

Douglas F Shearer

Donate

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

 
 

Search Back Up

Thanks to Jens Kraemer for sending me a copy of the ferret_ext file I was requiring to get my search working. Maybe upgrading from Ubuntu Breezy to Dapper causes a few problems I hadn’t come across before. I’ll need to try a fresh install of Dapper, and see if compiling Ferret works on that. I’m now running Capistrano, a very clever set of Rake deployment scripts for rails. Being able to commit a revision to the live server, and revert to the previous version if it all goes wrong is brilliant.
 
 

Finally Online

After 3 days of torment attempting to get my new Rails app online, it is now up!

My server is now running Ubuntu Dapper with Lighttpd and FastGGI serving my blog. I ran into two problems getting this to work:

  1. First up Ferret does not install properly, and the file ferret_ext appears not to be compiled, and thus unavailable to the app. As soon as I started the server it would crash, citing the missing file. For this reason search is disabled, but will hopefully be reinstated as soon as I have solved my problems with this.
  2. The RMagick Gem wouldn’t work, and was again cited as missing by the server. I uninstalled the RMagick gem, and installed the ruby library available in the Ubuntu packages. I’ll put instructions for this in another Blog post.
Hope you like the new design, I certainly feel it was worth all the effort it took, though I’m slightly disappointed that my search isn’t working for the moment.