Skip to content
Search migrations gem for PostgreSQL
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

buscando el viento

buscando el viento is a search migrations gem for PostgreSQL and Rails 3. It enables full-text searching by automating the process of creating appropriate migrations, and is largely based on Xavier Shay's PeepCode video on Postgres.


gem install buscando_el_viento


Inherit from BuscandoMigration instead of ActiveRecord::Migration. The BuscandoElViento version includes additional class methods. For example,

add_search_vector :users, :username

will add a search vector attribute to your users table, tracking the username attribute.

However if you do this

add_search :users, :username, :fuzzy => true

you get the search vector, a database trigger to keep that vector up to date, and an index to make retrieval fast.

Obviously the :fuzzy flag represents fuzzy versus exact search; this simply turns stemming on or off, although PostgreSQL supports a lot of additional features and options in its full-text search capacities. Use remove_search in the down method, to avoid IrreversibleMigrations. (Buscando doesn't support the def change approach yet, although there's no real reason why not.)

tests and specs

In order to run your Rails tests, if you use PostgreSQL this way, you'll need to modify how Rails handles schema dumps. See the Postgres PeepCode for more info.

In terms of the gem's own specs, these could be better. They really just test the implementation, which is to say they verify that calling particular methods on the custom migration invokes particular other methods on the ActiveRecord migration.

This makes the specs fast, and I prefer tests and specs which circumvent the database in most circumstances, but if you're noodling around wondering what kind of patches a project this awesome could possibly need, I'd have a look at verifying that the specs actually result in code which can perform searches properly.

wtf? is that name spanish?

yes. "buscando el viento" means "seeking the wind" and gets its name from a line in a poem by Pablo Neruda.

mi voz buscaba el viento para tocar su oido

which means

my voice sought the wind to touch her hearing

(there's a nuance here: where in English, you say a person "plays" a musical instrument, in order to bring forth sound, in Spanish, you say a person "touches" a musical instrument.)

I chose the name because it annoys me how many APIs use find where what they really mean is seek or look for, and this made me think of how useful it is that Spanish has a commonly-used word which means to look for something. In English, we have look for, which is not really a word but an idiom, and incorporating prepositions into your code is difficult outside of Smalltalk; meanwhile, seek is great, but nobody in the United States seems to use it at all, unless they're hippies seeking for truth or sword-bearing elves seeking the Great Chalice Of Whatever The Fuck.


  • Giles Bowkett
  • Xavier Shay


MIT License (which document included by reference)

hook a brother up

Patches requested:

  • setweight() support (crucial)
  • Rails 3.1 generators, both to generate migrations and relevant model finders
  • support for def change vs def up and def down
  • better specs
  • quite frankly, a better understanding of PostgreSQL would be useful

here be dragons

This gem is still very early days status. May explode unexpectedly. Do not taunt Happy Fun Ball.

Something went wrong with that request. Please try again.