aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application.rb10
-rw-r--r--app/controllers/general_controller.rb16
-rw-r--r--app/controllers/request_controller.rb4
-rw-r--r--app/controllers/track_controller.rb5
-rw-r--r--app/models/info_request.rb8
-rw-r--r--app/models/track_mailer.rb4
-rw-r--r--app/views/general/frontpage.rhtml10
-rw-r--r--app/views/general/search.rhtml66
-rw-r--r--app/views/layouts/default.rhtml4
-rw-r--r--app/views/request/list.rhtml12
-rw-r--r--app/views/track/atom_feed.atom.builder10
11 files changed, 83 insertions, 66 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index e36d21e22..6decd6591 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: application.rb,v 1.44 2008-04-30 02:14:07 francis Exp $
+# $Id: application.rb,v 1.45 2008-05-15 17:40:43 francis Exp $
class ApplicationController < ActionController::Base
@@ -141,7 +141,7 @@ class ApplicationController < ActionController::Base
end
# Function for search
- def perform_search(query, sortby, collapse, per_page = 25, this_page = nil)
+ def perform_search(models, query, sortby, collapse, per_page = 25, this_page = nil)
@query = query
@sortby = sortby
@@ -157,11 +157,7 @@ class ApplicationController < ActionController::Base
else
@page = this_page
end
- xapian_object = InfoRequest.full_search(@query, order, ascending, collapse, @per_page, @page)
- @search_results = xapian_object.results
- @search_hits = xapian_object.matches_estimated
- @search_spelling = xapian_object.spelling_correction
- @highlight_words = xapian_object.words_to_highlight
+ return InfoRequest.full_search(models, @query, order, ascending, collapse, @per_page, @page)
end
# URL generating functions are needed by all controllers (for redirects),
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index afdbee82b..3c94940dd 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: general_controller.rb,v 1.22 2008-04-30 00:57:20 francis Exp $
+# $Id: general_controller.rb,v 1.23 2008-05-15 17:40:43 francis Exp $
class GeneralController < ApplicationController
@@ -35,7 +35,7 @@ class GeneralController < ApplicationController
# Get all successful requests for display on the right
query = 'variety:response (status:successful OR status:partially_successful)'
sortby = "newest"
- perform_search(query, sortby, 'request_collapse', 3)
+ @xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_collapse', 3)
end
@@ -62,9 +62,17 @@ class GeneralController < ApplicationController
combined = combined[0..-2]
end
query = combined.join("/")
- perform_search(query, sortby, 'request_collapse')
- #render :controller => "help", :action => "about"
+ # Query each type separately for separate display
+ @xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse', 25)
+ @xapian_bodies = perform_search([PublicBody], query, sortby, nil, 5)
+ @xapian_users = perform_search([User], query, sortby, nil, 5)
+
+ @total_hits = @xapian_requests.matches_estimated + @xapian_bodies.matches_estimated + @xapian_users.matches_estimated
+
+ # Spelling and highight words are same for all three queries
+ @spelling_correction = @xapian_requests.spelling_correction
+ @highlight_words = @xapian_requests.words_to_highlight
end
# For debugging
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 719fd68e8..58ea944cb 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.83 2008-05-12 09:18:45 francis Exp $
+# $Id: request_controller.rb,v 1.84 2008-05-15 17:40:43 francis Exp $
class RequestController < ApplicationController
@@ -60,7 +60,7 @@ class RequestController < ApplicationController
else
raise "unknown request list view " + @view.to_s
end
- perform_search(query, sortby, 'request_collapse')
+ @xapian_object = perform_search([InfoRequestEvent], sortby, 'request_collapse')
end
# Page new form posts to
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index ebd9c7a30..7f0553a34 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_controller.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: track_controller.rb,v 1.16 2008-05-12 17:55:18 francis Exp $
+# $Id: track_controller.rb,v 1.17 2008-05-15 17:40:43 francis Exp $
class TrackController < ApplicationController
@@ -130,8 +130,7 @@ class TrackController < ApplicationController
# Atom feed (like RSS) for the track
def atom_feed
@track_thing = TrackThing.find(params[:track_id].to_i)
-
- perform_search(@track_thing.track_query, @track_thing.params[:feed_sortby], nil, 25, 1)
+ @xapian_object = perform_search([InfoRequestEvent], @track_thing.track_query, @track_thing.params[:feed_sortby], nil, 25, 1)
respond_to :atom
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index c0bd8de52..b760d5910 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -21,7 +21,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.108 2008-05-12 01:38:18 francis Exp $
+# $Id: info_request.rb,v 1.109 2008-05-15 17:40:43 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -67,10 +67,10 @@ class InfoRequest < ActiveRecord::Base
# Central function to do all searches
# (Not really the right place to put it, but everything can get it here, and it
# does *mainly* find info requests, via their events, so hey)
- def InfoRequest.full_search(query, order, ascending, collapse, per_page, page)
+ def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
offset = (page - 1) * per_page
return ::ActsAsXapian::Search.new(
- [InfoRequestEvent, PublicBody, User], query,
+ models, query,
:offset => offset, :limit => per_page,
:sort_by_prefix => order,
:sort_by_ascending => ascending,
@@ -85,7 +85,7 @@ class InfoRequest < ActiveRecord::Base
t = Time.now.usec - t
secs = t / 1000000.0
STDOUT.write secs.to_s + " query " + i.to_s + "\n"
- results = InfoRequest.full_search(query, "created_at", false, nil, 25, 1).results
+ results = InfoRequest.full_search([InfoRequestEvent], query, "created_at", false, nil, 25, 1).results
end
end
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 908ee1621..713bf3fca 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: track_mailer.rb,v 1.8 2008-04-30 00:46:01 francis Exp $
+# $Id: track_mailer.rb,v 1.9 2008-05-15 17:40:43 francis Exp $
class TrackMailer < ApplicationMailer
def event_digest(user, email_about_things)
@@ -41,7 +41,7 @@ class TrackMailer < ApplicationMailer
end
# Query for things in this track
- xapian_object = InfoRequest.full_search(track_thing.track_query, 'created_at', false, nil, 100, 1)
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'created_at', false, nil, 100, 1)
# Go through looking for unalerted things
alert_results = []
diff --git a/app/views/general/frontpage.rhtml b/app/views/general/frontpage.rhtml
index 9584b1608..bf6ccc6b9 100644
--- a/app/views/general/frontpage.rhtml
+++ b/app/views/general/frontpage.rhtml
@@ -58,14 +58,14 @@
<div id="find_information">
<h1>Explore government information that others received</h1>
- <% if @search_results.empty? %>
+ <% if @xapian_object.results.empty? %>
<p>None yet.</p>
<% else %>
- <% for search_result in @search_results %>
- <% if search_result[:model].class.to_s == 'InfoRequestEvent' %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => search_result[:model], :info_request => search_result[:model].info_request } %>
+ <% 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 <%=search_result[:model].class.to_s%></strong></p>
+ <p><strong>Unexpected search result type <%=result[:model].class.to_s%></strong></p>
<% end %>
<% end %>
<% end %>
diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml
index a043e41c9..a31596463 100644
--- a/app/views/general/search.rhtml
+++ b/app/views/general/search.rhtml
@@ -1,11 +1,12 @@
+<% @show_tips = @xapian_requests.nil? || (@total_hits == 0) %>
+
<% if @query.nil? %>
<% @title = "Search Freedom of Information requests, public authorities and users" %>
<h1><%=@title%></h1>
-<% elsif @search_hits == 0 %>
+<% elsif @total_hits == 0 %>
<% @title = "Nothing found for '" + h(@query) + "'" %>
-
<% else %>
- <% @title = "Results " + ((@page-1)*@per_page+1).to_s + "-" + [@page*@per_page, @search_hits].min.to_s + " of " + @search_hits.to_s + " for '" + h(@query) + "'" %>
+ <% @title = "Results page " + @page.to_s %>
<% end%>
<% form_tag({:action => "search_redirect"}, {:id => "search_form"}) do %>
@@ -13,42 +14,55 @@
<%= text_field_tag 'query', @query, { :size => 40 } %>
<%= hidden_field_tag 'sortby', params[:sortby] %>
<%= submit_tag "Search" %>
- <% if not @search_results.nil? and not @search_results.empty? %>
+ <% if not @show_tips %>
&nbsp;&nbsp;<a href="/search">Advanced tips</a>
<% end %>
</p>
<% end %>
-<% if not @search_results.nil? %>
- <%=link_to_unless @sortby.nil?, "Show most relevant results first", search_url(@query, nil) %>
- |
- <%=link_to_unless @sortby == 'newest', "Newest results first", search_url(@query, 'newest') %>
+<%=link_to_unless @sortby.nil?, "Show most relevant results first", search_url(@query, nil) %>
+|
+<%=link_to_unless @sortby == 'newest', "Newest results first", search_url(@query, 'newest') %>
- <h1><%=@title%></h1>
+<% if @total_hits == 0 %>
+ <h1><%=@title %></h1>
+<% end %>
- <% if @search_spelling %>
- <p id="did_you_mean">Did you mean: <%= link_to @search_spelling, search_url(@search_spelling, @sortby) %></p>
+<% if @spelling_correction %>
+ <p id="did_you_mean">Did you mean: <%= link_to @spelling_correction, search_url(@spelling_correction, @sortby) %></p>
+<% end %>
+
+<% if @xapian_bodies.results.size > 0 %>
+ <h1><%= "Public authorities " + ((@page-1)*@per_page+1).to_s + "-" + [@page*@per_page, @xapian_bodies.matches_estimated].min.to_s + " of " + @xapian_bodies.matches_estimated.to_s + " for '" + h(@query) + "'" %></h1>
+
+ <% for result in @xapian_bodies.results %>
+ <%= render :partial => 'body/body_listing_single', :locals => { :public_body => result[:model] } %>
<% end %>
- <% if @search_results.empty? %>
- <% else %>
- <% for search_result in @search_results %>
- <% if search_result[:model].class.to_s == 'PublicBody' %>
- <%= render :partial => 'body/body_listing_single', :locals => { :public_body => search_result[:model] } %>
- <% elsif search_result[:model].class.to_s == 'User' %>
- <%= render :partial => 'user/user_listing_single', :locals => { :display_user => search_result[:model] } %>
- <% elsif search_result[:model].class.to_s == 'InfoRequestEvent' %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => search_result[:model], :info_request => search_result[:model].info_request } %>
- <% else %>
- <p><strong>Unknown search result type <%=search_result[:model].class.to_s%></strong></p>
- <% end %>
- <% end %>
+ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_bodies.matches_estimated) %>
+<% end %>
+
+<% if @xapian_users.results.size > 0 %>
+ <h1><%= "People " + ((@page-1)*@per_page+1).to_s + "-" + [@page*@per_page, @xapian_users.matches_estimated].min.to_s + " of " + @xapian_users.matches_estimated.to_s + " for '" + h(@query) + "'" %></h1>
+
+ <% for result in @xapian_users.results %>
+ <%= render :partial => 'user/user_listing_single', :locals => { :display_user => result[:model] } %>
+ <% end %>
+
+ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_users.matches_estimated) %>
+<% end %>
+
+<% if @xapian_requests.results.size > 0 %>
+ <h1><%= "FOI requests " + ((@page-1)*@per_page+1).to_s + "-" + [@page*@per_page, @xapian_requests.matches_estimated].min.to_s + " of " + @xapian_requests.matches_estimated.to_s + " for '" + h(@query) + "'" %></h1>
+
+ <% for result in @xapian_requests.results %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
<% end %>
- <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @search_hits) %>
+ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_requests.matches_estimated) %>
<% end %>
-<% if @search_results.nil? or @search_results.empty? %>
+<% if @show_tips %>
<h2>Search tips</h2>
<ul>
<li>Enter words that you want to find separated by spaces, e.g. <strong>climbing lane</strong></li>
diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml
index e4877004b..9814a1b97 100644
--- a/app/views/layouts/default.rhtml
+++ b/app/views/layouts/default.rhtml
@@ -10,8 +10,8 @@
WhatDoTheyKnow - file and explore Freedom of Information (FOI) requests
<% end %>
</title>
- <%= stylesheet_link_tag 'yucky-green', :rel => "alternate stylesheet", :title => "Yucky Green" %>
- <%= stylesheet_link_tag 'main', :title => "Main" %>
+ <%= stylesheet_link_tag 'yucky-green', :title => "Yucky Green" %>
+ <%= stylesheet_link_tag 'main', :rel => "alternate stylesheet", :title => "Main" %>
</head>
<body>
<div id="banner">
diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml
index 3e84ca6e8..084f0577f 100644
--- a/app/views/request/list.rhtml
+++ b/app/views/request/list.rhtml
@@ -15,19 +15,19 @@
<%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => false, :list_people => false } %>
<% end %>
-<% if @search_results.empty? %>
+<% if @xapian_object.results.empty? %>
<p>No requests made yet.</p>
<% else %>
- <% for search_result in @search_results %>
- <% if search_result[:model].class.to_s == 'InfoRequestEvent' %>
- <%= render :partial => 'request/request_listing_via_event', :locals => { :event => search_result[:model], :info_request => search_result[:model].info_request } %>
+ <% 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 <%=search_result[:model].class.to_s%></strong></p>
+ <p><strong>Unexpected search result type <%=result[:model].class.to_s%></strong></p>
<% end %>
<% end %>
<% end %>
-<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @search_hits) %>
+<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_object.matches_estimated) %>
<% if @track_thing %>
<%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => false, :list_people => false } %>
diff --git a/app/views/track/atom_feed.atom.builder b/app/views/track/atom_feed.atom.builder
index bc7a48de2..7fa2dda1a 100644
--- a/app/views/track/atom_feed.atom.builder
+++ b/app/views/track/atom_feed.atom.builder
@@ -1,14 +1,14 @@
atom_feed do |feed|
feed.title(@track_thing.params[:title_in_rss])
- for search_result in @search_results
- feed.entry(search_result[:model]) do |entry|
+ for result in @xapian_object.results
+ feed.entry(result[:model]) do |entry|
# Get the HTML content from the same partial template as website search does
content = ''
- if search_result[:model].class.to_s == 'InfoRequestEvent'
- content += render :partial => 'request/request_listing_via_event', :locals => { :event => search_result[:model], :info_request => search_result[:model].info_request }
+ if result[:model].class.to_s == 'InfoRequestEvent'
+ content += render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request }
else
- content = "<p><strong>Unknown search result type " + search_result[:model].class.to_s + "</strong></p>"
+ content = "<p><strong>Unknown search result type " + result[:model].class.to_s + "</strong></p>"
end
# Pull out the heading as separate item, from the partial template
content.match(/(<span class="head">\s+<a href="[^>]*">(.*)<\/a>\s+<\/span>)/)