Skip to content

Commit

Permalink
Add ability to search for requests made to tagged public bodies
Browse files Browse the repository at this point in the history
In aea54a4 we copied the suggested way this search could work from #24
but in implementing it I realised that having
"tag:some_tag variety:sent" makes it ambiguous what the tag is on - the
request or the body?

So in this commit I've decided to create a new term for public body tags
on info_request_events in the same way that the tags from the
info_request is exposed.

To search for request with a particular public body tag, you use
"request_public_body_tag". It's a bit verbose but I think clarity is far
more important than brevity here.

Also adds documentation about request_public_body_tag to advanced search page.

Fixes #24.
  • Loading branch information
henare authored and garethrees committed Sep 15, 2016
1 parent eef48cb commit 265087e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/info_request_event.rb
Expand Up @@ -98,7 +98,8 @@ def must_be_valid_state
[ :latest_status, 'L', "latest_status" ],
[ :waiting_classification, 'W', "waiting_classification" ],
[ :filetype, 'T', "filetype" ],
[ :tags, 'U', "tag" ]
[ :tags, 'U', "tag" ],
[ :request_public_body_tags, 'X', "request_public_body_tag" ]
],
:if => :indexed_by_search?,
:eager_load => [ :outgoing_message, :comment, { :info_request => [ :user, :public_body, :censor_rules ] } ]
Expand Down Expand Up @@ -249,6 +250,10 @@ def tags
info_request.tag_array_for_search
end

def request_public_body_tags
info_request.public_body.tag_array_for_search
end

def indexed_by_search?
if ['sent', 'followup_sent', 'response', 'comment'].include?(event_type)
if !info_request.indexed_by_search?
Expand Down
3 changes: 3 additions & 0 deletions app/views/general/_advanced_search_tips.html.erb
Expand Up @@ -22,6 +22,9 @@
'default any of the tags can be present, you have to put ' \
'<code>AND</code> explicitly if you only want results them ' \
'all present.') %></li>
<li><%= _('<strong><code>request_public_body_tag:charity</code></strong> ' \
'to find requests to public authorities with a given ' \
'tag.') %></li>
<li><%= _('Read about <a href="{{advanced_search_url}}">advanced search operators</a>, such as proximity and wildcards.', :advanced_search_url => "http://www.xapian.org/docs/queryparser.html") %></li>
</ul>

Expand Down
5 changes: 5 additions & 0 deletions doc/CHANGES.md
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Search for requests made to a tagged set of public authorities (Henare Degan)
* Allow format to be parsed correctly so JSON searches work (Henare Degan)
* Improve styling of request status messages (Martin Wright)
* Improve Public Body import from CSV documentation and page layout (Liz Conlan,
Expand All @@ -24,6 +25,10 @@
httpd.conf-example` and `config/nginx.conf.example`).
* Install the `geoip-database-contrib` package to automatically fetch latest
geoip databases.
* To make requests searchable based on their public body's tags you'll need to
reindex Xapian. To make this quicker you can selectively reindex just the
model and new term by running
`bundle exec rake xapian:rebuild_index models="InfoRequestEvent" terms="X"`

### Changed Templates

Expand Down
17 changes: 17 additions & 0 deletions spec/integration/search_request_spec.rb
Expand Up @@ -96,4 +96,21 @@

end

it "should search for requests made to a tagged set of public authorities" do
request_via_redirect("get", "/search/requests",
:query => "request_public_body_tag:popular_agency")
# In the fixtures there are 2 public bodies with the popular_agency tag:
# - geraldine_public_body
# - humpadink_public_body
# and
n = 6
# requests to those public bodies:
# - fancy_dog_request
# - naughty_chicken_request
# - badger_request
# - boring_request
# - external_request
# - anonymous_external_request
expect(response.body).to include("FOI requests 1 to #{n} of #{n}")
end
end

0 comments on commit 265087e

Please sign in to comment.