Search
This commit is contained in:
parent
22a8ebb86d
commit
a0303d1eea
|
@ -103,8 +103,12 @@ class WikiController < ApplicationController
|
|||
|
||||
def search
|
||||
@query = @params['query']
|
||||
@title_results = @web.select { |page| page.name =~ /#{@query}/i }.sort
|
||||
@results = @web.select { |page| page.content =~ /#{@query}/i }.sort
|
||||
redirect_show(@results.first.name) if @results.length == 1
|
||||
all_pages_found = (@results + @title_results).uniq
|
||||
if all_pages_found.size == 1
|
||||
redirect_show(all_pages_found.first.name)
|
||||
end
|
||||
end
|
||||
|
||||
# Within a single page --------------------------------------------------------
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
<% @title = @results.length > 0 ? "#{@results.length} pages contains \"#{@params["query"]}\"" : "No pages contains \"#{@query}\"" %>
|
||||
<% @title = "Search results for \"#{@params["query"]}\"" %>
|
||||
|
||||
<% if @results.length > 0 %>
|
||||
<% unless @title_results.empty? %>
|
||||
<h2><%= @title_results.length %> page(s) containing search string in the page name:</h2>
|
||||
<ul>
|
||||
<% for page in @title_results %>
|
||||
<li><a href="../show/<%= page.name %>"><%= page.plain_name %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
|
||||
<% unless @results.empty? %>
|
||||
<h2> <%= @results.length %> page(s) containing search string in the page text:</h2>
|
||||
<ul>
|
||||
<% for page in @results %>
|
||||
<li><a href="../show/<%= page.name %>"><%= page.plain_name %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<p>Perhaps you should try expanding your query. Remember that Instiki searches for entire phrases, so if you search for "all that jazz" it will not match pages that contain these words in separation—only as a sentence fragment.</p>
|
||||
|
||||
<p>If you're a high-tech computer wizard, you might even want try constructing a regular expression. That's actually what Instiki uses, so go right ahead and flex your "[a-z]*Leet?RegExpSkill(s|z)"</p>
|
||||
<% end %>
|
||||
|
||||
<% if (@results + @title_results).empty? %>
|
||||
<h2>No pages contains "<%= @params["query"] %>" </h2>
|
||||
<p>
|
||||
Perhaps you should try expanding your query. Remember that Instiki searches for entire
|
||||
phrases, so if you search for "all that jazz" it will not match pages that contain these
|
||||
words in separation—only as a sentence fragment.
|
||||
</p>
|
||||
<p>
|
||||
If you're a high-tech computer wizard, you might even want try constructing a Ruby regular
|
||||
expression. That's actually what Instiki uses, so go right ahead and flex your
|
||||
"[a-z]*Leet?RegExpSkill(s|z)"
|
||||
</p>
|
||||
<% end %>
|
||||
|
|
|
@ -477,7 +477,9 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
def test_search
|
||||
setup_wiki_with_three_pages
|
||||
process 'search', 'web' => 'wiki1', 'query' => '\s[A-Z]ak'
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '\s[A-Z]ak'
|
||||
|
||||
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||
end
|
||||
|
||||
|
@ -489,6 +491,18 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
assert_success
|
||||
assert_equal 'All about', r.template_objects['query']
|
||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_search_by_content_and_title
|
||||
setup_wiki_with_three_pages
|
||||
|
||||
r = process 'search', 'web' => 'wiki1', 'query' => '(Oak|Elephant)'
|
||||
|
||||
assert_success
|
||||
assert_equal '(Oak|Elephant)', r.template_objects['query']
|
||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
||||
assert_equal [@elephant, @oak], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
def test_search_zero_results
|
||||
|
@ -498,9 +512,12 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
assert_success
|
||||
assert_equal [], r.template_objects['results']
|
||||
assert_equal [], r.template_objects['title_results']
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def test_show_page
|
||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||
assert_success
|
||||
|
|
Loading…
Reference in a new issue