Module: Litesearch::Model::SequelClassMethods

Defined in:
lib/litestack/litesearch/model.rb

Instance Method Summary collapse

Instance Method Details

#create_instance(row) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'lib/litestack/litesearch/model.rb', line 227

def create_instance(row)
  # we need to convert keys to symbols first!
  row.keys.each do |k|
    next if k.is_a? Symbol
    row[k.to_sym] = row[k]
    row.delete(k)
  end
  call(row)
end

#fetch_row(id) ⇒ Object



209
210
211
# File 'lib/litestack/litesearch/model.rb', line 209

def fetch_row(id)
  self[id]
end

#get_connectionObject



213
214
215
# File 'lib/litestack/litesearch/model.rb', line 213

def get_connection
  db.instance_variable_get(:@raw_db)
end

#search(term) ⇒ Object



217
218
219
220
221
222
223
224
225
# File 'lib/litestack/litesearch/model.rb', line 217

def search(term)
  dataset.select(
    Sequel.lit("#{table_name}.*, -#{index_name}.rank AS search_rank")
  ).inner_join(
    Sequel.lit("#{index_name}(:term) ON #{table_name}.id = #{index_name}.rowid AND rank != 0", {term: term})
  ).order(
    Sequel.lit("rank")
  )
end