Moonstone

We recently open-sourced Moonstone, our JRuby wrapper around Lucene, the Java search engine toolkit. Moonstone is simple, and easy to use - it lets you put together a powerful search engine quickly. It gives you the full capabilities of Lucene, but replaces the Java-isms with a more Ruby-ish syntax. I wanted to take a quick minute to run through the basics:

Installation

    sudo jruby -S gem install moonstone
Note that if you are on Windows, drop the "sudo". Also, for the record, no one's ever tested Moonstone on Windows. But since it's all JRuby and Java, there shouldn't be any issues...

If you want the source, you can get it from automatthew's github repo.

Engines

Creating an engine requires two things: a doc_from method and an analyzer.

class SimplestEngine def doc_from(record)
doc = Lucene::Document::Doc.new
doc.add_field('name', record[:name])
doc.add_field('desc', record[:description])
doc
end
def analyzer
@analyzer ||= Lucene::Analysis::WhitespaceAnalyzer.new
end
end
# We can now instantiate the engine
engine = SimplestEngine.new
# and create an index of some data
records = [
{:name => "Moonstone", :description => "A simple JRuby wrapper around Lucene"},
{:name => "Foo", :description => "A search engine based on Moonstone"}
]
# By convention the index method accepts an Enumerable that yields hashes
engine.index(records)

#Search for data
q = Lucene::Search::TermQuery.new("name", "Moonstone")
documents = engine.search(q)
documents.each {|d| puts d['name']}
That's it in a nutshell. There are some more examples in the README on github, and more documentation is coming soon.

Happy searching!