Commit e6524a919ee4c92d82518c2520d5c0cabc32eb47

Authored by Ilya Baryshev
1 parent db3d90cb

Wiki search

Very basic, using LIKE, and no search snippets.
app/contexts/search_context.rb
@@ -13,6 +13,7 @@ class SearchContext @@ -13,6 +13,7 @@ class SearchContext
13 result[:projects] = Project.where(id: project_ids).search(query).limit(10) 13 result[:projects] = Project.where(id: project_ids).search(query).limit(10)
14 result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10) 14 result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10)
15 result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10) 15 result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10)
  16 + result[:wiki_pages] = Wiki.where(project_id: project_ids).search(query).limit(10)
16 result 17 result
17 end 18 end
18 19
@@ -20,7 +21,8 @@ class SearchContext @@ -20,7 +21,8 @@ class SearchContext
20 @result ||= { 21 @result ||= {
21 projects: [], 22 projects: [],
22 merge_requests: [], 23 merge_requests: [],
23 - issues: [] 24 + issues: [],
  25 + wiki_pages: []
24 } 26 }
25 end 27 end
26 end 28 end
app/controllers/search_controller.rb
@@ -5,5 +5,6 @@ class SearchController < ApplicationController @@ -5,5 +5,6 @@ class SearchController < ApplicationController
5 @projects = result[:projects] 5 @projects = result[:projects]
6 @merge_requests = result[:merge_requests] 6 @merge_requests = result[:merge_requests]
7 @issues = result[:issues] 7 @issues = result[:issues]
  8 + @wiki_pages = result[:wiki_pages]
8 end 9 end
9 end 10 end
app/models/wiki.rb
@@ -15,6 +15,12 @@ class Wiki < ActiveRecord::Base @@ -15,6 +15,12 @@ class Wiki < ActiveRecord::Base
15 slug 15 slug
16 end 16 end
17 17
  18 + class << self
  19 + def search(query)
  20 + where("title like :query OR content like :query", query: "%#{query}%")
  21 + end
  22 + end
  23 +
18 protected 24 protected
19 25
20 def self.regenerate_from wiki 26 def self.regenerate_from wiki
app/views/search/show.html.haml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 %br 9 %br
10 %h3 10 %h3
11 Search results 11 Search results
12 - %small (#{@projects.count + @merge_requests.count + @issues.count}) 12 + %small (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count})
13 %hr 13 %hr
14 .search_results 14 .search_results
15 .row 15 .row
@@ -69,6 +69,23 @@ @@ -69,6 +69,23 @@
69 %tr 69 %tr
70 %td 70 %td
71 %h4.nothing_here_message No Issues 71 %h4.nothing_here_message No Issues
  72 + .span6
  73 + %table
  74 + %thead
  75 + %tr
  76 + %th Wiki
  77 + %tbody
  78 + - @wiki_pages.each do |wiki_page|
  79 + %tr
  80 + %td
  81 + = link_to project_wiki_path(wiki_page.project, wiki_page) do
  82 + %strong.term= truncate wiki_page.title, length: 40
  83 + %strong.right
  84 + %span.label= wiki_page.project.name
  85 + - if @wiki_pages.blank?
  86 + %tr
  87 + %td
  88 + %h4.nothing_here_message No wiki pages
72 :javascript 89 :javascript
73 $(function() { 90 $(function() {
74 $(".search_results .term").highlight("#{params[:search]}"); 91 $(".search_results .term").highlight("#{params[:search]}");
features/dashboard/search.feature
@@ -2,8 +2,13 @@ Feature: Dashboard Search @@ -2,8 +2,13 @@ Feature: Dashboard Search
2 Background: 2 Background:
3 Given I sign in as a user 3 Given I sign in as a user
4 And I own project "Shop" 4 And I own project "Shop"
  5 + And Project "Shop" has wiki page "Contibuting guide"
5 And I visit dashboard search page 6 And I visit dashboard search page
6 7
7 Scenario: I should see project I am looking for 8 Scenario: I should see project I am looking for
8 Given I search for "Sho" 9 Given I search for "Sho"
9 Then I should see "Shop" project link 10 Then I should see "Shop" project link
  11 +
  12 + Scenario: I should see wiki page I am looking for
  13 + Given I search for "Contibuting"
  14 + Then I should see "Contibuting guide" wiki link
10 \ No newline at end of file 15 \ No newline at end of file
features/steps/dashboard/dashboard_search.rb
@@ -15,4 +15,21 @@ class DashboardSearch &lt; Spinach::FeatureSteps @@ -15,4 +15,21 @@ class DashboardSearch &lt; Spinach::FeatureSteps
15 @project = Factory :project, :name => "Shop" 15 @project = Factory :project, :name => "Shop"
16 @project.add_access(@user, :admin) 16 @project.add_access(@user, :admin)
17 end 17 end
  18 +
  19 + Given 'I search for "Contibuting"' do
  20 + fill_in "dashboard_search", :with => "Contibuting"
  21 + click_button "Search"
  22 + end
  23 +
  24 + And 'Project "Shop" has wiki page "Contibuting guide"' do
  25 + @wiki_page = Factory :wiki, :project => @project,
  26 + :title => "Contibuting guide",
  27 + :slug => "contributing"
  28 + end
  29 +
  30 + Then 'I should see "Contibuting guide" wiki link' do
  31 + page.should have_link "Contibuting guide"
  32 + end
  33 +
  34 +
18 end 35 end