View | Details | Raw Unified | Return to bug 18316
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+12 lines)
Lines 92-97 sub build_query { Link Here
92
            default_operator => 'AND',
92
            default_operator => 'AND',
93
            default_field    => '_all',
93
            default_field    => '_all',
94
            lenient          => JSON::true,
94
            lenient          => JSON::true,
95
            fields           => $options{fields},
96
            use_dis_max      => JSON::true,
95
        }
97
        }
96
    };
98
    };
97
99
Lines 228-236 sub build_query_compat { Link Here
228
        join( ' ', $self->_create_query_string(@search_params) ) || (),
230
        join( ' ', $self->_create_query_string(@search_params) ) || (),
229
        $self->_join_queries( $self->_convert_index_strings(@$limits) ) || () );
231
        $self->_join_queries( $self->_convert_index_strings(@$limits) ) || () );
230
232
233
    my @weights = $params->{weight};
234
    my @w_fields = $params->{w_fields};
235
    my @fields = '_all';
236
    if ( defined $weights[0] ) {
237
        for (my $i = 0 ; $i < (scalar @weights) ; $i++ ){
238
            push @fields, "$w_fields[$i]^$weights[$i]";
239
        }
240
    }
241
231
    # If there's no query on the left, let's remove the junk left behind
242
    # If there's no query on the left, let's remove the junk left behind
232
    $query_str =~ s/^ AND //;
243
    $query_str =~ s/^ AND //;
233
    my %options;
244
    my %options;
245
    $options{fields} = \@fields;
234
    $options{sort} = \@sort_params;
246
    $options{sort} = \@sort_params;
235
    $options{expanded_facet} = $params->{expanded_facet};
247
    $options{expanded_facet} = $params->{expanded_facet};
236
    my $query = $self->build_query( $query_str, %options );
248
    my $query = $self->build_query( $query_str, %options );
(-)a/Koha/SearchFields.pm (+23 lines)
Lines 35-40 Koha::SearchFields - Koha SearchField Object set class Link Here
35
35
36
=cut
36
=cut
37
37
38
=head3 weighted_fields
39
40
my (@w_fields, @weight) = Koha::SearchFields->weighted_fields();
41
42
=cut
43
44
sub weighted_fields {
45
    my ($self) = @_;
46
47
    my ($w_fields, $weight) = ([], []);
48
    my $fields = $self->search(
49
        { weight => { '>' => 0, '!=' => undef } },
50
        { order_by => { -desc => 'weight' } }
51
    );
52
53
    while ( my $field = $fields->next ) {
54
        push @$w_fields, $field->name;
55
        push @$weight, $field->weight;
56
    }
57
58
    return ($w_fields, $weight);
59
}
60
38
=head3 type
61
=head3 type
39
62
40
=cut
63
=cut
(-)a/catalogue/search.pl (-1 / +7 lines)
Lines 155-160 use Koha::Patrons; Link Here
155
use Koha::SearchEngine::Search;
155
use Koha::SearchEngine::Search;
156
use Koha::SearchEngine::QueryBuilder;
156
use Koha::SearchEngine::QueryBuilder;
157
use Koha::Virtualshelves;
157
use Koha::Virtualshelves;
158
use Koha::SearchFields;
158
159
159
use URI::Escape;
160
use URI::Escape;
160
161
Lines 455-460 my $expanded_facet = $params->{'expand'}; Link Here
455
# Define some global variables
456
# Define some global variables
456
my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
457
my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
457
458
459
my ($w_fields, $weight);
460
unless ( $cgi->param('advsearch') ) {
461
    ($w_fields, $weight) = Koha::SearchFields->weighted_fields();
462
}
463
458
my $builder = Koha::SearchEngine::QueryBuilder->new(
464
my $builder = Koha::SearchEngine::QueryBuilder->new(
459
    { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
465
    { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
460
my $searcher = Koha::SearchEngine::Search->new(
466
my $searcher = Koha::SearchEngine::Search->new(
Lines 467-473 my $searcher = Koha::SearchEngine::Search->new( Link Here
467
    $query_type
473
    $query_type
468
  )
474
  )
469
  = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits,
475
  = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits,
470
    \@sort_by, $scan, $lang );
476
    \@sort_by, $scan, $lang, { w_fields => @$w_fields, weight => @$weight  } );
471
477
472
## parse the query_cgi string and put it into a form suitable for <input>s
478
## parse the query_cgi string and put it into a form suitable for <input>s
473
my @query_inputs;
479
my @query_inputs;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt (+1 lines)
Lines 17-22 Link Here
17
17
18
<form action="search.pl" method="get">
18
<form action="search.pl" method="get">
19
<div id="advanced-search">
19
<div id="advanced-search">
20
<input type="hidden" name="advsearch" value="1"/>
20
<h1>Advanced search</h1>
21
<h1>Advanced search</h1>
21
<p>
22
<p>
22
  <a href="/cgi-bin/koha/catalogue/itemsearch.pl">Go to item search</a>
23
  <a href="/cgi-bin/koha/catalogue/itemsearch.pl">Go to item search</a>
(-)a/t/db_dependent/Koha/SearchField.t (-2 / +69 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 16;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::SearchFields;
25
use Koha::SearchFields;
Lines 132-135 my $sf3 = $builder->build({ Link Here
132
$search_field = Koha::SearchFields->find($sf3->{id});
132
$search_field = Koha::SearchFields->find($sf3->{id});
133
ok(!$search_field->is_mapped_biblios, 'Search field is not mapped');
133
ok(!$search_field->is_mapped_biblios, 'Search field is not mapped');
134
134
135
Koha::SearchFields->search({})->delete;
136
137
$builder->build({
138
    source => 'SearchField',
139
    value => {
140
        name    => 'acqdate',
141
        label   => 'acqdate',
142
        weight  => undef
143
    }
144
});
145
146
$builder->build({
147
    source => 'SearchField',
148
    value => {
149
        name    => 'copydate',
150
        label   => 'copydate',
151
        weight  => undef
152
    }
153
});
154
155
$builder->build({
156
    source => 'SearchField',
157
    value => {
158
        name    => 'ccode',
159
        label   => 'ccode',
160
        weight  => 0
161
    }
162
});
163
164
$builder->build({
165
    source => 'SearchField',
166
    value => {
167
        name    => 'title',
168
        label   => 'title',
169
        weight  => 25
170
    }
171
});
172
173
$builder->build({
174
    source => 'SearchField',
175
    value => {
176
        name    => 'subject',
177
        label   => 'subject',
178
        weight  => 15
179
    }
180
});
181
182
$builder->build({
183
    source => 'SearchField',
184
    value => {
185
        name    => 'author',
186
        label   => 'author',
187
        weight  => 5
188
    }
189
});
190
191
my ($w_fields, $weight) = Koha::SearchFields->weighted_fields();
192
is(scalar(@$w_fields), 3, 'weighted_fields should return 3 weighted fields.');
193
is(scalar(@$weight), 3, 'weighted_fields should return 3 weight.');
194
195
is($w_fields->[0], 'title', 'First field is title.');
196
is($w_fields->[1], 'subject', 'Second field is subject.');
197
is($w_fields->[2], 'author', 'Third field is author.');
198
199
is($weight->[0], 25, 'Title weight is 25.');
200
is($weight->[1], 15, 'Subject weight is 15.');
201
is($weight->[2], 5, 'Author weight is 5.');
202
135
$schema->storage->txn_rollback;
203
$schema->storage->txn_rollback;
136
- 

Return to bug 18316