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

(-)a/C4/AuthoritiesMarc.pm (-5 / +35 lines)
Lines 201-206 sub SearchAuthorities { Link Here
201
        }
201
        }
202
    } else {
202
    } else {
203
        my $query;
203
        my $query;
204
        my $qpquery = '';
205
        my $QParser;
206
        $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
204
        my $attr = '';
207
        my $attr = '';
205
            # the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
208
            # the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
206
            # the authtypecode. Then, search on $a of this tag_to_report
209
            # the authtypecode. Then, search on $a of this tag_to_report
Lines 219-224 sub SearchAuthorities { Link Here
219
            if ($n>1){
222
            if ($n>1){
220
                while ($n>1){$query= "\@or ".$query;$n--;}
223
                while ($n>1){$query= "\@or ".$query;$n--;}
221
            }
224
            }
225
            if ($QParser) {
226
                $qpquery .= '(authtype:' . join('|| authtype:', @auths) . ')';
227
            }
222
        }
228
        }
223
        
229
        
224
        my $dosearch;
230
        my $dosearch;
Lines 276-281 sub SearchAuthorities { Link Here
276
                $q2 .=$attr;
282
                $q2 .=$attr;
277
                $dosearch=1;
283
                $dosearch=1;
278
                ++$attr_cnt;
284
                ++$attr_cnt;
285
                if ($QParser) {
286
                    $qpquery .= " $tags->[$i]:$value->[$i]";
287
                }
279
            }#if value
288
            }#if value
280
        }
289
        }
281
        ##Add how many queries generated
290
        ##Add how many queries generated
Lines 296-303 sub SearchAuthorities { Link Here
296
        } elsif ($sortby eq 'AuthidDsc') {
305
        } elsif ($sortby eq 'AuthidDsc') {
297
            $orderstring = '@attr 7=2 @attr 4=109 @attr 1=Local-Number 0';
306
            $orderstring = '@attr 7=2 @attr 4=109 @attr 1=Local-Number 0';
298
        }
307
        }
299
        $query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
308
        if ($QParser) {
300
        $query="\@or $orderstring $query" if $orderstring;
309
            $qpquery .= ' all:all' unless $value->[0];
310
311
            if ( $value->[0] =~ m/^qp=(.*)$/ ) {
312
                $qpquery = $1;
313
            }
314
315
            $qpquery .= " #$sortby";
316
317
            $QParser->parse( $qpquery );
318
            $query = $QParser->target_syntax('authorityserver');
319
        } else {
320
            $query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
321
            $query="\@or $orderstring $query" if $orderstring;
322
        }
301
323
302
        $offset=0 unless $offset;
324
        $offset=0 unless $offset;
303
        my $counter = $offset;
325
        my $counter = $offset;
Lines 406-412 sub CountUsage { Link Here
406
    } else {
428
    } else {
407
        ### ZOOM search here
429
        ### ZOOM search here
408
        my $query;
430
        my $query;
409
        $query= "an=".$authid;
431
        $query= "an:".$authid;
410
  		my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
432
  		my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
411
        if ($err) {
433
        if ($err) {
412
            warn "Error: $err from search $query";
434
            warn "Error: $err from search $query";
Lines 911-921 sub FindDuplicateAuthority { Link Here
911
    $sth->finish;
933
    $sth->finish;
912
#     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
934
#     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
913
    # build a request for SearchAuthorities
935
    # build a request for SearchAuthorities
914
    my $query='at='.$authtypecode.' ';
936
    my $QParser;
937
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
938
    my $op;
939
    if ($QParser) {
940
        $op = '&&';
941
    } else {
942
        $op = 'and';
943
    }
944
    my $query='at:'.$authtypecode.' ';
915
    my $filtervalues=qr([\001-\040\!\'\"\`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
945
    my $filtervalues=qr([\001-\040\!\'\"\`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
916
    if ($record->field($auth_tag_to_report)) {
946
    if ($record->field($auth_tag_to_report)) {
917
      foreach ($record->field($auth_tag_to_report)->subfields()) {
947
      foreach ($record->field($auth_tag_to_report)->subfields()) {
918
        $_->[1]=~s/$filtervalues/ /g; $query.= " and he,wrdl=\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
948
        $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
919
      }
949
      }
920
    }
950
    }
921
    my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
951
    my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
(-)a/C4/Matcher.pm (-24 / +31 lines)
Lines 626-631 sub get_matches { Link Here
626
626
627
    my %matches = ();
627
    my %matches = ();
628
628
629
    my $QParser;
630
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
629
    foreach my $matchpoint (@{ $self->{'matchpoints'} }) {
631
    foreach my $matchpoint (@{ $self->{'matchpoints'} }) {
630
        my @source_keys = _get_match_keys($source_record, $matchpoint);
632
        my @source_keys = _get_match_keys($source_record, $matchpoint);
631
        next if scalar(@source_keys) == 0;
633
        next if scalar(@source_keys) == 0;
Lines 634-664 sub get_matches { Link Here
634
        my $error;
636
        my $error;
635
        my $searchresults;
637
        my $searchresults;
636
        my $total_hits;
638
        my $total_hits;
637
        if ($self->{'record_type'} eq 'biblio') {
639
        if ($QParser) {
638
            $query = join(" or ", map { "$matchpoint->{'index'}=$_" } @source_keys);
640
            $query = join(" || ", map { "$matchpoint->{'index'}:$_" } @source_keys);
639
# FIXME only searching biblio index at the moment
640
            require C4::Search;
641
            require C4::Search;
641
            ($error, $searchresults, $total_hits) = C4::Search::SimpleSearch($query, 0, $max_matches);
642
            ($error, $searchresults, $total_hits) = C4::Search::SimpleSearch($query, 0, $max_matches, [ $self->{'record_type'} . 'server' ] );
642
        } elsif ($self->{'record_type'} eq 'authority') {
643
        } else {
643
            my $authresults;
644
            if ($self->{'record_type'} eq 'biblio') {
644
            my @marclist;
645
                $query = join(" or ", map { "$matchpoint->{'index'}=$_" } @source_keys);
645
            my @and_or;
646
                require C4::Search;
646
            my @excluding = [];
647
                ($error, $searchresults, $total_hits) = C4::Search::SimpleSearch($query, 0, $max_matches);
647
            my @operator;
648
            } elsif ($self->{'record_type'} eq 'authority') {
648
            my @value;
649
                my $authresults;
649
            foreach my $key (@source_keys) {
650
                my @marclist;
650
                push @marclist, $matchpoint->{'index'};
651
                my @and_or;
651
                push @and_or, 'or';
652
                my @excluding = [];
652
                push @operator, 'exact';
653
                my @operator;
653
                push @value, $key;
654
                my @value;
654
            }
655
                foreach my $key (@source_keys) {
655
            require C4::AuthoritiesMarc;
656
                    push @marclist, $matchpoint->{'index'};
656
            ($authresults, $total_hits) = C4::AuthoritiesMarc::SearchAuthorities(
657
                    push @and_or, 'or';
657
                    \@marclist, \@and_or, \@excluding, \@operator,
658
                    push @operator, 'exact';
658
                    \@value, 0, 20, undef, 'AuthidAsc', 1
659
                    push @value, $key;
659
            );
660
                }
660
            foreach my $result (@$authresults) {
661
                require C4::AuthoritiesMarc;
661
                push @$searchresults, $result->{'authid'};
662
                ($authresults, $total_hits) = C4::AuthoritiesMarc::SearchAuthorities(
663
                        \@marclist, \@and_or, \@excluding, \@operator,
664
                        \@value, 0, 20, undef, 'AuthidAsc', 1
665
                        );
666
                foreach my $result (@$authresults) {
667
                    push @$searchresults, $result->{'authid'};
668
                }
662
            }
669
            }
663
        }
670
        }
664
671
(-)a/C4/Search.pm (-36 / +77 lines)
Lines 100-108 sub FindDuplicate { Link Here
100
    if ( $result->{isbn} ) {
100
    if ( $result->{isbn} ) {
101
        $result->{isbn} =~ s/\(.*$//;
101
        $result->{isbn} =~ s/\(.*$//;
102
        $result->{isbn} =~ s/\s+$//;
102
        $result->{isbn} =~ s/\s+$//;
103
        $query = "isbn=$result->{isbn}";
103
        $query = "isbn:$result->{isbn}";
104
    }
104
    }
105
    else {
105
    else {
106
        my $QParser;
107
        $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
108
        my $titleindex;
109
        my $authorindex;
110
        my $op;
111
112
        if ($QParser) {
113
            $titleindex = 'title|exact';
114
            $authorindex = 'author|exact';
115
            $op = '&&';
116
        } else {
117
            $titleindex = 'ti,ext';
118
            $authorindex = 'au,ext';
119
            $op = 'and';
120
        }
121
106
        $result->{title} =~ s /\\//g;
122
        $result->{title} =~ s /\\//g;
107
        $result->{title} =~ s /\"//g;
123
        $result->{title} =~ s /\"//g;
108
        $result->{title} =~ s /\(//g;
124
        $result->{title} =~ s /\(//g;
Lines 111-117 sub FindDuplicate { Link Here
111
        # FIXME: instead of removing operators, could just do
127
        # FIXME: instead of removing operators, could just do
112
        # quotes around the value
128
        # quotes around the value
113
        $result->{title} =~ s/(and|or|not)//g;
129
        $result->{title} =~ s/(and|or|not)//g;
114
        $query = "ti,ext=$result->{title}";
130
        $query = "$titleindex:\"$result->{title}\"";
115
        if   ( $result->{author} ) {
131
        if   ( $result->{author} ) {
116
            $result->{author} =~ s /\\//g;
132
            $result->{author} =~ s /\\//g;
117
            $result->{author} =~ s /\"//g;
133
            $result->{author} =~ s /\"//g;
Lines 120-126 sub FindDuplicate { Link Here
120
136
121
            # remove valid operators
137
            # remove valid operators
122
            $result->{author} =~ s/(and|or|not)//g;
138
            $result->{author} =~ s/(and|or|not)//g;
123
            $query .= " and au,ext=$result->{author}";
139
            $query .= " $op $authorindex:\"$result->{author}\"";
124
        }
140
        }
125
    }
141
    }
126
142
Lines 224-234 sub SimpleSearch { Link Here
224
        my $results = [];
240
        my $results = [];
225
        my $total_hits = 0;
241
        my $total_hits = 0;
226
242
243
        my $QParser;
244
        $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') && ! ($query =~ m/\w,\w|\w=\w/));
245
227
        # Initialize & Search Zebra
246
        # Initialize & Search Zebra
228
        for ( my $i = 0 ; $i < @servers ; $i++ ) {
247
        for ( my $i = 0 ; $i < @servers ; $i++ ) {
229
            eval {
248
            eval {
230
                $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
249
                $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
231
                $zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]);
250
                if ($QParser) {
251
                    $query =~ s/=/:/g;
252
                    $QParser->parse( $query );
253
                    $query = $QParser->target_syntax($servers[$i]);
254
                    $zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]);
255
                } else {
256
                    $zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]);
257
                }
232
                $tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] );
258
                $tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] );
233
259
234
                # error handling
260
                # error handling
Lines 1091-1097 on authority data). Link Here
1091
=cut
1117
=cut
1092
1118
1093
sub _handle_exploding_index {
1119
sub _handle_exploding_index {
1094
    my ( $index, $term ) = @_;
1120
    my ($QParser, $struct, $filter, $params, $negate, $server) = @_;
1121
    my $index = $filter;
1122
    my $term = join(' ', @$params);
1095
1123
1096
    return unless ($index =~ m/(su-br|su-na|su-rl)/ && $term);
1124
    return unless ($index =~ m/(su-br|su-na|su-rl)/ && $term);
1097
1125
Lines 1099-1106 sub _handle_exploding_index { Link Here
1099
1127
1100
    my $codesubfield = $marcflavour eq 'UNIMARC' ? '5' : 'w';
1128
    my $codesubfield = $marcflavour eq 'UNIMARC' ? '5' : 'w';
1101
    my $wantedcodes = '';
1129
    my $wantedcodes = '';
1102
    my @subqueries = ( "(su=\"$term\")");
1130
    my @subqueries = ( "su:\"$term\"");
1103
    my ($error, $results, $total_hits) = SimpleSearch( "Heading,wrdl=$term", undef, undef, [ "authorityserver" ] );
1131
    my ($error, $results, $total_hits) = SimpleSearch( "he:$term", undef, undef, [ "authorityserver" ] );
1104
    foreach my $auth (@$results) {
1132
    foreach my $auth (@$results) {
1105
        my $record = MARC::Record->new_from_usmarc($auth);
1133
        my $record = MARC::Record->new_from_usmarc($auth);
1106
        my @references = $record->field('5..');
1134
        my @references = $record->field('5..');
Lines 1114-1124 sub _handle_exploding_index { Link Here
1114
            }
1142
            }
1115
            foreach my $reference (@references) {
1143
            foreach my $reference (@references) {
1116
                my $codes = $reference->subfield($codesubfield);
1144
                my $codes = $reference->subfield($codesubfield);
1117
                push @subqueries, '(su="' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '")' if (($codes && $codes eq $wantedcodes) || !$wantedcodes);
1145
                push @subqueries, 'su:"' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '"' if (($codes && $codes eq $wantedcodes) || !$wantedcodes);
1118
            }
1146
            }
1119
        }
1147
        }
1120
    }
1148
    }
1121
    return join(' or ', @subqueries);
1149
    my $query = '(' x scalar(@subqueries) . join(') || ', @subqueries) . ')';
1150
    warn $query;
1151
    return $query;
1122
}
1152
}
1123
1153
1124
=head2 parseQuery
1154
=head2 parseQuery
Lines 1145-1181 sub parseQuery { Link Here
1145
    my $query = $operands[0];
1175
    my $query = $operands[0];
1146
    my $index;
1176
    my $index;
1147
    my $term;
1177
    my $term;
1178
    my $query_desc;
1148
1179
1149
# TODO: once we are using QueryParser, all this special case code for
1180
    my $QParser;
1150
#       exploded search indexes will be replaced by a callback to
1181
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') || $query =~ s/^qp=//);
1151
#       _handle_exploding_index
1182
    undef $QParser if ($query =~ m/^(ccl=|pqf=|cql=)/ || grep (/\w,\w|\w=\w/, @operands) );
1152
    if ( $query =~ m/^(.*)\b(su-br|su-na|su-rl)[:=](\w.*)$/ ) {
1183
1153
        $query = $1;
1184
    if ($QParser)
1154
        $index = $2;
1185
    {
1155
        $term  = $3;
1156
    } else {
1157
        $query = '';
1186
        $query = '';
1158
        for ( my $i = 0 ; $i <= @operands ; $i++ ) {
1187
        for ( my $ii = 0 ; $ii <= @operands ; $ii++ ) {
1159
            if ($operands[$i] && $indexes[$i] =~ m/(su-br|su-na|su-rl)/) {
1188
            next unless $operands[$ii];
1160
                $index = $indexes[$i];
1189
            $query .= $operators[ $ii - 1 ] eq 'or' ? ' || ' : ' && '
1161
                $term = $operands[$i];
1190
              if ($query);
1162
            } elsif ($operands[$i]) {
1191
            $query .=
1163
                $query .= $operators[$i] eq 'or' ? ' or ' : ' and ' if ($query);
1192
              ( $operators[$ii] ? "$operators[$ii]:" : '' ) . $operands[$ii];
1164
                $query .= "($indexes[$i]:$operands[$i])";
1193
        }
1165
            }
1194
        foreach my $limit (@limits) {
1195
        }
1196
        foreach my $modifier (@sort_by) {
1197
            $query .= " #$modifier";
1166
        }
1198
        }
1167
    }
1168
1199
1169
    if ($index) {
1200
        $query_desc = $query;
1170
        my $queryPart = _handle_exploding_index($index, $term);
1201
        if ( C4::Context->preference("QueryWeightFields") ) {
1171
        if ($queryPart) {
1172
            $query .= "($queryPart)";
1173
        }
1202
        }
1174
        $operators = ();
1203
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index });
1175
        $operands[0] = "ccl=$query";
1204
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-na', { 'callback' => \&_handle_exploding_index });
1205
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index });
1206
        $QParser->parse( $query );
1207
        $operands[0] = "pqf=" . $QParser->target_syntax('biblioserver');
1208
# TODO: once we are using QueryParser, all this special case code for
1209
#       exploded search indexes will be replaced by a callback to
1210
#       _handle_exploding_index
1176
    }
1211
    }
1177
1212
1178
    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang);
1213
    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc);
1179
}
1214
}
1180
1215
1181
=head2 buildQuery
1216
=head2 buildQuery
Lines 1199-1205 sub buildQuery { Link Here
1199
1234
1200
    warn "---------\nEnter buildQuery\n---------" if $DEBUG;
1235
    warn "---------\nEnter buildQuery\n---------" if $DEBUG;
1201
1236
1202
    ( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang) = parseQuery($operators, $operands, $indexes, $limits, $sort_by, $scan, $lang);
1237
    my $query_desc;
1238
    ( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc) = parseQuery($operators, $operands, $indexes, $limits, $sort_by, $scan, $lang);
1203
1239
1204
    # dereference
1240
    # dereference
1205
    my @operators = $operators ? @$operators : ();
1241
    my @operators = $operators ? @$operators : ();
Lines 1227-1233 sub buildQuery { Link Here
1227
1263
1228
    # initialize the variables we're passing back
1264
    # initialize the variables we're passing back
1229
    my $query_cgi;
1265
    my $query_cgi;
1230
    my $query_desc;
1231
    my $query_type;
1266
    my $query_type;
1232
1267
1233
    my $limit;
1268
    my $limit;
Lines 1262-1268 sub buildQuery { Link Here
1262
        return ( undef, $', $', "q=cql=$'", $', '', '', '', '', 'cql' );
1297
        return ( undef, $', $', "q=cql=$'", $', '', '', '', '', 'cql' );
1263
    }
1298
    }
1264
    if ( $query =~ /^pqf=/ ) {
1299
    if ( $query =~ /^pqf=/ ) {
1265
        return ( undef, $', $', "q=pqf=$'", $', '', '', '', '', 'pqf' );
1300
        if ($query_desc) {
1301
            $query_cgi = "q=$query_desc";
1302
        } else {
1303
            $query_desc = $';
1304
            $query_cgi = "q=pqf=$'";
1305
        }
1306
        return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' );
1266
    }
1307
    }
1267
1308
1268
    # pass nested queries directly
1309
    # pass nested queries directly
(-)a/Koha/SuggestionEngine/Plugin/AuthorityFile.pm (-1 / +1 lines)
Lines 85-91 sub get_suggestions { Link Here
85
    # FIXME: calling into C4
85
    # FIXME: calling into C4
86
    require C4::AuthoritiesMarc;
86
    require C4::AuthoritiesMarc;
87
    my ( $searchresults, $count ) = C4::AuthoritiesMarc::SearchAuthorities(
87
    my ( $searchresults, $count ) = C4::AuthoritiesMarc::SearchAuthorities(
88
        \@marclist,  \@and_or, \@excluding,       \@operator,
88
        @marclist,  @and_or, @excluding,       @operator,
89
        @value,      0,        $param->{'count'}, '',
89
        @value,      0,        $param->{'count'}, '',
90
        'Relevance', 0
90
        'Relevance', 0
91
    );
91
    );
(-)a/cataloguing/addbooks.pl (-2 / +8 lines)
Lines 70-79 if ($query) { Link Here
70
70
71
    # build query
71
    # build query
72
    my @operands = $query;
72
    my @operands = $query;
73
    my ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(undef,\@operands);
73
74
    my $QParser;
75
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
76
    unless ($QParser) {
77
        my ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(undef,\@operands);
78
        $query = $builtquery;
79
    }
74
80
75
    # find results
81
    # find results
76
    my ( $error, $marcresults, $total_hits ) = SimpleSearch($builtquery, $results_per_page * ($page - 1), $results_per_page);
82
    my ( $error, $marcresults, $total_hits ) = SimpleSearch($query, $results_per_page * ($page - 1), $results_per_page);
77
83
78
    if ( defined $error ) {
84
    if ( defined $error ) {
79
        $template->param( error => $error );
85
        $template->param( error => $error );
(-)a/cataloguing/value_builder/marc21_linking_section.pl (-1 / +9 lines)
Lines 190-196 sub plugin { Link Here
190
           my $startfrom      = $query->param('startfrom');
190
           my $startfrom      = $query->param('startfrom');
191
               my $resultsperpage = $query->param('resultsperpage') || 20;
191
               my $resultsperpage = $query->param('resultsperpage') || 20;
192
            my $orderby;
192
            my $orderby;
193
           $search = 'kw,wrdl=' . $search . ' and mc-itemtype=' . $itype if $itype;
193
            my $QParser;
194
            $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
195
            my $op;
196
            if ($QParser) {
197
                $op = '&&';
198
            } else {
199
                $op = 'and';
200
            }
201
           $search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype;
194
               my ( $errors, $results, $total_hits ) =
202
               my ( $errors, $results, $total_hits ) =
195
                  SimpleSearch( $search, $startfrom * $resultsperpage,
203
                  SimpleSearch( $search, $startfrom * $resultsperpage,
196
                 $resultsperpage );
204
                 $resultsperpage );
(-)a/cataloguing/value_builder/unimarc_field_4XX.pl (-1 / +9 lines)
Lines 341-347 sub plugin { Link Here
341
        my $startfrom      = $query->param('startfrom');
341
        my $startfrom      = $query->param('startfrom');
342
        my $resultsperpage = $query->param('resultsperpage') || 20;
342
        my $resultsperpage = $query->param('resultsperpage') || 20;
343
        my $orderby;
343
        my $orderby;
344
        $search = 'kw,wrdl='.$search.' and mc-itemtype='.$itype if $itype;
344
        my $QParser;
345
        $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
346
        my $op;
347
        if ($QParser) {
348
            $op = '&&';
349
        } else {
350
            $op = 'and';
351
        }
352
        $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
345
        my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage );
353
        my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage );
346
        if (defined $errors ) {
354
        if (defined $errors ) {
347
            $results = [];
355
            $results = [];
(-)a/labels/label-item-search.pl (-6 / +19 lines)
Lines 66-75 my $display_columns = [ {_add => {label => "Add Item", link_fi Link Here
66
                      ];
66
                      ];
67
67
68
if ( $op eq "do_search" ) {
68
if ( $op eq "do_search" ) {
69
    my $QParser;
70
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
69
    $idx         = $query->param('idx');
71
    $idx         = $query->param('idx');
70
    $ccl_textbox = $query->param('ccl_textbox');
72
    $ccl_textbox = $query->param('ccl_textbox');
71
    if ( $ccl_textbox && $idx ) {
73
    if ( $ccl_textbox && $idx ) {
72
        $ccl_query = "$idx=$ccl_textbox";
74
        $ccl_query = "$idx:$ccl_textbox";
73
    }
75
    }
74
76
75
    $datefrom = $query->param('datefrom');
77
    $datefrom = $query->param('datefrom');
Lines 77-91 if ( $op eq "do_search" ) { Link Here
77
79
78
    if ($datefrom) {
80
    if ($datefrom) {
79
        $datefrom = C4::Dates->new($datefrom);
81
        $datefrom = C4::Dates->new($datefrom);
80
        $ccl_query .= ' and ' if $ccl_textbox;
82
        if ($QParser) {
81
        $ccl_query .=
83
            $ccl_query .= ' && ' if $ccl_textbox;
82
          "acqdate,st-date-normalized,ge=" . $datefrom->output("iso");
84
            $ccl_query .=
85
                "acqdate(" . $datefrom->output("iso") . '-)';
86
        } else {
87
            $ccl_query .= ' and ' if $ccl_textbox;
88
            $ccl_query .=
89
                "acqdate,st-date-normalized,ge=" . $datefrom->output("iso");
90
        }
83
    }
91
    }
84
92
85
    if ($dateto) {
93
    if ($dateto) {
86
        $dateto = C4::Dates->new($dateto);
94
        $dateto = C4::Dates->new($dateto);
87
        $ccl_query .= ' and ' if ( $ccl_textbox || $datefrom );
95
        if ($QParser) {
88
        $ccl_query .= "acqdate,st-date-normalized,le=" . $dateto->output("iso");
96
            $ccl_query .= ' && ' if ( $ccl_textbox || $datefrom );
97
            $ccl_query .= "acqdate(-" . $dateto->output("iso") . ')';
98
        } else {
99
            $ccl_query .= ' and ' if ( $ccl_textbox || $datefrom );
100
            $ccl_query .= "acqdate,st-date-normalized,le=" . $datefrom->output("iso");
101
        }
89
    }
102
    }
90
103
91
    my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
104
    my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
(-)a/misc/migration_tools/bulkmarcimport.pl (-3 / +19 lines)
Lines 432-438 sub build_query { Link Here
432
	  my $string = build_simplequery($matchingpoint,$record);
432
	  my $string = build_simplequery($matchingpoint,$record);
433
	  push @searchstrings,$string if (length($string)>0);
433
	  push @searchstrings,$string if (length($string)>0);
434
        }
434
        }
435
	return join(" and ",@searchstrings);
435
    my $QParser;
436
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
437
    my $op;
438
    if ($QParser) {
439
        $op = '&&';
440
    } else {
441
        $op = 'and';
442
    }
443
    return join(" $op ",@searchstrings);
436
}
444
}
437
sub build_simplequery {
445
sub build_simplequery {
438
	my $element=shift;
446
	my $element=shift;
Lines 442-451 sub build_simplequery { Link Here
442
        my @searchstrings;
450
        my @searchstrings;
443
        foreach my $field ($record->field($tag)){
451
        foreach my $field ($record->field($tag)){
444
		  if (length($field->as_string("$subfields"))>0){
452
		  if (length($field->as_string("$subfields"))>0){
445
          	push @searchstrings,"$index,wrdl=\"".$field->as_string("$subfields")."\"";
453
              push @searchstrings,"$index:\"".$field->as_string("$subfields")."\"";
446
		  }
454
		  }
447
        }
455
        }
448
	return join(" and ",@searchstrings);
456
    my $QParser;
457
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
458
    my $op;
459
    if ($QParser) {
460
        $op = '&&';
461
    } else {
462
        $op = 'and';
463
    }
464
    return join(" $op ",@searchstrings);
449
}
465
}
450
sub report_item_errors {
466
sub report_item_errors {
451
    my $biblionumber = shift;
467
    my $biblionumber = shift;
(-)a/serials/subscription-bib-search.pl (-5 / +13 lines)
Lines 90-100 if ($op eq "do_search" && $query) { Link Here
90
    # add the itemtype limit if applicable
90
    # add the itemtype limit if applicable
91
    my $itemtypelimit = $input->param('itemtypelimit');
91
    my $itemtypelimit = $input->param('itemtypelimit');
92
    if ( $itemtypelimit ) {
92
    if ( $itemtypelimit ) {
93
	if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
93
        my $QParser;
94
	    $query .= " AND $itype_or_itemtype=$itemtypelimit";
94
        $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
95
	} else {
95
        my $op;
96
	    $query .= " AND $advanced_search_types=$itemtypelimit";
96
        if ($QParser) {
97
	}
97
            $op = '&&';
98
        } else {
99
            $op = 'and';
100
        }
101
        if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
102
            $query .= " $op $itype_or_itemtype:$itemtypelimit";
103
        } else {
104
            $query .= " $op $advanced_search_types:$itemtypelimit";
105
        }
98
    }
106
    }
99
    $debug && warn $query;
107
    $debug && warn $query;
100
    $resultsperpage= $input->param('resultsperpage');
108
    $resultsperpage= $input->param('resultsperpage');
(-)a/t/db_dependent/Search.t (-7 / +15 lines)
Lines 32-37 my $QueryAutoTruncate = 0; Link Here
32
my $QueryWeightFields = 0;
32
my $QueryWeightFields = 0;
33
my $QueryFuzzy = 0;
33
my $QueryFuzzy = 0;
34
my $QueryRemoveStopwords = 0;
34
my $QueryRemoveStopwords = 0;
35
my $UseQueryParser = 0;
35
my $contextmodule = new Test::MockModule('C4::Context');
36
my $contextmodule = new Test::MockModule('C4::Context');
36
$contextmodule->mock('_new_dbh', sub {
37
$contextmodule->mock('_new_dbh', sub {
37
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
38
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
Lines 53-58 $contextmodule->mock('preference', sub { Link Here
53
        return $QueryFuzzy;
54
        return $QueryFuzzy;
54
    } elsif ($pref eq 'QueryRemoveStopwords') {
55
    } elsif ($pref eq 'QueryRemoveStopwords') {
55
        return $QueryRemoveStopwords;
56
        return $QueryRemoveStopwords;
57
    } elsif ($pref eq 'UseQueryParser') {
58
        return $UseQueryParser;
56
    } elsif ($pref eq 'maxRecordsForFacets') {
59
    } elsif ($pref eq 'maxRecordsForFacets') {
57
        return 20;
60
        return 20;
58
    } elsif ($pref eq 'FacetLabelTruncationLength') {
61
    } elsif ($pref eq 'FacetLabelTruncationLength') {
Lines 109-114 $contextmodule->mock('marcfromkohafield', sub { Link Here
109
        );
112
        );
110
        return \%hash;
113
        return \%hash;
111
});
114
});
115
$contextmodule->mock('queryparser', sub {
116
    my $QParser     = Koha::QueryParser::Driver::PQF->new();
117
    $QParser->load_config("$datadir/etc/searchengine/queryparser.yaml");
118
    return $QParser;
119
});
112
my $context = new C4::Context("$datadir/etc/koha-conf.xml");
120
my $context = new C4::Context("$datadir/etc/koha-conf.xml");
113
$context->set_context();
121
$context->set_context();
114
122
Lines 521-527 my $searchmodule = new Test::MockModule('C4::Search'); Link Here
521
$searchmodule->mock('SimpleSearch', sub {
529
$searchmodule->mock('SimpleSearch', sub {
522
    my $query = shift;
530
    my $query = shift;
523
531
524
    is($query, "Heading,wrdl=$term", "Searching for expected term '$term' for exploding") or return '', [], 0;
532
    is($query, "he:$term", "Searching for expected term '$term' for exploding") or return '', [], 0;
525
533
526
    my $record = MARC::Record->new;
534
    my $record = MARC::Record->new;
527
    if ($query =~ m/Arizona/) {
535
    if ($query =~ m/Arizona/) {
Lines 538-543 $searchmodule->mock('SimpleSearch', sub { Link Here
538
    return '', [ $record->as_usmarc() ], 1;
546
    return '', [ $record->as_usmarc() ], 1;
539
});
547
});
540
548
549
$UseQueryParser = 1;
541
$term = 'Arizona';
550
$term = 'Arizona';
542
( $error, $query, $simple_query, $query_cgi,
551
( $error, $query, $simple_query, $query_cgi,
543
$query_desc, $limit, $limit_cgi, $limit_desc,
552
$query_desc, $limit, $limit_cgi, $limit_desc,
Lines 568-595 like($query, qr/history/, "Order of terms doesn't matter for advanced search"); Link Here
568
577
569
( $error, $query, $simple_query, $query_cgi,
578
( $error, $query, $simple_query, $query_cgi,
570
$query_desc, $limit, $limit_cgi, $limit_desc,
579
$query_desc, $limit, $limit_cgi, $limit_desc,
571
$stopwords_removed, $query_type ) = buildQuery([], [ "su-br:$term" ], [  ], [  ], [], 0, 'en');
580
$stopwords_removed, $query_type ) = buildQuery([], [ "su-br($term)" ], [  ], [  ], [], 0, 'en');
572
matchesExplodedTerms("Simple search for broader subjects", $query, 'Arizona', 'United States');
581
matchesExplodedTerms("Simple search for broader subjects", $query, 'Arizona', 'United States');
573
582
574
( $error, $query, $simple_query, $query_cgi,
583
( $error, $query, $simple_query, $query_cgi,
575
$query_desc, $limit, $limit_cgi, $limit_desc,
584
$query_desc, $limit, $limit_cgi, $limit_desc,
576
$stopwords_removed, $query_type ) = buildQuery([], [ "su-na:$term" ], [  ], [  ], [], 0, 'en');
585
$stopwords_removed, $query_type ) = buildQuery([], [ "su-na($term)" ], [  ], [  ], [], 0, 'en');
577
matchesExplodedTerms("Simple search for narrower subjects", $query, 'Arizona', 'Maricopa County', 'Navajo County', 'Pima County');
586
matchesExplodedTerms("Simple search for narrower subjects", $query, 'Arizona', 'Maricopa County', 'Navajo County', 'Pima County');
578
587
579
( $error, $query, $simple_query, $query_cgi,
588
( $error, $query, $simple_query, $query_cgi,
580
$query_desc, $limit, $limit_cgi, $limit_desc,
589
$query_desc, $limit, $limit_cgi, $limit_desc,
581
$stopwords_removed, $query_type ) = buildQuery([], [ "su-rl:$term" ], [  ], [  ], [], 0, 'en');
590
$stopwords_removed, $query_type ) = buildQuery([], [ "su-rl($term)" ], [  ], [  ], [], 0, 'en');
582
matchesExplodedTerms("Simple search for related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
591
matchesExplodedTerms("Simple search for related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
583
592
584
( $error, $query, $simple_query, $query_cgi,
593
( $error, $query, $simple_query, $query_cgi,
585
$query_desc, $limit, $limit_cgi, $limit_desc,
594
$query_desc, $limit, $limit_cgi, $limit_desc,
586
$stopwords_removed, $query_type ) = buildQuery([], [ "history and su-rl:$term" ], [  ], [  ], [], 0, 'en');
595
$stopwords_removed, $query_type ) = buildQuery([], [ "history && su-rl($term)" ], [  ], [  ], [], 0, 'en');
587
matchesExplodedTerms("Simple search for related subjects and keyword 'history' searches related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
596
matchesExplodedTerms("Simple search for related subjects and keyword 'history' searches related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
588
like($query, qr/history/, "Simple search for related subjects and keyword 'history' searches for 'history'");
597
like($query, qr/history/, "Simple search for related subjects and keyword 'history' searches for 'history'");
589
598
590
sub matchesExplodedTerms {
599
sub matchesExplodedTerms {
591
    my ($message, $query, @terms) = @_;
600
    my ($message, $query, @terms) = @_;
592
    my $match = "(( or )?\\((" . join ('|', map { "su=\"$_\"" } @terms) . ")\\)){" . scalar(@terms) . "}";
601
    my $match = '(' . join ('|', map { " \@attr 1=Subject \@attr 4=1 \"$_\"" } @terms) . "){" . scalar(@terms) . "}";
593
    like($query, qr/$match/, $message);
602
    like($query, qr/$match/, $message);
594
}
603
}
595
604
596
- 

Return to bug 9239