Ruby on Rails
Searching and Query Plugins (Version #18)

ActiveRecord searching extensions and utilities:

Squirrel Plugin

  • Extension to ActiveRecord::Base#find that allows for block syntax and more natural-looking queries, including crossing associations in a natural, straightforward manner.

svn: http://svn.thoughtbot.com/plugins/squirrel

Where Plugin

svn: http://invisible.ch/svn/projects/plugins/where

ex:

     order = Item.find_with_conditions( :first ) do
                  name 'like', 'Item%'
              end 

Slice and Dice Plugin?

  • Allows construction of where clauses using a hash passed in as the :conditions option, for example:
User.find :first, :conditions => {:name => 'Tom Ward'} # note that this already works in rails
Task.find :all, :conditions => {:priority_more_than => 50} # this one doesn't

svn: svn://rubyforge.org//var/svn/popdog/slice_and_dice/tags/REL-0.1

English style queries

  • Allows construction using English like syntax
    Schools.where 'name includes' => 'George'
    People.awhere 'id in' => [34,35,36]
    

Very addictive!

home page http://code.google.com/p/ruby-roger-useful-functions/wiki/SqlAsEnglish

Criteria Query Plugin?

  • an extension to the ActiveRecord find mechanism. It allows object-oriented construction of queries.
Person.query.first_name_like('%name%').last_name_eq('lastname').join('address').city_eq('Sydney')

SQL Helper?

Helper methods for directly building and combining conditions.

Sql.and(
  ["foo=?", bar],
  Sql.in("id", [1, 3, 5])
)
# => ["(foo=?) AND (id IN (?,?,?))", bar, 1, 3, 5]

rdoc: http://sql-helper.rubyforge.org/rdoc/

svn: http://sql-helper.rubyforge.org/svn/trunk/plugins/sql_helper

Lazy loading plugin

Allows your db to be hit only when you actually run a query (i.e.

a = Item.find :all
a[0] # query is executed right here, instead of when created, above.

website: http://m.onkey.org/2007/12/12/query-objects-and-delayed-execution

Eager Finder SQL Plugin

Allows us to specify custom sql and a column mapping to your find with included associations. On it’s own, ActiveRecord will produce SQL to load multiple associations recursively, but the generated SQL is usually not optimal. This plugin allows you to use customized SQL and map the column results to attributes of your (potentially recursive) eager-loaded associations.

website:
http://rubyforge.org/projects/eagerfindersql/

home page:
http://kellogg-assoc.com/articles/2006/11/05/eager-finder-sql

rdoc:
http://kellogg-assoc.com/rdoc/eager_finder_sql/index.html

svn:
svn://rubyforge.org/var/svn/eagerfindersql

ORMQL Plugin

Allows a query which already preloads (eager loads_ some information from associated objects (so you can create just one AR object instead of many)
ex:

    Customer.find_by_ormql("SELECT user.nick, postal_code.province.name, name WHERE user.nick='Josh'")
into
    "SELECT a.`nick` AS `user.nick`, d.`name` AS `postal_code.province.name`, b.`name` FROM `customers` b LEFT JOIN `postal_codes` c ON c.`id`=b.`postal_code_id` LEFT JOIN `provinces` d ON d.`id`=c.`province_id`, `users` a WHERE  a.`id`=b.`user_id` AND (a.`nick`='Josh')" 

homepage: http://rubyforge.org/projects/ormql/

Enum Column in MySql

An extension to the database adapter, validations, and helpers to support database columns with constrained values using informtion in the database schema (MySql enum column type). Currently MySql is supported, future releases will support other databases using column constraints.

home page:
http://enum-column.rubyforge.org/

website:
http://rubyforge.org/projects/enum-column/

svn:
svn://rubyforge.org/var/svn/enum-column/plugins/enum-column

GnuPG for two-way encryption

Lets you interact with the command-line gpg interface. Assumes you have GnuPG installed, and your keys already generated and ready!

website:
http://www.ahgsoftware.com/pages/gnupg

svn:
svn://ahgsoftware.com/gnupg/trunk

Full-text search engine additions or indexing helps:

Active Search Plugin

svn: http://julik.textdriven.com/svn/tools/rails_plugins/simple_search

SodaSearch Plugin

SodaSearch enhances your existing model objects with full text indexing. It supports stopwords, term stemming, and stores the index right in your RDBMS. An optional “subsource” metadata tag allows you to store arbitrary information along with the index data, enabling reindexing or deletion of arbitrary subsets of the index for a particular item.

http://sodasearch.rubyforge.org/

Acts as Ferret Plugin

  • Mixin that uses ferret to automatically build and maintain an index for fast fulltext search within the data stored in a Rails model.
  • homepage: http://projects.jkraemer.net/acts_as_ferret/
  • svn: svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin/acts_as_ferret

Acts as Solr Plugin

  • The acts_as_solr plugin allows you to interact Rails with the Solr engine, adding full text search capabilities to any Rails model.
  • homepage: http://acts_as_solr.railsfreaks.org/
  • svn: svn://svn.railsfreaks.com/projects/acts_as_solr

Note there is a comparison page of some of these http://blog.evanweaver.com/articles/2008/03/17/rails-search-benchmarks/

ActiveRecord searching extensions and utilities:

Squirrel Plugin

  • Extension to ActiveRecord::Base#find that allows for block syntax and more natural-looking queries, including crossing associations in a natural, straightforward manner.

svn: http://svn.thoughtbot.com/plugins/squirrel

Where Plugin

svn: http://invisible.ch/svn/projects/plugins/where

ex:

     order = Item.find_with_conditions( :first ) do
                  name 'like', 'Item%'
              end 

Slice and Dice Plugin?

  • Allows construction of where clauses using a hash passed in as the :conditions option, for example:
User.find :first, :conditions => {:name => 'Tom Ward'} # note that this already works in rails
Task.find :all, :conditions => {:priority_more_than => 50} # this one doesn't

svn: svn://rubyforge.org//var/svn/popdog/slice_and_dice/tags/REL-0.1

English style queries

  • Allows construction using English like syntax
    Schools.where 'name includes' => 'George'
    People.awhere 'id in' => [34,35,36]
    

Very addictive!

home page http://code.google.com/p/ruby-roger-useful-functions/wiki/SqlAsEnglish

Criteria Query Plugin?

  • an extension to the ActiveRecord find mechanism. It allows object-oriented construction of queries.
Person.query.first_name_like('%name%').last_name_eq('lastname').join('address').city_eq('Sydney')

SQL Helper?

Helper methods for directly building and combining conditions.

Sql.and(
  ["foo=?", bar],
  Sql.in("id", [1, 3, 5])
)
# => ["(foo=?) AND (id IN (?,?,?))", bar, 1, 3, 5]

rdoc: http://sql-helper.rubyforge.org/rdoc/

svn: http://sql-helper.rubyforge.org/svn/trunk/plugins/sql_helper

Lazy loading plugin

Allows your db to be hit only when you actually run a query (i.e.

a = Item.find :all
a[0] # query is executed right here, instead of when created, above.

website: http://m.onkey.org/2007/12/12/query-objects-and-delayed-execution

Eager Finder SQL Plugin

Allows us to specify custom sql and a column mapping to your find with included associations. On it’s own, ActiveRecord will produce SQL to load multiple associations recursively, but the generated SQL is usually not optimal. This plugin allows you to use customized SQL and map the column results to attributes of your (potentially recursive) eager-loaded associations.

website:
http://rubyforge.org/projects/eagerfindersql/

home page:
http://kellogg-assoc.com/articles/2006/11/05/eager-finder-sql

rdoc:
http://kellogg-assoc.com/rdoc/eager_finder_sql/index.html

svn:
svn://rubyforge.org/var/svn/eagerfindersql

ORMQL Plugin

Allows a query which already preloads (eager loads_ some information from associated objects (so you can create just one AR object instead of many)
ex:

    Customer.find_by_ormql("SELECT user.nick, postal_code.province.name, name WHERE user.nick='Josh'")
into
    "SELECT a.`nick` AS `user.nick`, d.`name` AS `postal_code.province.name`, b.`name` FROM `customers` b LEFT JOIN `postal_codes` c ON c.`id`=b.`postal_code_id` LEFT JOIN `provinces` d ON d.`id`=c.`province_id`, `users` a WHERE  a.`id`=b.`user_id` AND (a.`nick`='Josh')" 

homepage: http://rubyforge.org/projects/ormql/

Enum Column in MySql

An extension to the database adapter, validations, and helpers to support database columns with constrained values using informtion in the database schema (MySql enum column type). Currently MySql is supported, future releases will support other databases using column constraints.

home page:
http://enum-column.rubyforge.org/

website:
http://rubyforge.org/projects/enum-column/

svn:
svn://rubyforge.org/var/svn/enum-column/plugins/enum-column

GnuPG for two-way encryption

Lets you interact with the command-line gpg interface. Assumes you have GnuPG installed, and your keys already generated and ready!

website:
http://www.ahgsoftware.com/pages/gnupg

svn:
svn://ahgsoftware.com/gnupg/trunk

Full-text search engine additions or indexing helps:

Active Search Plugin

svn: http://julik.textdriven.com/svn/tools/rails_plugins/simple_search

SodaSearch Plugin

SodaSearch enhances your existing model objects with full text indexing. It supports stopwords, term stemming, and stores the index right in your RDBMS. An optional “subsource” metadata tag allows you to store arbitrary information along with the index data, enabling reindexing or deletion of arbitrary subsets of the index for a particular item.

http://sodasearch.rubyforge.org/

Acts as Ferret Plugin

  • Mixin that uses ferret to automatically build and maintain an index for fast fulltext search within the data stored in a Rails model.
  • homepage: http://projects.jkraemer.net/acts_as_ferret/
  • svn: svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin/acts_as_ferret

Acts as Solr Plugin

  • The acts_as_solr plugin allows you to interact Rails with the Solr engine, adding full text search capabilities to any Rails model.
  • homepage: http://acts_as_solr.railsfreaks.org/
  • svn: svn://svn.railsfreaks.com/projects/acts_as_solr

Note there is a comparison page of some of these http://blog.evanweaver.com/articles/2008/03/17/rails-search-benchmarks/