lib/wally/search_features.rb in wally-0.0.5 vs lib/wally/search_features.rb in wally-0.0.6

- old
+ new

@@ -1,47 +1,44 @@ +require "komainu" + module Wally class SearchFeatures def initialize lists_features @lists_features = lists_features end def find(query) - results = [] - @lists_features.features.each do |feature| - result = SearchResult.new(feature) + searchables = [] + @lists_features.features.each do |feature| + feature_text = feature["name"] if feature["tags"] - feature["tags"].each do |tag| - if tag["name"].downcase.include? query[:query].downcase - result.matched_feature = feature - end - end + feature_text += " " + feature["tags"].map { |tag| tag["name"] }.join(" ") end + feature_data = OpenStruct.new + feature_data.feature = feature + feature_data.text = feature_text + searchables << feature_data - if feature["name"].downcase.include? query[:query].downcase - result.matched_feature = feature - end - if feature["elements"] - result.matched_scenarios = feature["elements"].select do |element| - if element["name"].downcase.include? query[:query].downcase - true - elsif element["steps"] - element["steps"].any? do |step| - step["name"].downcase.include? query[:query].downcase - end - elsif element["tags"] - element["tags"].any? do |tag| - tag["name"].downcase.include? query[:query].downcase - end + feature["elements"].each do |element| + element_text = [element["name"]] + if element["steps"] + element_text << element["steps"].map { |s| s["name"] } end + if element["tags"] + element_text << element["tags"].map { |t| t["name"] } + end + scenario_data = OpenStruct.new + scenario_data.feature = feature + scenario_data.scenario = element + scenario_data.text = element_text.join(" ") + searchables << scenario_data end end - - if result.matches? - results << result - end end - results + + searches_text = Komainu::SearchesText.new(searchables) + searches_text.search(query[:query]) end end end