1 # Copyright 2015 Catalyst IT
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 13;
23 use Koha::SearchEngine::Elasticsearch::QueryBuilder;
24 use Koha::SearchEngine::Elasticsearch::Indexer;
27 my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' );
28 $se->mock( 'get_elasticsearch_mappings', sub {
50 sortablenumber__sort => {
55 $all_mappings{$self->index} = $mappings;
65 $self->sort_fields($sort_fields->{$self->index});
67 return $all_mappings{$self->index};
70 my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } );
72 use_ok('Koha::SearchEngine::Elasticsearch::Search');
75 my $searcher = Koha::SearchEngine::Elasticsearch::Search->new(
76 { 'nodes' => ['localhost:9200'], 'index' => 'mydb' }
78 'Creating a Koha::SearchEngine::Elasticsearch::Search object'
81 is( $searcher->index, 'mydb', 'Testing basic accessor' );
83 ok( my $query = $builder->build_query('easy'), 'Build a search query');
87 eval { $builder->get_elasticsearch_params; };
89 skip 'Elasticsearch configuration not available', 8
92 Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->drop_index;
93 Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->create_index;
95 ok( my $results = $searcher->search( $query) , 'Do a search ' );
97 is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results ');
99 ok ($results = $searcher->search_compat( $query ), 'Test search_compat' );
101 my ( undef, $scan_query ) = $builder->build_query_compat( undef, ['easy'], [], undef, undef, 1 );
102 ok ((undef, $results) = $searcher->search_compat( $scan_query, undef, [], [], 20, 0, undef, undef, undef, 1 ), 'Test search_compat scan query' );
109 is_deeply($results, $expected, 'Scan query results ok');
111 ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' );
113 is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use');
115 is ($searcher->max_result_window, 10000, 'By default, max_result_window is 10000');
117 $searcher->get_elasticsearch()->indices->put_settings(
118 index => $searcher->index_name,
121 'max_result_window' => 12000,
125 is ($searcher->max_result_window, 12000, 'max_result_window returns the correct value');