lib/makit/indexer.rb in makit-0.0.36 vs lib/makit/indexer.rb in makit-0.0.37

- old
+ new

@@ -7,21 +7,21 @@ class Indexer attr_accessor :keywords_index # Hash of string key to string[] of keyword attr_accessor :protoc_json_serializer def initialize - @keywords_index=Hash.new + @keywords_index = Hash.new @protoc_json_serializer = Makit::Serializer::new(Makit::Proto3Formats::JSON) end def index(key, item) # item must be serializable to json keywords = [] hash = JSON.parse(item.to_json) hash.each do |key, value| value = value.to_s.downcase - if(value.length >= 3 && !keywords.include?(value)) + if (value.length >= 3 && !keywords.include?(value)) keywords << value end end keywords.each do |keyword| if !@keywords_index.key?(keyword) @@ -32,25 +32,25 @@ end def search(query) keys = [] # todo, remove terms less that length of 3 - terms = query.downcase.split(' ').reject { |term| term.length < 3 } - keywords_index.each do |key,value|#{|kvp| - if(get_match_count(terms,value) == terms.length) - keys << key + terms = query.downcase.split(" ").reject { |term| term.length < 3 } + keywords_index.each do |key, value| #{|kvp| + if (get_match_count(terms, value) == terms.length) + keys << key end end keys end - def get_match_count(terms,keywords) - match_count = 0 - terms.each{ |term| - if(keywords.include?(term)) - match_count +=1 - end - } - return match_count + def get_match_count(terms, keywords) + match_count = 0 + terms.each { |term| + if (keywords.include?(term)) + match_count += 1 + end + } + return match_count end end # class Indexer end # module Makit