Wiki search

Very basic, using LIKE, and no search snippets.
This commit is contained in:
Ilya Baryshev 2012-10-16 23:05:11 +04:00
parent db3d90cbcb
commit e6524a919e
6 changed files with 50 additions and 2 deletions

View file

@ -13,6 +13,7 @@ class SearchContext
result[:projects] = Project.where(id: project_ids).search(query).limit(10)
result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10)
result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10)
result[:wiki_pages] = Wiki.where(project_id: project_ids).search(query).limit(10)
result
end
@ -20,7 +21,8 @@ class SearchContext
@result ||= {
projects: [],
merge_requests: [],
issues: []
issues: [],
wiki_pages: []
}
end
end

View file

@ -5,5 +5,6 @@ class SearchController < ApplicationController
@projects = result[:projects]
@merge_requests = result[:merge_requests]
@issues = result[:issues]
@wiki_pages = result[:wiki_pages]
end
end

View file

@ -15,6 +15,12 @@ class Wiki < ActiveRecord::Base
slug
end
class << self
def search(query)
where("title like :query OR content like :query", query: "%#{query}%")
end
end
protected
def self.regenerate_from wiki

View file

@ -9,7 +9,7 @@
%br
%h3
Search results
%small (#{@projects.count + @merge_requests.count + @issues.count})
%small (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count})
%hr
.search_results
.row
@ -69,6 +69,23 @@
%tr
%td
%h4.nothing_here_message No Issues
.span6
%table
%thead
%tr
%th Wiki
%tbody
- @wiki_pages.each do |wiki_page|
%tr
%td
= link_to project_wiki_path(wiki_page.project, wiki_page) do
%strong.term= truncate wiki_page.title, length: 40
%strong.right
%span.label= wiki_page.project.name
- if @wiki_pages.blank?
%tr
%td
%h4.nothing_here_message No wiki pages
:javascript
$(function() {
$(".search_results .term").highlight("#{params[:search]}");