Full-Text Indexing in Ruby Using Ferret - Few things are more useful that a good full-text search. It's clearly the easiest way for users to actively drill down into the content they want. It's also quite easy on the Ruby programmer to implement thanks to Ferret, an Apache Lucene-inspired search engine library. Building an Index The first step to implementing a search is to get an index built. The following code illustrates creating an index with two documents in it. require 'ferret' include Ferret # get or create an index on the filesystem index = Index::Index.new(:path => './test.idx') # store a document index 'A Cool Article', :content => 'Penguins are cool.' } # store another document index 'A Hot Article', :content => 'Volcanoes are hot' } Querying the Index Now that the index is built it's ready to...
Faceted Queries on acts_as_solr Associations - Recently in a rails app that employs Solr (via the acts_as_solr plugin) I've had the need to produce aggregate counts of entities on the far end of a many-to-many relationship. Essentially a tag cloud. My first attempt was to keep it entirely in ActiveRecord which resulted in a proliferation of SQL command executions. Obviously that wasn't performant. Sure it looked elegant, but was slow and unsustainable. While I could have hand-crafted the SQL it was more performant still to retrieve the aggregations from Solr via facets. Hell, I had the data handy! Such a faceted query directly from Solr is qutie simple but it required a little research to get it done with acts_as_solr due to my unfamiliarity with it. In order to make it simple for others attempting to do...
MapReduce with MongoMapper - A number of rails projects I've been working on lately have used MongoDB for a back-end via MongoMapper. In general it seems to do pretty much anything I'd want to do in a typical web app but finding documentation on how to do it can be difficult. One such task I came across recently was performing on-the-fly map-reduce. After implementing it myself I decided to share a simple example. Blog Post Example Consider the typical Article model which is essentially a blog post. A title, some content and a list of tags. What I'll do is produce aggregate counts that could be used to display a tag cloud. class Article include MongoMapper::Document key :title, String key :content, String key :tags, Array end Sample Data I'll throw in three sample articles from...











