mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Merge pull request #4981 from dmacjam/fix_limited_search_results
FIX: limited search results
This commit is contained in:
@ -155,8 +155,8 @@ class Search
|
||||
@search_context = @opts[:search_context]
|
||||
@include_blurbs = @opts[:include_blurbs] || false
|
||||
@blurb_length = @opts[:blurb_length]
|
||||
@limit = Search.per_facet
|
||||
@valid = true
|
||||
@page = @opts[:page]
|
||||
|
||||
# Removes any zero-width characters from search terms
|
||||
term.to_s.gsub!(/[\u200B-\u200D\uFEFF]/, '')
|
||||
@ -174,10 +174,6 @@ class Search
|
||||
@search_context = @guardian.user
|
||||
end
|
||||
|
||||
if @opts[:type_filter].present?
|
||||
@limit = Search.per_filter
|
||||
end
|
||||
|
||||
@results = GroupedSearchResults.new(
|
||||
@opts[:type_filter],
|
||||
clean_term,
|
||||
@ -187,6 +183,22 @@ class Search
|
||||
)
|
||||
end
|
||||
|
||||
def limit
|
||||
if @opts[:type_filter].present?
|
||||
Search.per_filter + 1
|
||||
else
|
||||
Search.per_facet + 1
|
||||
end
|
||||
end
|
||||
|
||||
def offset
|
||||
if @page && @opts[:type_filter].present?
|
||||
(@page - 1) * Search.per_filter
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
@valid
|
||||
end
|
||||
@ -557,7 +569,6 @@ class Search
|
||||
raise Discourse::InvalidAccess.new("invalid type filter") unless Search.facets.include?(@results.type_filter)
|
||||
send("#{@results.type_filter}_search")
|
||||
else
|
||||
@limit = Search.per_facet + 1
|
||||
unless @search_context
|
||||
user_search if @term.present?
|
||||
category_search if @term.present?
|
||||
@ -753,6 +764,7 @@ class Search
|
||||
posts = posts.where("(categories.id IS NULL) OR (NOT categories.read_restricted)").references(:categories)
|
||||
end
|
||||
|
||||
posts = posts.offset(offset)
|
||||
posts.limit(limit)
|
||||
end
|
||||
|
||||
@ -795,10 +807,10 @@ class Search
|
||||
query =
|
||||
if @order == :likes
|
||||
# likes are a pain to aggregate so skip
|
||||
posts_query(@limit, private_messages: opts[:private_messages])
|
||||
posts_query(limit, private_messages: opts[:private_messages])
|
||||
.select('topics.id', "posts.post_number")
|
||||
else
|
||||
posts_query(@limit, aggregate_search: true, private_messages: opts[:private_messages])
|
||||
posts_query(limit, aggregate_search: true, private_messages: opts[:private_messages])
|
||||
.select('topics.id', "#{min_or_max}(posts.post_number) post_number")
|
||||
.group('topics.id')
|
||||
end
|
||||
@ -846,7 +858,7 @@ class Search
|
||||
|
||||
def topic_search
|
||||
if @search_context.is_a?(Topic)
|
||||
posts = posts_eager_loads(posts_query(@limit))
|
||||
posts = posts_eager_loads(posts_query(limit))
|
||||
.where('posts.topic_id = ?', @search_context.id)
|
||||
|
||||
posts.each do |post|
|
||||
|
Reference in New Issue
Block a user