An ORM for Solr documents.
Currently, SolrMapper is under active development, and is not ready even for beta use. That said, if you're interested in living on the bleeding edge, you can install the gem from source.
gem 'solrmapper', :git => 'git://github.com/nz/solrmapper.git'
You can use the SolrMapper::Document
class directly…
doc = SolrMapper::Document.new(
:title => "Hello world!",
:content => "My name is Frederick."
)
doc.save
SolrMapper::Document
feels a lot like ActiveRecord. And, indeed, it is build on many of the same fundamentals provided by ActiveModel
and ActiveSupport
.
class Document < SolrMapper::Document
end
doc = Document.create(
:title => "TPS Report #3423"
)
The attribute names given to your documents are expected to match the definitions in your Solr schema.xml
.
Just give your query to the search
class method.
@search = Document.search('hello world')
You can also provide the search
class method with a hash that will be serialized into Solr parameters. If you're familiar with Solr, then this is just the method you're looking for.
@search = Document.search(
:q => 'hello world',
:fq => { :category => 'Cheerful' }
)
@search = Document.search('hello world').
where(category: 'Cheerful').
facet(field: 'category').
mm(1)
@search = Document.facet(fields: %w(category author))
@search.facets.each do |facet|
puts facet.field
facet.terms.each do |term, count|
puts " #{term}: #{count}"
end
puts
end
The above would print something like the following...
Category
Cheerful: 23
Gloomy: 12
Author
e.e. cummings: 14
T.S. Eliot: 10