UX: move search to its own route

previously search was bundled with discovery, something that makes stuff confusing internally
This commit is contained in:
Sam
2015-07-27 16:13:11 +10:00
parent 68a262ff08
commit 41ceff8430
13 changed files with 244 additions and 63 deletions

View File

@ -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