diff options
author | francis <francis> | 2008-05-18 21:53:15 +0000 |
---|---|---|
committer | francis <francis> | 2008-05-18 21:53:15 +0000 |
commit | c048302b287baf8ea8dc0c6bf080af61fb054f1c (patch) | |
tree | f65235b7946926fabe6dbbe0ed4ebe597fef4e4d | |
parent | fb056ea565edc94f5e1b81148c98e58b94f080c6 (diff) |
Show more similar requests.
Remove display of requests to same person / authority as overlaps too much anyway.
-rw-r--r-- | app/controllers/request_controller.rb | 27 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 5 | ||||
-rw-r--r-- | app/views/request/show.rhtml | 14 | ||||
-rw-r--r-- | app/views/request/similar.rhtml | 19 | ||||
-rw-r--r-- | config/routes.rb | 4 | ||||
-rw-r--r-- | todo.txt | 7 |
6 files changed, 50 insertions, 26 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 4e2e8703c..063e2fd01 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: request_controller.rb,v 1.87 2008-05-18 03:47:01 francis Exp $ +# $Id: request_controller.rb,v 1.88 2008-05-18 21:53:15 francis Exp $ class RequestController < ApplicationController @@ -30,24 +30,25 @@ class RequestController < ApplicationController @new_responses_count = @events_needing_description.select {|i| i.event_type == 'response'}.size # Sidebar stuff - limit = 3 + 1 - # ... requests made by same person to same authority - @info_requests_same_user_same_body = InfoRequest.find(:all, :order => "created_at desc", - :conditions => ["prominence = 'normal' and user_id = ? and public_body_id = ? and id <> ?", @info_request.user_id, @info_request.public_body_id, @info_request.id], - :limit => limit) - @info_requests_same_user_same_body_more = false - if @info_requests_same_user_same_body.size == limit - @info_requests_same_user_same_body = @info_requests_same_user_same_body[0, limit - 1] - @info_requests_same_user_same_body_more = true - end + limit = 3 # ... requests that have similar imporant terms @xapian_similar = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, - :limit => limit - 1, :collapse_by_prefix => 'request_collapse') - + :limit => limit, :collapse_by_prefix => 'request_collapse') + @xapian_similar_more = (@xapian_similar.matches_estimated > limit) + # Track corresponding to this page @track_thing = TrackThing.create_track_for_request(@info_request) end + # Requests similar to this one + def similar + @per_page = 25 + @page = (params[:page] || "1").to_i + @info_request = InfoRequest.find_by_url_title(params[:url_title]) + @xapian_object = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, + :offset => (@page - 1) * @per_page, :limit => @per_page, :collapse_by_prefix => 'request_collapse') + end + def list @view = params[:view] diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index cb4b7e5b6..88ffd790e 100644 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -5,7 +5,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: link_to_helper.rb,v 1.31 2008-05-15 22:47:16 francis Exp $ +# $Id: link_to_helper.rb,v 1.32 2008-05-18 21:53:16 francis Exp $ module LinkToHelper @@ -24,6 +24,9 @@ module LinkToHelper def request_admin_link(info_request) link_to h(info_request.title), request_admin_url(info_request) end + def request_similar_url(info_request) + return similar_request_url(:url_title => info_request.url_title, :only_path => true) + end # Incoming / outgoing messages def incoming_message_url(incoming_message) diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml index 9a116f7e2..181bb27e3 100644 --- a/app/views/request/show.rhtml +++ b/app/views/request/show.rhtml @@ -16,21 +16,15 @@ <br><img src="/images/pledgebank.png" alt=""> <a href="http://www.pledgebank.com">Pledge with others</a> </p> - <% if @info_requests_same_user_same_body.size > 0 %> - <h2>Requests from same user to same authority</h2> - <!-- <h2>Some other requests made by <%= user_link(@info_request.user) %> to <%= public_body_link(@info_request.public_body) %></h2> --> - <%= render :partial => 'sidebar_request_listing', :locals => { :info_requests => @info_requests_same_user_same_body } %> - <% if @info_requests_same_user_same_body_more %> - <p><%= link_to "More such requests", search_url("variety:sent requested_from:" + @info_request.public_body.url_name + " requested_by:" + @info_request.user.url_name + " -request:" + @info_request.url_title, "newest") %></p> - <% end %> - <% end %> - <% if @xapian_similar.results.size > 0 %> <h2>Similar requests</h2> <% for result in @xapian_similar.results %> <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %> <% end %> - <% end %> + <% if @xapian_similar_more %> + <p><%= link_to "More similar requests", request_similar_url(@info_request) %></p> + <% end %> + <% end %> <!-- <%= @xapian_similar.important_terms.join(" ") %> --> <!--<h2>Blog posts about this request</h2> diff --git a/app/views/request/similar.rhtml b/app/views/request/similar.rhtml new file mode 100644 index 000000000..8bcceab19 --- /dev/null +++ b/app/views/request/similar.rhtml @@ -0,0 +1,19 @@ +<% @title = "Requests similar to '" + h(@info_request.title) + "'" %> +<h1><%="Requests similar to '" + request_link(@info_request) + "'"%></h1> + +<% if @xapian_object.results.empty? %> + <p>No requests made yet.</p> +<% else %> + <p class="subtitle"> + <%= @xapian_object.matches_estimated %> in total + </p> + <% for result in @xapian_object.results %> + <% if result[:model].class.to_s == 'InfoRequestEvent' %> + <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %> + <% else %> + <p><strong>Unexpected search result type <%=result[:model].class.to_s%></strong></p> + <% end %> + <% end %> +<% end %> + +<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_object.matches_estimated) %> diff --git a/config/routes.rb b/config/routes.rb index b7450ac4f..b72bf488a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: routes.rb,v 1.63 2008-05-16 18:28:07 francis Exp $ +# $Id: routes.rb,v 1.64 2008-05-18 21:53:16 francis Exp $ ActionController::Routing::Routes.draw do |map| @@ -35,6 +35,8 @@ ActionController::Routing::Routes.draw do |map| request.new_request_to_body '/new/:public_body_id', :action => 'new' request.show_request '/request/:url_title', :action => 'show' + request.similar_request '/request/:url_title/similar', :action => 'similar' + request.describe_state '/request/:id/describe', :action => 'describe_state' request.show_response_no_followup '/request/:id/response', :action => 'show_response' request.show_response '/request/:id/response/:incoming_message_id', :action => 'show_response' @@ -1,3 +1,8 @@ +Commit similar documents thing to acts_as_xapian + +Second page of search knackered +http://www.whatdotheyknow.com/search/bill?page=2 + FOI requests to use to test it ============================== @@ -47,7 +52,7 @@ Reconsider described vs. newest for the tracks Fix up the privacy policy Advertise WDTK search queries on TWFY - +Advertise alerts on end pages with WDTK Later ===== |