Mr. Pitt and Mr. Brosnan

written by benjamin on January 16th, 2007 @ 11:53 AM

One of the great features of textmate, that i got used to so quickly, is the way you load files. If you want to edit the movie_controller, just press cmd-t, enter ‘mo co’ and the movie_controller.rb file will be right there for you to select. This is something i wanted to add to omdb, if you add for example actors to a movie.

Its already possible to add someone like Brad Pitt as an actor by simply searching for ‘br pi’ in the appropriate add-actor dialog. omdb will find Brad, however, you will get results for Pierce Brosnan or Pieter Jan Brugge as well. Entering the phrases ‘br’ and ‘pi’ should make sure, you don’t want to find Pierce Brosnan, otherwise you would have entered ‘pi br’ not ‘br pi’. :-)

With the wonderful magic of ferret, you can do exactly that (you need to upgrade to at least 0.10.14). Take a look at the following example:

require 'rubygems'
require 'ferret'
i = Ferret::I.new
i << {:name => 'Janice Joplin'}
i << {:name => 'James Joyce'}
i << {:name => 'John Jarrett'}

Now here’s the query to make sure you find only two of the people.

include Ferret::Search::Spans
puts i.search(SpanNearQuery.new(:clauses => [
  SpanPrefixQuery.new(:name, 'ja'),
  SpanPrefixQuery.new(:name, 'jo')
], :in_order => true)).to_s(:name)

You just get 2 hits (3 hits with ferret versions prior to 0.10.14). omdb will make use of it in the near future, improving the usabilty even more.

Comments