Sha256: 14758e572619e49767a6f906429eb1414eb50d3280a9640b0bfbc9e621722cb4

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

Lunar
=====

A minimalistic search index implemented using Redis, taking advantage of its 
powerful `sorted sets` and the ability to do set intersection and union.

Results are sorted by their word score, which is stored as the score in the
Redis sorted set.

Examples
--------

    class Item < Ohm::Model
      attribute :name
      attribute :description
      
    protected
      def write
        super
        index
      end

      def index
        Lunar::Index.create 'Item' do |i|
          i.key  id
          i.attr :name, name
          i.attr :description, description
        end
        
        # You can also do this, no problem
        Lunar::Index.create Item do |i|
          i.key  id
          i.attr :name, name
          i.attr :description, description
        end

        # Or to avoid name ties...
        Lunar::Index.create self.class do |i|
          i.key  id
          i.attr :name, name
          i.attr :description, description
        end

        Lunar::Index.create Item do |i|
          i.key id
          i.fuzzy   :name, name # this has a 100 character limit on name
                                # for performance reasons
          i.integer :cost, cost
          i.float   :voting_quotient, voting_quotient
        end
      end
    end

    # Searching...
    # You can just straight out search keywords
    Lunar.search(Item, "iphone")

    # Or opt to filter by field
    Lunar.search(Item, :name => "iphone", :description => "mobile")
    
    # For fuzzy declared fields you can currently only search 
    # using a fuzzy strategy exclusively, e.g.
    Lunar.search(Item, :fuzzy => { :name => "i" })
    # i, ip, iph, ipho, iphone, 3, 3g, 3gs all would match 'iPhone 3Gs'
    
    # For integer / float types, you can do range searches on them e.g.
    Lunar.search(Item, :cost => 300..500, :voting_quotient => 10..20)

    # Or using the pagination gem with this:
    @items = Lunar.search(Item, "iphone")
    paginate @items, :per_page => 10, :page => 1

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lunar-0.3.0 README.md