supernova

Setup

Define Solr Index

class LocationIndex < Supernova::SolrIndexer
  has :title,     :type => :text
  has :location,  :type => :string

  clazz Location

  # is called before hash is added to index (with original database row)
  # only called when defined
  def before_index(row)
    row.merge(:indexed_b => true)
  end

  # is called with a made up record of class defined with "clazz Location" and
  # should return a hash which is merged into the original hash
  # only called when method defined and clazz set
  def extra_attributes_from_record(record)
    { :normalized_title_s => record.normalized_title }
  end
end

Indexing

index = LocationIndex.new(:db => db, :ids => [1, 3, 4])
index.index!

Anonymous Scopes

scope = Offer.order("popularity desc").with(:city => "Hamburg").paginate(:page => 2, :per_page => 10)

# no query sent yet
# query is sent e.g. when

scope.each { |offer| puts offer.city }                            # objects of current page are iterated
scope.total_entries                                               # no objects loaded though
scope.ids                                                         # no objects loaded, only ids are returned
scope.first or scope.last                                         # all objects are loaded, only first or last in "page" is returned

Named Scopes

class Offer
  named_search_scope :popular do
    order("popularity desc")
  end

  named_search_scope :for_artists do |ids|
    with(:artist_id => ids)
  end
end

Offer.popular.for_artists([1, 2, 3])                              # various named scopes can be combined
Offer.popular.for_artists([1, 2, 3]).with(:available => true)     # named scopes can also be combined with anonymous scopes

Geo Searches

Offer.search_scope.near(47.0, 11.0).within(1.kms)
Offer.search_scope.near(47.0, 11.0).within(100.meters)
Offer.search_scope.near(other_offer).within(100.meters)

Contributing to supernova

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2011 Dynport GmbH. See LICENSE.txt for further details.