Search
This commit is contained in:
parent
22a8ebb86d
commit
a0303d1eea
|
@ -103,8 +103,12 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
def search
|
def search
|
||||||
@query = @params['query']
|
@query = @params['query']
|
||||||
|
@title_results = @web.select { |page| page.name =~ /#{@query}/i }.sort
|
||||||
@results = @web.select { |page| page.content =~ /#{@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
|
end
|
||||||
|
|
||||||
# Within a single page --------------------------------------------------------
|
# 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>
|
<ul>
|
||||||
<% for page in @results %>
|
<% for page in @results %>
|
||||||
<li><a href="../show/<%= page.name %>"><%= page.plain_name %></a></li>
|
<li><a href="../show/<%= page.name %>"><%= page.plain_name %></a></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% else %>
|
<% end %>
|
||||||
<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>
|
|
||||||
|
<% if (@results + @title_results).empty? %>
|
||||||
<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>
|
<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 %>
|
<% end %>
|
||||||
|
|
|
@ -477,7 +477,9 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_search
|
def test_search
|
||||||
setup_wiki_with_three_pages
|
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'
|
assert_redirected_to :action => 'show', :id => 'Oak'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -489,6 +491,18 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
assert_success
|
assert_success
|
||||||
assert_equal 'All about', r.template_objects['query']
|
assert_equal 'All about', r.template_objects['query']
|
||||||
assert_equal [@elephant, @oak], r.template_objects['results']
|
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
|
end
|
||||||
|
|
||||||
def test_search_zero_results
|
def test_search_zero_results
|
||||||
|
@ -498,9 +512,12 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
assert_equal [], r.template_objects['results']
|
assert_equal [], r.template_objects['results']
|
||||||
|
assert_equal [], r.template_objects['title_results']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_show_page
|
def test_show_page
|
||||||
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
r = process('show', 'id' => 'HomePage', 'web' => 'wiki1')
|
||||||
assert_success
|
assert_success
|
||||||
|
|
Loading…
Reference in a new issue