Lines 111-123
sub build_query {
Link Here
|
111 |
# See _convert_facets in Search.pm for how these get turned into |
111 |
# See _convert_facets in Search.pm for how these get turned into |
112 |
# things that Koha can use. |
112 |
# things that Koha can use. |
113 |
$res->{aggregations} = { |
113 |
$res->{aggregations} = { |
114 |
author => { terms => { field => "author__facet" } }, |
114 |
author => { terms => { field => "author__facet" } }, |
115 |
subject => { terms => { field => "subject__facet" } }, |
115 |
subject => { terms => { field => "subject__facet" } }, |
116 |
itype => { terms => { field => "itype__facet" } }, |
116 |
itype => { terms => { field => "itype__facet" } }, |
117 |
location => { terms => { field => "location__facet" } }, |
117 |
location => { terms => { field => "location__facet" } }, |
118 |
'su-geo' => { terms => { field => "su-geo__facet" } }, |
118 |
'su-geo' => { terms => { field => "su-geo__facet" } }, |
119 |
se => { terms => { field => "se__facet" } }, |
119 |
'title-series' => { terms => { field => "title-series__facet" } }, |
120 |
ccode => { terms => { field => "ccode__facet" } }, |
120 |
ccode => { terms => { field => "ccode__facet" } }, |
121 |
}; |
121 |
}; |
122 |
|
122 |
|
123 |
my $display_library_facets = C4::Context->preference('DisplayLibraryFacets'); |
123 |
my $display_library_facets = C4::Context->preference('DisplayLibraryFacets'); |
Lines 411-422
appropriate search object.
Link Here
|
411 |
=cut |
411 |
=cut |
412 |
|
412 |
|
413 |
our $koha_to_index_name = { |
413 |
our $koha_to_index_name = { |
414 |
mainmainentry => 'Heading-Main', |
414 |
mainmainentry => 'heading-main', |
415 |
mainentry => 'Heading', |
415 |
mainentry => 'heading', |
416 |
match => 'Match', |
416 |
match => 'match', |
417 |
'match-heading' => 'Match-heading', |
417 |
'match-heading' => 'match-heading', |
418 |
'see-from' => 'Match-heading-see-from', |
418 |
'see-from' => 'match-heading-see-from', |
419 |
thesaurus => 'Subject-heading-thesaurus', |
419 |
thesaurus => 'subject-heading-thesaurus', |
420 |
any => '', |
420 |
any => '', |
421 |
all => '' |
421 |
all => '' |
422 |
}; |
422 |
}; |
Lines 430-435
sub build_authorities_query_compat {
Link Here
|
430 |
# extensible hash form that is understood by L<build_authorities_query>. |
430 |
# extensible hash form that is understood by L<build_authorities_query>. |
431 |
my @searches; |
431 |
my @searches; |
432 |
|
432 |
|
|
|
433 |
# Convert to lower case |
434 |
$marclist = [map(lc, @{$marclist})]; |
435 |
|
433 |
# Make sure everything exists |
436 |
# Make sure everything exists |
434 |
foreach my $m (@$marclist) { |
437 |
foreach my $m (@$marclist) { |
435 |
Koha::Exceptions::WrongParameter->throw("Invalid marclist field provided: $m") |
438 |
Koha::Exceptions::WrongParameter->throw("Invalid marclist field provided: $m") |
Lines 447-454
sub build_authorities_query_compat {
Link Here
|
447 |
|
450 |
|
448 |
my %sort; |
451 |
my %sort; |
449 |
my $sort_field = |
452 |
my $sort_field = |
450 |
( $orderby =~ /^Heading/ ) ? 'Heading' |
453 |
( $orderby =~ /^heading/ ) ? 'heading' |
451 |
: ( $orderby =~ /^Auth/ ) ? 'Local-number' |
454 |
: ( $orderby =~ /^auth/ ) ? 'local-number' |
452 |
: undef; |
455 |
: undef; |
453 |
if ($sort_field) { |
456 |
if ($sort_field) { |
454 |
my $sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc'; |
457 |
my $sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc'; |
Lines 479-491
sub _convert_sort_fields {
Link Here
|
479 |
|
482 |
|
480 |
# Turn the sorting into something we care about. |
483 |
# Turn the sorting into something we care about. |
481 |
my %sort_field_convert = ( |
484 |
my %sort_field_convert = ( |
482 |
acqdate => 'acqdate', |
485 |
acqdate => 'date-of-acquisition', |
483 |
author => 'author', |
486 |
author => 'author', |
484 |
call_number => 'callnum', |
487 |
call_number => 'local-classification', |
485 |
popularity => 'issues', |
488 |
popularity => 'issues', |
486 |
relevance => undef, # default |
489 |
relevance => undef, # default |
487 |
title => 'title', |
490 |
title => 'title', |
488 |
pubdate => 'pubdate', |
491 |
pubdate => 'date-of-publication', |
489 |
); |
492 |
); |
490 |
my %sort_order_convert = |
493 |
my %sort_order_convert = |
491 |
( qw( desc desc ), qw( dsc desc ), qw( asc asc ), qw( az asc ), qw( za desc ) ); |
494 |
( qw( desc desc ), qw( dsc desc ), qw( asc asc ), qw( az asc ), qw( za desc ) ); |
Lines 515-537
types.
Link Here
|
515 |
=cut |
518 |
=cut |
516 |
|
519 |
|
517 |
our %index_field_convert = ( |
520 |
our %index_field_convert = ( |
518 |
'kw' => '_all', |
521 |
'kw' => '_all', |
519 |
'ti' => 'title', |
522 |
'ab' => 'abstract', |
520 |
'au' => 'author', |
523 |
'au' => 'author', |
521 |
'su' => 'subject', |
524 |
'lcn' => 'local-classification', |
522 |
'nb' => 'isbn', |
525 |
'callnum' => 'local-classification', |
523 |
'se' => 'title-series', |
526 |
'record-type' => 'rtype', |
524 |
'callnum' => 'callnum', |
527 |
'mc-rtype' => 'rtype', |
525 |
'itype' => 'itype', |
528 |
'mus' => 'rtype', |
526 |
'ln' => 'ln', |
529 |
'lc-card' => 'lc-card-number', |
527 |
'branch' => 'homebranch', |
530 |
'sn' => 'local-number', |
528 |
'fic' => 'lf', |
531 |
'yr' => 'date-of-publication', |
529 |
'mus' => 'rtype', |
532 |
'pubdate' => 'date-of-publication', |
530 |
'aud' => 'ta', |
533 |
'acqdate' => 'date-of-acquisition', |
531 |
'hi' => 'Host-Item-Number', |
534 |
'date/time-last-modified' => 'date-time-last-modified', |
532 |
'at' => 'authtype', |
535 |
'dtlm' => 'date/time-last-modified', |
533 |
'he' => 'Heading' |
536 |
'diss' => 'dissertation-information', |
|
|
537 |
'nb' => 'isbn', |
538 |
'ns' => 'issn', |
539 |
'music-number' => 'identifier-publisher-for-music', |
540 |
'number-music-publisher' => 'identifier-publisher-for-music', |
541 |
'music' => 'identifier-publisher-for-music', |
542 |
'ident' => 'identifier-standard', |
543 |
'cpn' => 'corporate-name', |
544 |
'cfn' => 'conference-name', |
545 |
'pn' => 'personal-name', |
546 |
'pb' => 'publisher', |
547 |
'pv' => 'provider', |
548 |
'nt' => 'note', |
549 |
'notes' => 'note', |
550 |
'rcn' => 'record-control-number', |
551 |
'su' => 'subject', |
552 |
'su-to' => 'subject', |
553 |
#'su-geo' => 'subject', |
554 |
'su-ut' => 'subject', |
555 |
'ti' => 'title', |
556 |
'se' => 'title-series', |
557 |
'ut' => 'title-uniform', |
558 |
'an' => 'authority-number', |
559 |
'koha-auth-number' => 'authority-number', |
560 |
'at' => 'authtype', |
561 |
'he' => 'heading', |
562 |
'rank' => 'relevance', |
563 |
'phr' => 'st-phrase', |
564 |
'wrdl' => 'st-word-list', |
565 |
'rt' => 'right-truncation', |
566 |
'rtrn' => 'right-truncation', |
567 |
'ltrn' => 'left-truncation', |
568 |
'rltrn' => 'left-and-right', |
569 |
'mc-itemtype' => 'itemtype', |
570 |
'mc-ccode' => 'ccode', |
571 |
'branch' => 'homebranch', |
572 |
'mc-loc' => 'location', |
573 |
'stocknumber' => 'number-local-acquisition', |
574 |
'inv' => 'number-local-acquisition', |
575 |
'bc' => 'barcode', |
576 |
'mc-itype' => 'itype', |
577 |
'aub' => 'author-personal-bibliography', |
578 |
'auo' => 'author-in-order', |
579 |
'ff8-22' => 'ta', |
580 |
'aud' => 'ta', |
581 |
'audience' => 'ta', |
582 |
'frequency-code' => 'ff8-18', |
583 |
'illustration-code' => 'ff8-18-21', |
584 |
'regularity-code' => 'ff8-19', |
585 |
'type-of-serial' => 'ff8-21', |
586 |
'format' => 'ff8-23', |
587 |
'conference-code' => 'ff8-29', |
588 |
'festschrift-indicator' => 'ff8-30', |
589 |
'index-indicator' => 'ff8-31', |
590 |
'fiction' => 'lf', |
591 |
'fic' => 'lf', |
592 |
'literature-code' => 'lf', |
593 |
'biography' => 'bio', |
594 |
'ff8-34' => 'bio', |
595 |
'biography-code' => 'bio', |
596 |
'l-format' => 'ff7-01-02', |
597 |
'lex' => 'lexile-number', |
598 |
'hi' => 'host-item-number', |
599 |
'itu' => 'index-term-uncontrolled', |
600 |
'itg' => 'index-term-genre', |
534 |
); |
601 |
); |
|
|
602 |
my $field_name_pattern = '[\w\-]+'; |
603 |
my $multi_field_pattern = "(?:\\.$field_name_pattern)*"; |
535 |
|
604 |
|
536 |
sub _convert_index_fields { |
605 |
sub _convert_index_fields { |
537 |
my ( $self, @indexes ) = @_; |
606 |
my ( $self, @indexes ) = @_; |
Lines 544-557
sub _convert_index_fields {
Link Here
|
544 |
# when joining things, to indicate we make it an 'OR' join. |
613 |
# when joining things, to indicate we make it an 'OR' join. |
545 |
# (Sorry, this got a bit ugly after special cases were found.) |
614 |
# (Sorry, this got a bit ugly after special cases were found.) |
546 |
grep { $_->{field} } map { |
615 |
grep { $_->{field} } map { |
547 |
my ( $f, $t ) = split /,/; |
616 |
# Lower case all field names |
|
|
617 |
my ( $f, $t ) = map(lc, split /,/); |
548 |
my $mc = ''; |
618 |
my $mc = ''; |
549 |
if ($f =~ /^mc-/) { |
619 |
if ($f =~ /^mc-/) { |
550 |
$mc = 'mc-'; |
620 |
$mc = 'mc-'; |
551 |
$f =~ s/^mc-//; |
621 |
$f =~ s/^mc-//; |
552 |
} |
622 |
} |
553 |
my $r = { |
623 |
my $r = { |
554 |
field => $index_field_convert{$f}, |
624 |
field => exists $index_field_convert{$f} ? $index_field_convert{$f} : $f, |
555 |
type => $index_type_convert{ $t // '__default' } |
625 |
type => $index_type_convert{ $t // '__default' } |
556 |
}; |
626 |
}; |
557 |
$r->{field} = ($mc . $r->{field}) if $mc && $r->{field}; |
627 |
$r->{field} = ($mc . $r->{field}) if $mc && $r->{field}; |
Lines 606-614
will have to wait for a real query parser.
Link Here
|
606 |
|
676 |
|
607 |
sub _convert_index_strings_freeform { |
677 |
sub _convert_index_strings_freeform { |
608 |
my ( $self, $search ) = @_; |
678 |
my ( $self, $search ) = @_; |
609 |
while ( my ( $zeb, $es ) = each %index_field_convert ) { |
679 |
# @TODO: Currenty will alter also fields contained within quotes: |
610 |
$search =~ s/\b$zeb(?:,[\w\-]*)?:/$es:/g; |
680 |
# `searching for "stuff cn:123"` for example will become |
611 |
} |
681 |
# `searching for "stuff local-number:123" |
|
|
682 |
# |
683 |
# Fixing this is tricky, one possibility: |
684 |
# https://stackoverflow.com/questions/19193876/perl-regex-to-match-a-string-that-is-not-enclosed-in-quotes |
685 |
# Still not perfect, and will not handle escaped quotes within quotes and assumes balanced quotes. |
686 |
# |
687 |
# Another, not so elegant, solution could be to replace all quoted content with placeholders, and put |
688 |
# them back when processing is done. |
689 |
|
690 |
# Lower case field names |
691 |
$search =~ s/($field_name_pattern)(?:,[\w-]*)?($multi_field_pattern):/\L$1\E$2:/og; |
692 |
# Resolve possible field aliases |
693 |
$search =~ s/($field_name_pattern)($multi_field_pattern):/(exists $index_field_convert{$1} ? $index_field_convert{$1} : $1)."$2:"/oge; |
612 |
return $search; |
694 |
return $search; |
613 |
} |
695 |
} |
614 |
|
696 |
|
Lines 805-810
operands and double quoted strings.
Link Here
|
805 |
|
887 |
|
806 |
=cut |
888 |
=cut |
807 |
|
889 |
|
|
|
890 |
my $tokenize_split_re = qr/((?:${field_name_pattern}${multi_field_pattern}:)?"[^"]+"|\s+)/; |
808 |
sub _truncate_terms { |
891 |
sub _truncate_terms { |
809 |
my ( $self, $query ) = @_; |
892 |
my ( $self, $query ) = @_; |
810 |
|
893 |
|