Poor Mans Search plugin

Plugin details

poor_mans_search is a mixin for ActiveRecord that provides basic searching on model records utilzing sql search querying. This mixin merely provides automated building of SQL search queries, it is up to you to ensure that the queried columns are properly indexed and/or have the appropriate support on your database.

Websitehttps://yfactorial.devguard.com/trac/commons/wiki/PoorMansSearch Repositoryhttps://yfactorial.devguard.com/svn/commons/plugins/poor_mans_search/trunk Tags Search LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install https://yfactorial.devguard.com/svn/commons/plugins/poor_mans_search/trunk

poor_mans_search is a mixin for ActiveRecord that provides basic searching on model records utilzing sql search querying. This mixin merely provides automated building of SQL search queries, it is up to you to ensure that the queried columns are properly indexed and/or have the appropriate support on your database.

For database independent search functionality, please see acts_as_ferret and acts_as_searchable, among others. Also, please make a conscious decision that db text searching is what you really want - read this blog entry
for a good db vs. ferret comparison:

Include the poor_mans_search_on declaration within any model class that you wish to be searchable. For instance, assume a Post model:

class Post < ActiveRecord::Base
	  poor_mans_search_on :title, :body
end



This gives you the search_for class method on Post that takes a list of search terms and any other standard find options:

	# Get the first 20 posts within the last year that contain the word test
	#
	# Equivalent to the following query:
	#
	#   SELECT * FROM posts WHERE
	#     ((published_at > '2006-08-02 14:29:17') AND
	#      (lower(posts.title) like '%test%' OR lower(posts.body) like '%test%'))
	#     ORDER BY published_at DESC LIMIT 20
	#
  Post.search_for('TEst', :conditions => ["published_at > ?", (Time.now - 1.year)],
													:limit => 20, :order => 'published_at DESC')



See poor_mans_search_on for further documentation

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (2 older versions) | Last edited by: Guest, 7 months ago