summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-12-12 20:49:31 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-12-12 20:49:31 +0000
commit2fe806a4a49cc3fcd7c2b7fe3a385d3a46ffbfd5 (patch)
tree82f8da72bfdc6e68c83cbecf3ffac2b5bcc9738a /test
parent963719042a12e7833a95396036a662237a7939a0 (diff)
downloadredmine-2fe806a4a49cc3fcd7c2b7fe3a385d3a46ffbfd5.tar.gz
redmine-2fe806a4a49cc3fcd7c2b7fe3a385d3a46ffbfd5.zip
Rewrites search engine to properly paginate results (#18631).
Instead of counting and retrieving results based on their timestamps, we now load all result ids then load the appropriate results by their ids. This also brings a 2x performance improvement as we search tokens in one of the 2 queries only. git-svn-id: http://svn.redmine.org/redmine/trunk@13739 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/search_controller_test.rb30
-rw-r--r--test/unit/search_test.rb48
2 files changed, 41 insertions, 37 deletions
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 4124985db..24dfa7d6f 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -75,8 +75,8 @@ class SearchControllerTest < ActionController::TestCase
assert_select 'dt.issue a', :text => /Add ingredients categories/
assert_select 'dd', :text => /should be classified by categories/
- assert assigns(:results_by_type).is_a?(Hash)
- assert_equal 5, assigns(:results_by_type)['changesets']
+ assert assigns(:result_count_by_type).is_a?(Hash)
+ assert_equal 5, assigns(:result_count_by_type)['changesets']
assert_select 'a', :text => 'Changesets (5)'
end
@@ -222,20 +222,24 @@ class SearchControllerTest < ActionController::TestCase
assert_equal 1, results.size
end
- def test_search_with_offset
- get :index, :q => 'coo', :offset => '20080806073000'
+ def test_search_with_pagination
+ issue = (0..24).map {Issue.generate! :subject => 'search_with_limited_results'}.reverse
+
+ get :index, :q => 'search_with_limited_results'
assert_response :success
- results = assigns(:results)
- assert results.any?
- assert results.map(&:event_datetime).max < '20080806T073000'.to_time
- end
+ assert_equal issue[0..9], assigns(:results)
- def test_search_previous_with_offset
- get :index, :q => 'coo', :offset => '20080806073000', :previous => '1'
+ get :index, :q => 'search_with_limited_results', :page => 2
assert_response :success
- results = assigns(:results)
- assert results.any?
- assert results.map(&:event_datetime).min >= '20080806T073000'.to_time
+ assert_equal issue[10..19], assigns(:results)
+
+ get :index, :q => 'search_with_limited_results', :page => 3
+ assert_response :success
+ assert_equal issue[20..24], assigns(:results)
+
+ get :index, :q => 'search_with_limited_results', :page => 4
+ assert_response :success
+ assert_equal [], assigns(:results)
end
def test_search_with_invalid_project_id
diff --git a/test/unit/search_test.rb b/test/unit/search_test.rb
index 5a10ec71c..c98982e8a 100644
--- a/test/unit/search_test.rb
+++ b/test/unit/search_test.rb
@@ -42,25 +42,25 @@ class SearchTest < ActiveSupport::TestCase
def test_search_by_anonymous
User.current = nil
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert r.include?(@changeset)
# Removes the :view_changesets permission from Anonymous role
remove_permission Role.anonymous, :view_changesets
User.current = nil
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert !r.include?(@changeset)
# Make the project private
@project.update_attribute :is_public, false
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert !r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert !r.include?(@changeset)
end
@@ -68,25 +68,25 @@ class SearchTest < ActiveSupport::TestCase
User.current = User.find_by_login('rhill')
assert User.current.memberships.empty?
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert r.include?(@changeset)
# Removes the :view_changesets permission from Non member role
remove_permission Role.non_member, :view_changesets
User.current = User.find_by_login('rhill')
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert !r.include?(@changeset)
# Make the project private
@project.update_attribute :is_public, false
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert !r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert !r.include?(@changeset)
end
@@ -94,16 +94,16 @@ class SearchTest < ActiveSupport::TestCase
User.current = User.find_by_login('jsmith')
assert User.current.projects.include?(@project)
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert r.include?(@changeset)
# Make the project private
@project.update_attribute :is_public, false
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert r.include?(@changeset)
end
@@ -115,26 +115,26 @@ class SearchTest < ActiveSupport::TestCase
User.current = User.find_by_login('jsmith')
assert User.current.projects.include?(@project)
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert !r.include?(@changeset)
# Make the project private
@project.update_attribute :is_public, false
- r = Issue.search(@issue_keyword).first
+ r = Issue.search_results(@issue_keyword)
assert r.include?(@issue)
- r = Changeset.search(@changeset_keyword).first
+ r = Changeset.search_results(@changeset_keyword)
assert !r.include?(@changeset)
end
def test_search_issue_with_multiple_hits_in_journals
- i = Issue.find(1)
- assert_equal 2, i.journals.where("notes LIKE '%notes%'").count
+ issue = Issue.find(1)
+ assert_equal 2, issue.journals.where("notes LIKE '%notes%'").count
- r = Issue.search('%notes%').first
+ r = Issue.search_results('%notes%')
assert_equal 1, r.size
- assert_equal i, r.first
+ assert_equal issue, r.first
end
private