From f06ad7ed8ee4564f31c258567e08b7b00a909493 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 3 Sep 2014 12:15:48 +1000 Subject: [PATCH] remove old unused files --- lib/search.rb | 2 - lib/search/search_result.rb | 93 -------------------------------- lib/search/search_result_type.rb | 31 ----------- 3 files changed, 126 deletions(-) delete mode 100644 lib/search/search_result.rb delete mode 100644 lib/search/search_result_type.rb diff --git a/lib/search.rb b/lib/search.rb index b7854054ce4..c52f7e28e08 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -1,5 +1,3 @@ -require_dependency 'search/search_result' -require_dependency 'search/search_result_type' require_dependency 'search/grouped_search_results' class Search diff --git a/lib/search/search_result.rb b/lib/search/search_result.rb deleted file mode 100644 index f4dd97000c4..00000000000 --- a/lib/search/search_result.rb +++ /dev/null @@ -1,93 +0,0 @@ -require 'sanitize' - -class Search - - class SearchResult - class TextHelper - extend ActionView::Helpers::TextHelper - end - - attr_accessor :type, :id, :topic_id, :blurb, :locked, :pinned - - # Category attributes - attr_accessor :color, :text_color - - # User attributes - attr_accessor :avatar_template, :uploaded_avatar_id - - def initialize(row) - row.symbolize_keys! - @type = row[:type].to_sym - @url, @id, @title, @topic_id, @blurb = row[:url], row[:id], row[:title], row[:topic_id], row[:blurb] - end - - def as_json(options = nil) - json = {id: @id, title: @title, url: @url} - [ :avatar_template, - :uploaded_avatar_id, - :color, - :text_color, - :blurb, - :locked, - :pinned - ].each do |k| - val = send(k) - json[k] = val if val - end - json - end - - def self.from_category(c) - SearchResult.new(type: :category, id: c.id, title: c.name, url: c.url).tap do |r| - r.color = c.color - r.text_color = c.text_color - end - end - - def self.from_user(u) - SearchResult.new( - type: :user, - id: u.username_lower, - title: u.username, - url: "/users/#{u.username_lower}").tap do |r| - r.uploaded_avatar_id = u.uploaded_avatar_id - r.avatar_template = u.avatar_template - end - end - - def self.from_topic(t, options = {}) - SearchResult.new(type: :topic, topic_id: t.id, id: t.id, title: options[:custom_title] || t.title, url: t.relative_url, blurb: options[:custom_blurb]) - end - - def self.blurb(raw, term) - blurb = TextHelper.excerpt(raw, term.split(/\s+/)[0], radius: 100) - blurb = TextHelper.truncate(raw, length: 200) if blurb.blank? - Sanitize.clean(blurb) - end - - def self.from_post(p, context, term, include_blurbs=false) - custom_title = - if context && context.id == p.topic_id - I18n.t("search.within_post", - post_number: p.post_number, - username: p.user && p.user.username - ) - end - if include_blurbs - #add a blurb from the post to the search results - cooked = SearchObserver::HtmlScrubber.scrub(p.cooked).squish - custom_blurb = blurb(cooked, term) - end - if p.post_number == 1 - # we want the topic link when it's the OP - SearchResult.from_topic(p.topic, {custom_title: custom_title, custom_blurb: custom_blurb}) - elsif context && context.id == p.topic_id - SearchResult.new(type: :topic, topic_id: p.topic_id, id: "_#{p.id}", title: custom_title, url: p.url, blurb: custom_blurb) - else - SearchResult.new(type: :topic, topic_id: p.topic_id, id: p.topic.id, title: p.topic.title, url: p.url, blurb: custom_blurb) - end - end - - end - -end diff --git a/lib/search/search_result_type.rb b/lib/search/search_result_type.rb deleted file mode 100644 index a9d4e35e3ab..00000000000 --- a/lib/search/search_result_type.rb +++ /dev/null @@ -1,31 +0,0 @@ -class Search - - class SearchResultType - attr_accessor :more, :results, :result_ids - - def initialize(type) - @type = type - @results = [] - @result_ids = Set.new - @more = false - end - - def size - @results.size - end - - def add(result) - return if @result_ids.include?(result.id) - @results << result - @result_ids << result.id - end - - def as_json(options = nil) - { type: @type.to_s, - name: I18n.t("search.types.#{@type}"), - more: @more, - results: @results.map(&:as_json) } - end - end - -end