]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3790 Remove duplicate resources in search results
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 22 Nov 2012 09:04:23 +0000 (10:04 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 22 Nov 2012 09:04:30 +0000 (10:04 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/search_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/resource_index.rb

index c4946d1f4ea8516e293a6c16f0eabd1f9bc37d53..bbc80bb41f802cf6f6d2a22a689a60359d0665ad 100644 (file)
@@ -17,6 +17,8 @@
 # License along with Sonar; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 #
+require "set"
+
 class SearchController < ApplicationController
 
   SECTION=Navigation::SECTION_HOME
@@ -36,17 +38,18 @@ class SearchController < ApplicationController
                                  :order => 'name_size')
 
     results = select_authorized(:user, results)
+    results = Set.new(results) # do not want the same resource_index to appear many times in the result
     @total = results.size
 
     resource_ids=[]
     @resource_indexes_by_qualifier={}
     results.each do |resource_index|
       qualifier = fix_qualifier(resource_index.qualifier)
-      @resource_indexes_by_qualifier[qualifier]||=[]
-      array=@resource_indexes_by_qualifier[qualifier]
-      if array.size<MAX_RESULTS
-        resource_ids<<resource_index.resource_id
-        array<<resource_index
+      @resource_indexes_by_qualifier[qualifier] ||= []
+      array = @resource_indexes_by_qualifier[qualifier]
+      if array.size < MAX_RESULTS
+        resource_ids << resource_index.resource_id
+        array << resource_index
       end
     end
 
index 934649be8b83ea1dfb5f660919d5d88f9b14c56f..6a3b4770d886fb4601c0b9408a404c9ea682a7c2 100644 (file)
@@ -29,4 +29,13 @@ class ResourceIndex < ActiveRecord::Base
   def resource_id_for_authorization
     root_project_id
   end
+
+  def eql?(another_resource_index)
+    resource_id == another_resource_index.resource_id && root_project_id == another_resource_index.root_project_id
+  end
+
+  def hash
+    [resource_id, root_project_id].hash
+  end
+
 end
\ No newline at end of file