diff options
-rw-r--r-- | app/models/public_body.rb | 4 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index ed30585e4..2c13d1bf3 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -139,7 +139,9 @@ class PublicBody < ActiveRecord::Base :values => [ [ :created_at_numeric, 1, "created_at", :number ] # for sorting ], - :terms => [ [ :variety, 'V', "variety" ] ] + :terms => [ [ :variety, 'V', "variety" ], + [ :tag_array_for_search, 'U', "tag" ] + ] def created_at_numeric # format it here as no datetime support in Xapian's value ranges return self.created_at.strftime("%Y%m%d%H%M%S") diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 2ed8e9277..cc319c2d7 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -289,6 +289,30 @@ describe InfoRequest, " when indexing requests by tag" do end end +describe PublicBody, " when indexing authorities by tag" do + fixtures :public_bodies, :incoming_messages, :outgoing_messages, :raw_emails, :comments + + it "should find request by tag, even when changes" do + rebuild_xapian_index + body = public_bodies(:geraldine_public_body) + body.tag_string = 'mice:3' + body.save! + update_xapian_index + + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object.results[0][:model] == public_bodies(:geraldine_public_body) + + xapian_object = InfoRequest.full_search([PublicBody], "tag:mice:3", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 1 + xapian_object.results[0][:model] == public_bodies(:geraldine_public_body) + + xapian_object = InfoRequest.full_search([PublicBody], "tag:orangeaardvark", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + end +end + + |