remove old unused files
This commit is contained in:
parent
921dd75dd9
commit
f06ad7ed8e
|
@ -1,5 +1,3 @@
|
|||
require_dependency 'search/search_result'
|
||||
require_dependency 'search/search_result_type'
|
||||
require_dependency 'search/grouped_search_results'
|
||||
|
||||
class Search
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue