Sha256: 71706c0afcf9f5a29a740a1bd0fcce5210bfb21c6b6ded9548473e328c0d7375
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
class SearchController < ApplicationController def index q = params[:term] @searcher = Searcher.search query: q render layout: false end def mentions q = params[:query] delimiter = params[:delimiter] search_group = "pages,attachments" if delimiter == "!" search_group = "attachments" end q = ["title:#{q}*", "filename:#{q}*", "name:#{q}*", "email:#{q}*"].join(" OR ") @searcher = Searcher.search q: q, search_group: search_group results = [] @searcher.results_with_hits{|result, hit| results << process_result(result, hit) } render json: results end protected #TODO: dirty. fix. def process_result(result, hit) json = {} json[:type] = result.class.to_s.underscore if ["space", "page"].include?(hit._type) json[:name] = result.title json[:url] = wiki_page_url(result.id) json[:space] = result.root.title if json[:type] == "space" json[:icon] = "fa-bullseye" else json[:icon] = "fa-file" end elsif ["project", "bug", "task", "story"].include?(hit._type) json[:name] = result.title json[:url] = ticket_url(result.id) json[:project] = result.root.title elsif hit._type == "attachment" json[:name] = result.filename json[:url] = attachment_url(result.id) json[:icon] = "fa-paperclip" elsif hit._type == "user" json[:name] = result.name json[:email] = result.email end json end end
Version data entries
5 entries across 5 versions & 1 rubygems