Class: Seasyar::ActiveRecordStorage
- Inherits:
-
Object
- Object
- Seasyar::ActiveRecordStorage
- Defined in:
- lib/seasyar/activerecordstorage.rb
Instance Method Summary collapse
-
#name=(name) ⇒ Object
seasy storage implementation ##.
- #remove(deletee) ⇒ Object
- #save(target, weights, options = {}) ⇒ Object
- #search(question) ⇒ Object
Instance Method Details
#name=(name) ⇒ Object
seasy storage implementation ##
9 10 11 |
# File 'lib/seasyar/activerecordstorage.rb', line 9 def name= name @name = name end |
#remove(deletee) ⇒ Object
43 44 45 |
# File 'lib/seasyar/activerecordstorage.rb', line 43 def remove deletee Seasyar::SeasyData.where( source: deletee ).each {|data| data.delete} end |
#save(target, weights, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/seasyar/activerecordstorage.rb', line 13 def save target, weights, = {} raise "source is not set" if [:source].nil? source = [:source] old = SeasyData.where source: source old.each { |data| data.delete } hash_for_create = weights.keys.map do |k| { :key => k, :target => target, :source => source, :weight => weights[k], :index_name => @name } end Seasyar::SeasyData.create hash_for_create end |
#search(question) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/seasyar/activerecordstorage.rb', line 30 def search question # todo : count hits..... query_parts = question.split ' ' # TODO : split on other white spaces? result = {} query_parts.each do |query_part| hits = Seasyar::SeasyData.where key: query_part, index_name: @name hits.each do |one_hit| result[one_hit.target] = one_hit.weight end end result end |