aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-07-29 09:03:56 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-07-31 12:33:38 +0100
commitbd42d6a1fcb6c8e6d89413e0ee22617625d95bad (patch)
tree2bdbeff779e44d14aa2409f9660ab3c91c9a8377 /perllib/FixMyStreet/App/Controller
parent34dd7c253d337ea922049390dc6ba44b8686e516 (diff)
Add database index for full text search.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Reports.pm46
1 files changed, 15 insertions, 31 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
index 48386cf3e..052230643 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
@@ -50,6 +50,8 @@ sub index : Path {
return if $c->cobrand->call_hook(report_search_query => $query, $p_page, $u_page, $order);
+ my $problems = $c->cobrand->problems;
+
if (my $search = $c->get_param('search')) {
$search = $self->trim($search);
@@ -62,9 +64,6 @@ sub index : Path {
$c->stash->{searched} = $search;
- my $search_n = 0;
- $search_n = int($search) if $search =~ /^\d+$/;
-
my $like_search = "%$search%";
my $parsed = FixMyStreet::SMS->parse_username($search);
@@ -92,20 +91,10 @@ sub index : Path {
'me.external_id' => { like => "%$1%" }
];
} else {
- $query->{'-or'} = [
- 'me.id' => $search_n,
- 'user.email' => { ilike => $like_search },
- 'user.phone' => { ilike => $like_search },
- 'me.external_id' => { ilike => $like_search },
- 'me.name' => { ilike => $like_search },
- 'me.title' => { ilike => $like_search },
- detail => { ilike => $like_search },
- bodies_str => { like => $like_search },
- cobrand_data => { like => $like_search },
- ];
+ $problems = $problems->search_text($search);
}
- my $problems = $c->cobrand->problems->search(
+ $problems = $problems->search(
$query,
{
join => 'user',
@@ -119,6 +108,7 @@ sub index : Path {
$c->stash->{problems} = [ $problems->all ];
$c->stash->{problems_pager} = $problems->pager;
+ my $updates = $c->cobrand->updates;
if ($valid_email) {
$query = [
'user.email' => { ilike => $like_search },
@@ -133,24 +123,18 @@ sub index : Path {
'me.problem_id' => int($1),
];
} elsif ($search =~ /^area:(\d+)$/) {
- $query = [];
+ $query = 0;
} else {
- $query = [
- 'me.id' => $search_n,
- 'problem.id' => $search_n,
- 'user.email' => { ilike => $like_search },
- 'user.phone' => { ilike => $like_search },
- 'me.name' => { ilike => $like_search },
- text => { ilike => $like_search },
- 'me.cobrand_data' => { ilike => $like_search },
- ];
+ $updates = $updates->search_text($search);
+ $query = 1;
}
- if (@$query) {
- my $updates = $c->cobrand->updates->search(
- {
- -or => $query,
- },
+ $query = { -or => $query } if ref $query;
+
+ if ($query) {
+ $query = undef unless ref $query;
+ $updates = $updates->search(
+ $query,
{
'+columns' => ['user.email'],
join => 'user',
@@ -165,7 +149,7 @@ sub index : Path {
} else {
- my $problems = $c->cobrand->problems->search(
+ $problems = $problems->search(
$query,
{
'+columns' => ['user.email'],