REFACTOR: remove hacky search from discovery

This commit is contained in:
Sam
2015-07-27 16:46:50 +10:00
parent 41ceff8430
commit 2876725e1b
17 changed files with 17 additions and 159 deletions

View File

@@ -61,7 +61,7 @@ module Discourse
class CSRF < StandardError; end
def self.filters
@filters ||= [:latest, :unread, :new, :read, :posted, :bookmarks, :search]
@filters ||= [:latest, :unread, :new, :read, :posted, :bookmarks]
end
def self.feed_filters
@@ -69,7 +69,7 @@ module Discourse
end
def self.anonymous_filters
@anonymous_filters ||= [:latest, :top, :categories, :search]
@anonymous_filters ||= [:latest, :top, :categories]
end
def self.logged_in_filters

View File

@@ -19,7 +19,7 @@ class Search
@term = term
@search_context = search_context
@include_blurbs = include_blurbs
@blurb_length = blurb_length
@blurb_length = blurb_length || 200
@posts = []
@categories = []
@users = []
@@ -40,7 +40,7 @@ class Search
end
def self.blurb_for(cooked, term, blurb_length)
def self.blurb_for(cooked, term=nil, blurb_length=200)
cooked = SearchObserver::HtmlScrubber.scrub(cooked).squish
blurb = nil

View File

@@ -71,53 +71,6 @@ class TopicQuery
create_list(:latest, {}, latest_results)
end
def list_search
results = nil
if @options[:q].present?
search = Search.execute(@options[:q],
type_filter: 'topic',
guardian: Guardian.new(@user))
topic_ids = search.posts.map(&:topic_id)
if topic_ids.present?
sql = topic_ids.each_with_index.map do |id, idx|
"SELECT #{idx} pos, #{id} id"
end.join(" UNION ALL ")
results = Topic
.unscoped
.joins("JOIN (#{sql}) X on X.id = topics.id")
.order("X.pos")
posts_map = {}
search.posts.each do |p|
(posts_map[p.topic_id] ||= []) << p
end
end
end
results ||= Topic.where("1=0")
if @user
results = results.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{@user.id.to_i})")
.references('tu')
end
list = create_list(:search, {unordered: true}, results)
list.topics.each do |topic|
if posts = posts_map[topic.id]
if post = posts.shift
topic.search_data = {excerpt: search.blurb(post), post_number: post.post_number}
end
end
end
list
end
def list_read
create_list(:read, unordered: true) do |topics|
topics.order('COALESCE(tu.last_visited_at, topics.bumped_at) DESC')