aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Roles
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Roles')
-rw-r--r--perllib/FixMyStreet/Roles/ConfirmOpen311.pm8
-rw-r--r--perllib/FixMyStreet/Roles/ContactExtra.pm4
-rw-r--r--perllib/FixMyStreet/Roles/FullTextSearch.pm29
3 files changed, 34 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Roles/ConfirmOpen311.pm b/perllib/FixMyStreet/Roles/ConfirmOpen311.pm
index 0845105f1..1663844a2 100644
--- a/perllib/FixMyStreet/Roles/ConfirmOpen311.pm
+++ b/perllib/FixMyStreet/Roles/ConfirmOpen311.pm
@@ -13,8 +13,8 @@ sub open311_config {
$params->{multi_photos} = 1;
}
-sub open311_extra_data {
- my ($self, $row, $h, $extra) = @_;
+sub open311_extra_data_include {
+ my ($self, $row, $h) = @_;
my $open311_only = [
{ name => 'report_url',
@@ -31,9 +31,7 @@ sub open311_extra_data {
# service at the point we're sending the report over Open311.
if (!$row->get_extra_field_value('site_code')) {
if (my $site_code = $self->lookup_site_code($row)) {
- push @$extra,
- { name => 'site_code',
- value => $site_code };
+ $row->update_extra_field({ name => 'site_code', value => $site_code });
}
}
diff --git a/perllib/FixMyStreet/Roles/ContactExtra.pm b/perllib/FixMyStreet/Roles/ContactExtra.pm
index e78d9b53f..9615b0f0c 100644
--- a/perllib/FixMyStreet/Roles/ContactExtra.pm
+++ b/perllib/FixMyStreet/Roles/ContactExtra.pm
@@ -45,8 +45,8 @@ sub by_categories {
$_->$join_table == 0 # There's no category at all on this defect type/template/priority
|| (grep { $_->contact_id == $contact->get_column('id') } $_->$join_table)
} @results;
- @ts = $rs->map_extras(@ts);
- $extras{$contact->category} = encode_json(\@ts);
+ @ts = $rs->map_extras(\%params, @ts);
+ $extras{$contact->category} = JSON::XS->new->encode(\@ts);
}
return \%extras;
diff --git a/perllib/FixMyStreet/Roles/FullTextSearch.pm b/perllib/FixMyStreet/Roles/FullTextSearch.pm
new file mode 100644
index 000000000..871b1d185
--- /dev/null
+++ b/perllib/FixMyStreet/Roles/FullTextSearch.pm
@@ -0,0 +1,29 @@
+package FixMyStreet::Roles::FullTextSearch;
+
+use Moo::Role;
+use FixMyStreet;
+
+requires 'text_search_columns';
+requires 'text_search_nulls';
+requires 'text_search_translate';
+
+sub search_text {
+ my ($rs, $query) = @_;
+ my %nulls = map { $_ => 1 } $rs->text_search_nulls;
+ my @cols = map {
+ my $col = $rs->me($_);
+ $nulls{$_} ? "coalesce($col, '')" : $col;
+ } $rs->text_search_columns;
+ my $vector = join(" || ' ' || ", @cols);
+ my $bind = '?';
+ if (my $trans = $rs->text_search_translate) {
+ my $replace = ' ' x length $trans;
+ $vector = "translate($vector, '$trans', '$replace')";
+ $bind = "translate(?, '$trans', '$replace')";
+ }
+ my $config = FixMyStreet->config('DB_FULL_TEXT_SEARCH_CONFIG') || 'english';
+ $rs->search(\[ "to_tsvector('$config', $vector) @@ plainto_tsquery('$config', $bind)", $query ]);
+}
+
+1;
+