Project

General

Profile

Search in all sub projects by default

Added by André Bachmann about 13 years ago

Given is a Redmine project with several sub projects. If a user wants to search for a keyword, he inputs this in the little search window on the top right. However, the default Redmine behaviour is to search only in exact the same project (without sub projects). I want to change this default behaviour so that it searches by default in the project AND its sub projects - without the longer way to use the extended search menu.

So which file do I have to edit to achieve this?


Replies (6)

RE: Search in all sub projects by default - Added by André Bachmann almost 13 years ago

Ok, I guess I have to edit app/controllers/search_controller.rb to get this working. Line 30 seems to be a candidate:

projects_to_search =
      case params[:scope]
      when 'all'
        nil
      when 'my_projects'
        User.current.memberships.collect(&:project)
      when 'subprojects'
        @project ? (@project.self_and_descendants.active) : nil
      else
        @project
      end

My idea was to change this default behaviour - so that the search looks always in subprojects. But I'm not sure about how to change this. I appreciate any hints...

RE: Search in all sub projects by default - Added by Deoren Moor almost 13 years ago

+1

That would be a great feature. As a workaround, I've kept a link to the main Redmine page on my browser's Bookmark Bar and visit that page before making a search (separate tab).

RE: Search in all sub projects by default - Added by Terence Mill almost 13 years ago

Search settings shall be stored pesistently every time a user changes them.
Also default activites in Actvity view.

RE: Search in all sub projects by default - Added by André Bachmann over 11 years ago

If I change the else statement from @project to nil, it seems that now always the entire Redmine is searched. Not a nice solution, but it would be enough for the time being, I suppose. I will now use this for our productive system.

RE: Search in all sub projects by default - Added by Marc D. about 10 years ago

Just add <input type="hidden" name="scope" value="subprojects" /> in redmine/app/views/layouts/base.html.erb

<div id="header">
    <% if User.current.logged? || !Setting.login_required? %>
    <div id="quick-search">
        <%= form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
        <%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %>
        <%#CHANGE%>
        <input type="hidden" name="scope" value="subprojects" />
        <%#CHANGE_END%>
        <label for='q'>

RE: Search in all sub projects by default - Added by Noah O'Neal almost 8 years ago

Updated code to handle subprojects without bailing on projects without subprojects.
I added to an existing plugin and updated the app/views/layouts/base.html.erb file

<div id="header">
    <% if User.current.logged? || !Setting.login_required? %>
    <div id="quick-search">
        <%= form_tag({:controller => 'search', :action => 'index', :id => @project}, :method => :get ) do %>
        <%= hidden_field_tag(controller.default_search_scope, 1, :id => nil) if controller.default_search_scope %>
        <%#CHANGE%>
        <% unless @project.nil? || @project.descendants.active.empty? %>
        <input type="hidden" name="scope" value="subprojects" />
        <% end %>
        <%#CHANGE%>
        <label for='q'>
          <%= link_to l(:label_search), {:controller => 'search', :action => 'index', :id => @project}, :accesskey => accesskey(:search) %>:
        </label>
        <%= text_field_tag 'q', @question, :size => 20, :class => 'small', :accesskey => accesskey(:quick_search) %>
        <% end %>
        <%= render_project_jump_box %>
    </div>
    <% end %>
    (1-6/6)