diff options
-rw-r--r-- | app/models/info_request.rb | 2 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 67 | ||||
-rw-r--r-- | spec/spec_helper.rb | 7 | ||||
-rw-r--r-- | vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb | 6 |
5 files changed, 60 insertions, 25 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 7cee3fe1c..8e2c25879 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -132,7 +132,7 @@ class InfoRequest < ActiveRecord::Base # we update index for every event. Also reindex if prominence changes. after_update :reindex_some_request_events def reindex_some_request_events - if self.changes.include?('url_title') || self.changes.include?('prominence') + if self.changes.include?('url_title') || self.changes.include?('prominence') || self.changes.include?('user_id') self.reindex_request_events end end diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index b16ced344..c55407371 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -110,12 +110,11 @@ describe InfoRequest do it "should cope with indexing after item is deleted" do rebuild_xapian_index - verbose = false # delete event from underneath indexing; shouldn't cause error info_request_events(:useless_incoming_message_event).save! info_request_events(:useless_incoming_message_event).destroy - ActsAsXapian.update_index(true, verbose) + update_xapian_index end end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index b0c122f50..bfa8c8470 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -3,17 +3,13 @@ require File.dirname(__FILE__) + '/../spec_helper' describe User, " when indexing users with Xapian" do fixtures :users - before(:all) do - rebuild_xapian_index - end - it "should search by name" do + rebuild_xapian_index # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([User], "Silly", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == users(:silly_name_user) end - end describe PublicBody, " when indexing public bodies with Xapian" do @@ -47,8 +43,6 @@ describe PublicBody, " when indexing requests by body they are to" do end it "should update index correctly when URL name of body changes" do - verbose = false - # initial search rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) @@ -60,7 +54,7 @@ describe PublicBody, " when indexing requests by body they are to" do body.short_name = 'GQ' body.save! body.url_name.should == 'gq' - ActsAsXapian.update_index(true, verbose) # true = flush to disk + update_xapian_index # check we get results expected xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) @@ -82,9 +76,52 @@ describe User, " when indexing requests by user they are from" do xapian_object.results.size.should == 4 end - it "should update index correctly when URL name of user changes" do - verbose = false + it "should find just the sent message events from a particular user" do + rebuild_xapian_index + # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + xapian_object.results[1][:model].should == info_request_events(:useless_outgoing_message_event) + xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event) + end + + it "should not find it when one of the request's users is changed" do + rebuild_xapian_index + silly_user = users(:silly_name_user) + naughty_chicken_request = info_requests(:naughty_chicken_request) + naughty_chicken_request.user = silly_user + naughty_chicken_request.save! + + update_xapian_index + # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith variety:sent", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object.results[0][:model].should == info_request_events(:useless_outgoing_message_event) + end + + it "should not find it when one of the request's users is changed to a name which is a substring of the other request" do + rebuild_xapian_index + silly_user = users(:silly_name_user) + + silly_user.name = "Bob S" + silly_user.url_name.should == 'bob_s' + silly_user.save! + + naughty_chicken_request = info_requests(:naughty_chicken_request) + naughty_chicken_request.user = silly_user + naughty_chicken_request.save! + + update_xapian_index + + # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_s variety:sent", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event) + end + + + it "should update index correctly when URL name of user changes" do # initial search rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) @@ -96,7 +133,7 @@ describe User, " when indexing requests by user they are from" do u.name = 'Robert Smith' u.save! u.url_name.should == 'robert_smith' - ActsAsXapian.update_index(flush_to_disk=true, verbose) + update_xapian_index # check we get results expected xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_smith", 'created_at', true, nil, 100, 1) @@ -119,8 +156,6 @@ describe User, " when indexing comments by user they are by" do end it "should update index correctly when URL name of user changes" do - verbose = false - # initial search rebuild_xapian_index xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1) @@ -132,7 +167,7 @@ describe User, " when indexing comments by user they are by" do u.name = 'Silly Name' u.save! u.url_name.should == 'silly_name' - ActsAsXapian.update_index(true, verbose) # true = flush to disk + update_xapian_index # check we get results expected xapian_object = InfoRequest.full_search([InfoRequestEvent], "commented_by:silly_emnameem", 'created_at', true, nil, 100, 1) @@ -156,15 +191,13 @@ describe InfoRequest, " when indexing requests by their title" do end it "should update index correctly when URL title of request changes" do - verbose = false - # change the URL name of the body rebuild_xapian_index ir = info_requests(:naughty_chicken_request) ir.title = 'Really naughty' ir.save! ir.url_title.should == 'really_naughty' - ActsAsXapian.update_index(true, verbose) # true = flush to disk + update_xapian_index # check we get results expected xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2b1fbac53..72457815a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,13 +38,16 @@ def load_file_fixture(file_name) end def rebuild_xapian_index + # XXX could for speed call ActsAsXapian.rebuild_index directly, but would + # need model name list, and would need to fix acts_as_xapian so can call writes + # and reads mixed up (it asserts where it thinks it can't do this) rebuild_name = File.dirname(__FILE__) + '/../script/rebuild-xapian-index' Kernel.system(rebuild_name) or raise "failed to launch #{rebuild_name}, error bitcode #{$?}, exit status: #{$?.exitstatus}" end def update_xapian_index - update_name = File.dirname(__FILE__) + '/../script/update-xapian-index' - Kernel.system(update_name) or raise "failed to launch #{update_name}, error bitcode #{$?}, exit status: #{$?.exitstatus}" + verbose = false + ActsAsXapian.update_index(flush_to_disk=true, verbose) end # Validate an entire HTML page diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb index 941a59735..0d0605cd3 100644 --- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb +++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb @@ -507,10 +507,10 @@ module ActsAsXapian class ActsAsXapianJob < ActiveRecord::Base end - # Update index with any changes needed, call this offline. Only call it + # Update index with any changes needed, call this offline. Usually call it # from a script that exits - otherwise Xapian's writable database won't - # flush your changes. Specifying flush will reduce performance, but - # make sure that each index update is definitely saved to disk before + # flush your changes. Specifying flush will reduce performance, but make + # sure that each index update is definitely saved to disk before # logging in the database that it has been. def ActsAsXapian.update_index(flush = false, verbose = false) # STDOUT.puts("start of ActsAsXapian.update_index") if verbose |