@@ -540,16 +540,24 class ProjectsController < ApplicationController | |||||
540 | end |
|
540 | end | |
541 |
|
541 | |||
542 | def search |
|
542 | def search | |
543 |
@to |
|
543 | @question = params[:q] || "" | |
|
544 | @question.strip! | |||
|
545 | @all_words = params[:all_words] || (params[:submit] ? false : true) | |||
544 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) ) |
|
546 | @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) ) | |
545 |
|
547 | if !@question.empty? | ||
546 | if @token and @token.length > 2 |
|
548 | # tokens must be at least 3 character long | |
547 | @token.strip! |
|
549 | @tokens = @question.split.uniq.select {|w| w.length > 2 } | |
548 | like_token = "%#{@token}%" |
|
550 | # no more than 5 tokens to search for | |
|
551 | @tokens.slice! 5..-1 if @tokens.size > 5 | |||
|
552 | # strings used in sql like statement | |||
|
553 | like_tokens = @tokens.collect {|w| "%#{w}%"} | |||
|
554 | operator = @all_words ? " AND " : " OR " | |||
|
555 | limit = 10 | |||
549 | @results = [] |
|
556 | @results = [] | |
550 |
@results += @project.issues.find(:all, :include => :author, :conditions => ["issues.subject like ? |
|
557 | @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(issues.subject) like ? OR LOWER(issues.description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' | |
551 |
@results += @project.news.find(:all, :conditions => ["news.title like ? |
|
558 | @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(news.title) like ? OR LOWER(news.description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' | |
552 |
@results += @project.documents.find(:all, :conditions => ["title like ? |
|
559 | @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' | |
|
560 | @question = @tokens.join(" ") | |||
553 | end |
|
561 | end | |
554 | end |
|
562 | end | |
555 |
|
563 |
@@ -16,8 +16,14 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module ProjectsHelper |
|
18 | module ProjectsHelper | |
19 | def result_overview(text, token) |
|
19 | ||
20 | match = excerpt(text, token) |
|
20 | def highlight_tokens(text, tokens) | |
21 | match ? highlight(match, token) : truncate(text, 150) |
|
21 | return text unless tokens && !tokens.empty? | |
|
22 | regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE | |||
|
23 | result = '' | |||
|
24 | text.split(regexp).each_with_index do |words, i| | |||
|
25 | result << (i.even? ? (words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words) : content_tag('span', words, :class => 'highlight')) | |||
|
26 | end | |||
|
27 | result | |||
22 | end |
|
28 | end | |
23 | end |
|
29 | end |
@@ -2,10 +2,11 | |||||
2 |
|
2 | |||
3 | <div class="box"> |
|
3 | <div class="box"> | |
4 | <% form_tag({:action => 'search', :id => @project}, :method => :get) do %> |
|
4 | <% form_tag({:action => 'search', :id => @project}, :method => :get) do %> | |
5 |
<p><%= text_field_tag ' |
|
5 | <p><%= text_field_tag 'q', @question, :size => 30 %> | |
6 | <%= check_box_tag 'scope[]', 'issues', (@scope.include? 'issues') %> <label><%= l(:label_issue_plural) %></label> |
|
6 | <%= check_box_tag 'scope[]', 'issues', (@scope.include? 'issues') %> <label><%= l(:label_issue_plural) %></label> | |
7 | <%= check_box_tag 'scope[]', 'news', (@scope.include? 'news') %> <label><%= l(:label_news_plural) %></label> |
|
7 | <%= check_box_tag 'scope[]', 'news', (@scope.include? 'news') %> <label><%= l(:label_news_plural) %></label> | |
8 |
<%= check_box_tag 'scope[]', 'documents', (@scope.include? 'documents') %> <label><%= l(:label_document_plural) %></label></ |
|
8 | <%= check_box_tag 'scope[]', 'documents', (@scope.include? 'documents') %> <label><%= l(:label_document_plural) %></label><br /> | |
|
9 | <%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></p> | |||
9 | <%= submit_tag l(:button_submit), :name => 'submit' %> |
|
10 | <%= submit_tag l(:button_submit), :name => 'submit' %> | |
10 | <% end %> |
|
11 | <% end %> | |
11 | </div> |
|
12 | </div> | |
@@ -16,16 +17,16 | |||||
16 | <% @results.each do |e| %> |
|
17 | <% @results.each do |e| %> | |
17 | <li><p> |
|
18 | <li><p> | |
18 | <% if e.is_a? Issue %> |
|
19 | <% if e.is_a? Issue %> | |
19 | <%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %><br /> |
|
20 | <%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight_tokens(h(e.subject), @tokens) %><br /> | |
20 |
<%= |
|
21 | <%= highlight_tokens(e.description, @tokens) %><br /> | |
21 | <i><%= e.author.name %>, <%= format_time(e.created_on) %></i> |
|
22 | <i><%= e.author.name %>, <%= format_time(e.created_on) %></i> | |
22 | <% elsif e.is_a? News %> |
|
23 | <% elsif e.is_a? News %> | |
23 | <%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %><br /> |
|
24 | <%=l(:label_news)%>: <%= link_to highlight_tokens(h(e.title), @tokens), :controller => 'news', :action => 'show', :id => e %><br /> | |
24 |
<%= |
|
25 | <%= highlight_tokens(e.description, @tokens) %><br /> | |
25 | <i><%= e.author.name %>, <%= format_time(e.created_on) %></i> |
|
26 | <i><%= e.author.name %>, <%= format_time(e.created_on) %></i> | |
26 | <% elsif e.is_a? Document %> |
|
27 | <% elsif e.is_a? Document %> | |
27 | <%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %><br /> |
|
28 | <%=l(:label_document)%>: <%= link_to highlight_tokens(h(e.title), @tokens), :controller => 'documents', :action => 'show', :id => e %><br /> | |
28 |
<%= |
|
29 | <%= highlight_tokens(e.description, @tokens) %><br /> | |
29 | <i><%= format_time(e.created_on) %></i> |
|
30 | <i><%= format_time(e.created_on) %></i> | |
30 | <% end %> |
|
31 | <% end %> | |
31 | </p></li> |
|
32 | </p></li> |
@@ -321,6 +321,7 label_roadmap: Roadmap | |||||
321 | label_search: Suche |
|
321 | label_search: Suche | |
322 | label_result: %d Resultat |
|
322 | label_result: %d Resultat | |
323 | label_result_plural: %d Resultate |
|
323 | label_result_plural: %d Resultate | |
|
324 | label_all_words: Alle Wörter | |||
324 |
|
325 | |||
325 | button_login: Einloggen |
|
326 | button_login: Einloggen | |
326 | button_submit: Einreichen |
|
327 | button_submit: Einreichen |
@@ -321,6 +321,7 label_roadmap: Roadmap | |||||
321 | label_search: Search |
|
321 | label_search: Search | |
322 | label_result: %d result |
|
322 | label_result: %d result | |
323 | label_result_plural: %d results |
|
323 | label_result_plural: %d results | |
|
324 | label_all_words: All words | |||
324 |
|
325 | |||
325 | button_login: Login |
|
326 | button_login: Login | |
326 | button_submit: Submit |
|
327 | button_submit: Submit |
@@ -321,6 +321,7 label_roadmap: Roadmap | |||||
321 | label_search: Búsqueda |
|
321 | label_search: Búsqueda | |
322 | label_result: %d resultado |
|
322 | label_result: %d resultado | |
323 | label_result_plural: %d resultados |
|
323 | label_result_plural: %d resultados | |
|
324 | label_all_words: Todas las palabras | |||
324 |
|
325 | |||
325 | button_login: Conexión |
|
326 | button_login: Conexión | |
326 | button_submit: Someter |
|
327 | button_submit: Someter |
@@ -321,6 +321,7 label_roadmap: Roadmap | |||||
321 | label_search: Recherche |
|
321 | label_search: Recherche | |
322 | label_result: %d résultat |
|
322 | label_result: %d résultat | |
323 | label_result_plural: %d résultats |
|
323 | label_result_plural: %d résultats | |
|
324 | label_all_words: Tous les mots | |||
324 |
|
325 | |||
325 | button_login: Connexion |
|
326 | button_login: Connexion | |
326 | button_submit: Soumettre |
|
327 | button_submit: Soumettre |
@@ -322,6 +322,7 label_roadmap: ロードマップ | |||||
322 | label_search: 検索 |
|
322 | label_search: 検索 | |
323 | label_result: %d 件の結果 |
|
323 | label_result: %d 件の結果 | |
324 | label_result_plural: %d 件の結果 |
|
324 | label_result_plural: %d 件の結果 | |
|
325 | label_all_words: すべての単語 | |||
325 |
|
326 | |||
326 | button_login: ログイン |
|
327 | button_login: ログイン | |
327 | button_submit: 変更 |
|
328 | button_submit: 変更 |
@@ -243,7 +243,7 legend {color: #505050;} | |||||
243 | hr { border:0; border-top: dotted 1px #fff; border-bottom: dotted 1px #c0c0c0; } |
|
243 | hr { border:0; border-top: dotted 1px #fff; border-bottom: dotted 1px #c0c0c0; } | |
244 | table p {margin:0; padding:0;} |
|
244 | table p {margin:0; padding:0;} | |
245 |
|
245 | |||
246 |
|
|
246 | .highlight { background-color: #FCFD8D;} | |
247 |
|
247 | |||
248 | div.square { |
|
248 | div.square { | |
249 | border: 1px solid #999; |
|
249 | border: 1px solid #999; |
General Comments 0
You need to be logged in to leave comments.
Login now