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