mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
UX: move search to its own route
previously search was bundled with discovery, something that makes stuff confusing internally
This commit is contained in:
@ -14,18 +14,19 @@ class Search
|
||||
:more_posts, :more_categories, :more_users,
|
||||
:term, :search_context, :include_blurbs
|
||||
|
||||
def initialize(type_filter, term, search_context, include_blurbs)
|
||||
def initialize(type_filter, term, search_context, include_blurbs, blurb_length)
|
||||
@type_filter = type_filter
|
||||
@term = term
|
||||
@search_context = search_context
|
||||
@include_blurbs = include_blurbs
|
||||
@blurb_length = blurb_length
|
||||
@posts = []
|
||||
@categories = []
|
||||
@users = []
|
||||
end
|
||||
|
||||
def blurb(post)
|
||||
GroupedSearchResults.blurb_for(post.cooked, @term)
|
||||
GroupedSearchResults.blurb_for(post.cooked, @term, @blurb_length)
|
||||
end
|
||||
|
||||
def add(object)
|
||||
@ -39,15 +40,15 @@ class Search
|
||||
end
|
||||
|
||||
|
||||
def self.blurb_for(cooked, term=nil)
|
||||
def self.blurb_for(cooked, term, blurb_length)
|
||||
cooked = SearchObserver::HtmlScrubber.scrub(cooked).squish
|
||||
|
||||
blurb = nil
|
||||
if term
|
||||
terms = term.split(/\s+/)
|
||||
blurb = TextHelper.excerpt(cooked, terms.first, radius: 100)
|
||||
blurb = TextHelper.excerpt(cooked, terms.first, radius: blurb_length / 2, seperator: " ")
|
||||
end
|
||||
blurb = TextHelper.truncate(cooked, length: 200) if blurb.blank?
|
||||
blurb = TextHelper.truncate(cooked, length: blurb_length, seperator: " ") if blurb.blank?
|
||||
Sanitize.clean(blurb)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user