Sha256: 7cd8db70ebca848f4fd45d3cfa64636f67bea6738b0eba09791981b38ef34bcc

Contents?: true

Size: 699 Bytes

Versions: 4

Compression:

Stored size: 699 Bytes

Contents

module Seasyar
  require 'seasy'
  
  def index index_name, *fields
    index = Seasy::Index.with_name index_name.to_s
    
    value = ''
    fields.each do |one_field|
      value << " #{self.send one_field }"
    end
    
    target = self.id
    source = "#{self.class}:#{target}"

    if block_given?
      target = yield self
    end
    index.add value.to_s, target.to_s, :source => source
  end  
  
  def search index_name, query
    index = Seasy::Index.with_name index_name.to_s
    index.search query
  end
  
  def unindex index_name
    index = Seasy::Index.with_name index_name.to_s
    index.remove "#{self.class}:#{self.id}"
  end
  
  module_function :index, :search, :unindex
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
seasyar-0.0.11 lib/seasyar/seasyar.rb
seasyar-0.0.10 lib/seasyar/seasyar.rb
seasyar-0.0.9 lib/seasyar/seasyar.rb
seasyar-0.0.8 lib/seasyar/seasyar.rb