mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
REFACTOR: remove hacky search from discovery
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user