|
Lines 1-3
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 1 |
# Copyright 2015 Catalyst IT |
3 |
# Copyright 2015 Catalyst IT |
| 2 |
# |
4 |
# |
| 3 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
|
Lines 17-28
Link Here
|
| 17 |
|
19 |
|
| 18 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 19 |
|
21 |
|
| 20 |
use Test::More tests => 11; |
22 |
use Test::More; |
| 21 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
|
|
24 |
use English qw( -no-match-vars ); |
| 22 |
|
25 |
|
| 23 |
use Koha::SearchEngine::Elasticsearch::QueryBuilder; |
26 |
use Koha::SearchEngine::Elasticsearch::QueryBuilder; |
| 24 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
|
|
| 25 |
|
27 |
|
|
|
28 |
BEGIN { |
| 29 |
my $check; |
| 30 |
my $msg; |
| 31 |
if ( !defined C4::Context->config('elasticsearch') ) { |
| 32 |
$msg = '**** ELASTICSEARCH CONFIGURATION NOT AVAILABLE ****'; |
| 33 |
} |
| 34 |
if ( !$msg ) { |
| 35 |
my $ses = Search::Elasticsearch->new( |
| 36 |
{ 'nodes' => ['localhost:9200'], 'index' => 'mydb' } ); |
| 37 |
$check = eval { my $node_check = $ses->nodes->info; }; |
| 38 |
$msg = $EVAL_ERROR; |
| 39 |
} |
| 40 |
|
| 41 |
if ( !$check && !$msg ) { |
| 42 |
$msg = '**** UNABLE TO CHECK ELASTICSEARCH NODE INFO ****'; |
| 43 |
} |
| 44 |
elsif ( $msg =~ /NoNode/xsm ) { |
| 45 |
$msg = '**** ELASTICsEARCH LACKS NODES ****'; |
| 46 |
} |
| 47 |
|
| 48 |
if ($msg) { |
| 49 |
plan skip_all => $msg; |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
| 26 |
|
55 |
|
| 27 |
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); |
56 |
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); |
| 28 |
$se->mock( 'get_elasticsearch_mappings', sub { |
57 |
$se->mock( 'get_elasticsearch_mappings', sub { |
|
Lines 84-114
is( $searcher->index, 'mydb', 'Testing basic accessor' );
Link Here
|
| 84 |
|
113 |
|
| 85 |
ok( my $query = $builder->build_query('easy'), 'Build a search query'); |
114 |
ok( my $query = $builder->build_query('easy'), 'Build a search query'); |
| 86 |
|
115 |
|
| 87 |
SKIP: { |
116 |
Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->drop_index; |
| 88 |
|
117 |
Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->create_index; |
| 89 |
eval { $builder->get_elasticsearch_params; }; |
|
|
| 90 |
|
| 91 |
skip 'Elasticsearch configuration not available', 8 |
| 92 |
if $@; |
| 93 |
|
118 |
|
| 94 |
Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->drop_index; |
119 |
ok( my $results = $searcher->search( $query) , 'Do a search ' ); |
| 95 |
Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'mydb' })->create_index; |
|
|
| 96 |
|
120 |
|
| 97 |
ok( my $results = $searcher->search( $query) , 'Do a search ' ); |
121 |
is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results '); |
| 98 |
|
122 |
|
| 99 |
is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results '); |
123 |
ok ($results = $searcher->search_compat( $query ), 'Test search_compat' ); |
| 100 |
|
124 |
|
| 101 |
ok ($results = $searcher->search_compat( $query ), 'Test search_compat' ); |
125 |
ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' ); |
| 102 |
|
126 |
|
| 103 |
ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' ); |
127 |
is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use'); |
| 104 |
|
128 |
|
| 105 |
is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use'); |
129 |
is ($searcher->max_result_window, 10000, 'By default, max_result_window is 10000'); |
|
|
130 |
$searcher->store->es->indices->put_settings(index => $searcher->store->index_name, body => { |
| 131 |
'index' => { |
| 132 |
'max_result_window' => 12000, |
| 133 |
}, |
| 134 |
}); |
| 135 |
is ($searcher->max_result_window, 12000, 'max_result_window returns the correct value'); |
| 106 |
|
136 |
|
| 107 |
is ($searcher->max_result_window, 10000, 'By default, max_result_window is 10000'); |
137 |
done_testing(); |
| 108 |
$searcher->store->es->indices->put_settings(index => $searcher->store->index_name, body => { |
|
|
| 109 |
'index' => { |
| 110 |
'max_result_window' => 12000, |
| 111 |
}, |
| 112 |
}); |
| 113 |
is ($searcher->max_result_window, 12000, 'max_result_window returns the correct value'); |
| 114 |
} |
| 115 |
- |
|
|