Browse Source

Bug 25278: add clear_search_fields_cache method

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Nick Clemens 1 year ago
committed by Martin Renvoize
parent
commit
067aa1c5f7
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 24
      Koha/SearchEngine/Elasticsearch.pm
  2. 6
      admin/searchengine/elasticsearch/mappings.pl
  3. 10
      t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t
  4. 6
      t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t

24
Koha/SearchEngine/Elasticsearch.pm

@ -382,11 +382,7 @@ sub reset_elasticsearch_mappings {
}
}
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_opac_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities');
$cache->clear_from_cache('elasticsearch_search_fields_opac_authorities');
$self->clear_search_fields_cache();
# FIXME return the mappings?
}
@ -1287,6 +1283,24 @@ sub get_facetable_fields {
return ( @faceted_fields, @not_faceted_fields );
}
=head2 clear_search_fields_cache
Koha::SearchEngine::Elasticsearch->clear_search_fields_cache();
Clear cached values for ES search fields
=cut
sub clear_search_fields_cache {
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_opac_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities');
$cache->clear_from_cache('elasticsearch_search_fields_opac_authorities');
}
1;
__END__

6
admin/searchengine/elasticsearch/mappings.pl

@ -165,11 +165,7 @@ if ( $op eq 'edit' ) {
push @messages, { type => 'message', code => 'success_on_update' };
$schema->storage->txn_commit;
my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_opac_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities');
$cache->clear_from_cache('elasticsearch_search_fields_opac_authorities');
Koha::SearchEngine::Elasticsearch->clear_search_fields_cache();
$update_mappings->();
}

10
t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t

@ -101,14 +101,6 @@ $se->mock( 'get_elasticsearch_mappings', sub {
return $all_mappings{$self->index};
});
my $cache = Koha::Caches->get_instance();
my $clear_search_fields_cache = sub {
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_opac_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities');
$cache->clear_from_cache('elasticsearch_search_fields_opac_authorities');
};
subtest 'build_authorities_query_compat() tests' => sub {
plan tests => 57;
@ -635,7 +627,7 @@ subtest 'build_query with weighted fields tests' => sub {
$search_field->update({ weight => 25.0 });
$search_field = Koha::SearchFields->find({ name => 'subject' });
$search_field->update({ weight => 15.5 });
$clear_search_fields_cache->();
Koha::SearchEngine::Elasticsearch->clear_search_fields_cache();
my ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef,
undef, undef, undef, { weighted_fields => 1 });

6
t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t

@ -72,8 +72,4 @@ is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
$schema->storage->txn_rollback;
$cache = Koha::Caches->get_instance();
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_opac_biblios');
$cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities');
$cache->clear_from_cache('elasticsearch_search_fields_opac_authorities');
Koha::SearchEngine::Elasticsearch->clear_search_fields_cache();
Loading…
Cancel
Save