diff options
Diffstat (limited to 'spec/models/xapian_spec.rb')
-rw-r--r-- | spec/models/xapian_spec.rb | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 932966dfb..cf9ea5fbd 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -12,9 +12,10 @@ describe User, " when indexing users with Xapian" do end it "should search by 'about me' text" do + rebuild_xapian_index user = users(:bob_smith_user) - # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) + # def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) xapian_object = InfoRequest.full_search([User], "stuff", 'created_at', true, nil, 100, 1) xapian_object.results.size.should == 1 xapian_object.results[0][:model].should == user @@ -332,6 +333,66 @@ describe PublicBody, " when indexing authorities by tag" do end end +describe PublicBody, " when only indexing selected things on a rebuild" do + fixtures :public_bodies, :public_body_translations, :public_body_versions, :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things + before(:each) do + load_raw_emails_data(raw_emails) + end + + it "should only index what we ask it to" do + rebuild_xapian_index + body = public_bodies(:geraldine_public_body) + body.tag_string = 'mice:3' + body.name = 'frobzn' + body.save! + # only reindex 'variety' term + dropfirst = true + terms = "V" + values = false + texts = false + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + # only reindex 'tag' and text + dropfirst = true + terms = "U" + values = false + texts = true + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + # only reindex 'variety' term, but keeping the existing data in-place + dropfirst = false + terms = "V" + texts = false + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + # only reindex 'variety' term, blowing away existing data + dropfirst = true + rebuild_xapian_index(terms, values, texts, dropfirst) + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "frobzn", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([PublicBody], "variety:authority", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 2 + end +end + + |