Sha256: a79ac7726e6d7f9cccf9c696df69fc181f32fdc29a23b715271203b9099e3bd0

Contents?: true

Size: 1.3 KB

Versions: 19

Compression:

Stored size: 1.3 KB

Contents

class SearchController < ApplicationController
  def mentions
    q = params[:query]
    delimiter = params[:delimiter]
    search_group = "spaces,pages,projects,bugs,tasks,stories,users,attachments"

    if delimiter == "!"
      search_group = "attachments"
    end

    query = Tire.search(search_group) do
      query do
        boolean do
          should { string "title:#{q}*" }
          should { string "filename:#{q}*" }
          should { string "name:#{q}*" }
          should { string "email:#{q}*" }
        end
      end
    end

    render json: query.results.map{|result| process_result(result) }
  end

  protected

  #TODO: dirty. fix.
  def process_result(result)
    json = {}
    json[:type] = result._type
    if ["space", "page"].include?(result._type)
      json[:name] = result.title
      json[:url] = wiki_page_url(result.id)
      json[:space] = result.load.root.title
    elsif ["project", "bug", "task", "story"].include?(result._type)
      json[:name] = result.title
      json[:url] = ticket_url(result.id)
      json[:project] = result.load.root.title
    elsif result._type == "attachment"
      json[:name] = result.filename
      json[:url] = attachment_url(result.id)
    elsif result._type == "user"
      json[:name] = result.name
      json[:email] = result.email
    end

    json
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
tawork-0.0.19 app/controllers/search_controller.rb
tawork-0.0.18 app/controllers/search_controller.rb
tawork-0.0.17 app/controllers/search_controller.rb
tawork-0.0.16 app/controllers/search_controller.rb
tawork-0.0.15 app/controllers/search_controller.rb
tawork-0.0.14 app/controllers/search_controller.rb
tawork-0.0.13 app/controllers/search_controller.rb
tawork-0.0.12 app/controllers/search_controller.rb
tawork-0.0.11 app/controllers/search_controller.rb
tawork-0.0.10 app/controllers/search_controller.rb
tawork-0.0.9 app/controllers/search_controller.rb
tawork-0.0.8 app/controllers/search_controller.rb
tawork-0.0.7 app/controllers/search_controller.rb
tawork-0.0.6 app/controllers/search_controller.rb
tawork-0.0.5 app/controllers/search_controller.rb
tawork-0.0.4 app/controllers/search_controller.rb
tawork-0.0.3 app/controllers/search_controller.rb
tawork-0.0.2 app/controllers/search_controller.rb
tawork-0.0.1 app/controllers/search_controller.rb