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 405-416
appropriate search object.
Link Here
|
405 |
=cut |
405 |
=cut |
406 |
|
406 |
|
407 |
our $koha_to_index_name = { |
407 |
our $koha_to_index_name = { |
408 |
mainmainentry => 'Heading-Main', |
408 |
mainmainentry => 'heading-main', |
409 |
mainentry => 'Heading', |
409 |
mainentry => 'heading', |
410 |
match => 'Match', |
410 |
match => 'match', |
411 |
'match-heading' => 'Match-heading', |
411 |
'match-heading' => 'match-heading', |
412 |
'see-from' => 'Match-heading-see-from', |
412 |
'see-from' => 'match-heading-see-from', |
413 |
thesaurus => 'Subject-heading-thesaurus', |
413 |
thesaurus => 'subject-heading-thesaurus', |
414 |
any => '', |
414 |
any => '', |
415 |
all => '' |
415 |
all => '' |
416 |
}; |
416 |
}; |
Lines 424-429
sub build_authorities_query_compat {
Link Here
|
424 |
# extensible hash form that is understood by L<build_authorities_query>. |
424 |
# extensible hash form that is understood by L<build_authorities_query>. |
425 |
my @searches; |
425 |
my @searches; |
426 |
|
426 |
|
|
|
427 |
# Convert to lower case |
428 |
$marclist = [map(lc, @{$marclist})]; |
429 |
|
427 |
# Make sure everything exists |
430 |
# Make sure everything exists |
428 |
foreach my $m (@$marclist) { |
431 |
foreach my $m (@$marclist) { |
429 |
Koha::Exceptions::WrongParameter->throw("Invalid marclist field provided: $m") |
432 |
Koha::Exceptions::WrongParameter->throw("Invalid marclist field provided: $m") |
Lines 441-448
sub build_authorities_query_compat {
Link Here
|
441 |
|
444 |
|
442 |
my %sort; |
445 |
my %sort; |
443 |
my $sort_field = |
446 |
my $sort_field = |
444 |
( $orderby =~ /^Heading/ ) ? 'Heading' |
447 |
( $orderby =~ /^heading/ ) ? 'heading' |
445 |
: ( $orderby =~ /^Auth/ ) ? 'Local-number' |
448 |
: ( $orderby =~ /^auth/ ) ? 'local-number' |
446 |
: undef; |
449 |
: undef; |
447 |
if ($sort_field) { |
450 |
if ($sort_field) { |
448 |
my $sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc'; |
451 |
my $sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc'; |
Lines 473-485
sub _convert_sort_fields {
Link Here
|
473 |
|
476 |
|
474 |
# Turn the sorting into something we care about. |
477 |
# Turn the sorting into something we care about. |
475 |
my %sort_field_convert = ( |
478 |
my %sort_field_convert = ( |
476 |
acqdate => 'acqdate', |
479 |
acqdate => 'date-of-acquisition', |
477 |
author => 'author', |
480 |
author => 'author', |
478 |
call_number => 'callnum', |
481 |
call_number => 'local-classification', |
479 |
popularity => 'issues', |
482 |
popularity => 'issues', |
480 |
relevance => undef, # default |
483 |
relevance => undef, # default |
481 |
title => 'title', |
484 |
title => 'title', |
482 |
pubdate => 'pubdate', |
485 |
pubdate => 'date-of-publication', |
483 |
); |
486 |
); |
484 |
my %sort_order_convert = |
487 |
my %sort_order_convert = |
485 |
( qw( desc desc ), qw( dsc desc ), qw( asc asc ), qw( az asc ), qw( za desc ) ); |
488 |
( qw( desc desc ), qw( dsc desc ), qw( asc asc ), qw( az asc ), qw( za desc ) ); |
Lines 509-531
types.
Link Here
|
509 |
=cut |
512 |
=cut |
510 |
|
513 |
|
511 |
our %index_field_convert = ( |
514 |
our %index_field_convert = ( |
512 |
'kw' => '_all', |
515 |
'kw' => '_all', |
513 |
'ti' => 'title', |
516 |
'ab' => 'abstract', |
514 |
'au' => 'author', |
517 |
'au' => 'author', |
515 |
'su' => 'subject', |
518 |
'lcn' => 'local-classification', |
516 |
'nb' => 'isbn', |
519 |
'callnum' => 'local-classification', |
517 |
'se' => 'title-series', |
520 |
'record-type' => 'rtype', |
518 |
'callnum' => 'callnum', |
521 |
'mc-rtype' => 'rtype', |
519 |
'itype' => 'itype', |
522 |
'mus' => 'rtype', |
520 |
'ln' => 'ln', |
523 |
'lc-card' => 'lc-card-number', |
521 |
'branch' => 'homebranch', |
524 |
'sn' => 'local-number', |
522 |
'fic' => 'lf', |
525 |
'yr' => 'date-of-publication', |
523 |
'mus' => 'rtype', |
526 |
'pubdate' => 'date-of-publication', |
524 |
'aud' => 'ta', |
527 |
'acqdate' => 'date-of-acquisition', |
525 |
'hi' => 'Host-Item-Number', |
528 |
'date/time-last-modified' => 'date-time-last-modified', |
526 |
'at' => 'authtype', |
529 |
'dtlm' => 'date/time-last-modified', |
527 |
'he' => 'Heading' |
530 |
'diss' => 'dissertation-information', |
|
|
531 |
'nb' => 'isbn', |
532 |
'ns' => 'issn', |
533 |
'music-number' => 'identifier-publisher-for-music', |
534 |
'number-music-publisher' => 'identifier-publisher-for-music', |
535 |
'music' => 'identifier-publisher-for-music', |
536 |
'ident' => 'identifier-standard', |
537 |
'cpn' => 'corporate-name', |
538 |
'cfn' => 'conference-name', |
539 |
'pn' => 'personal-name', |
540 |
'pb' => 'publisher', |
541 |
'pv' => 'provider', |
542 |
'nt' => 'note', |
543 |
'notes' => 'note', |
544 |
'rcn' => 'record-control-number', |
545 |
'su' => 'subject', |
546 |
'su-to' => 'subject', |
547 |
#'su-geo' => 'subject', |
548 |
'su-ut' => 'subject', |
549 |
'ti' => 'title', |
550 |
'se' => 'title-series', |
551 |
'ut' => 'title-uniform', |
552 |
'an' => 'authority-number', |
553 |
'koha-auth-number' => 'authority-number', |
554 |
'at' => 'authtype', |
555 |
'he' => 'heading', |
556 |
'rank' => 'relevance', |
557 |
'phr' => 'st-phrase', |
558 |
'wrdl' => 'st-word-list', |
559 |
'rt' => 'right-truncation', |
560 |
'rtrn' => 'right-truncation', |
561 |
'ltrn' => 'left-truncation', |
562 |
'rltrn' => 'left-and-right', |
563 |
'mc-itemtype' => 'itemtype', |
564 |
'mc-ccode' => 'ccode', |
565 |
'branch' => 'homebranch', |
566 |
'mc-loc' => 'location', |
567 |
'stocknumber' => 'number-local-acquisition', |
568 |
'inv' => 'number-local-acquisition', |
569 |
'bc' => 'barcode', |
570 |
'mc-itype' => 'itype', |
571 |
'aub' => 'author-personal-bibliography', |
572 |
'auo' => 'author-in-order', |
573 |
'ff8-22' => 'ta', |
574 |
'aud' => 'ta', |
575 |
'audience' => 'ta', |
576 |
'frequency-code' => 'ff8-18', |
577 |
'illustration-code' => 'ff8-18-21', |
578 |
'regularity-code' => 'ff8-19', |
579 |
'type-of-serial' => 'ff8-21', |
580 |
'format' => 'ff8-23', |
581 |
'conference-code' => 'ff8-29', |
582 |
'festschrift-indicator' => 'ff8-30', |
583 |
'index-indicator' => 'ff8-31', |
584 |
'fiction' => 'lf', |
585 |
'fic' => 'lf', |
586 |
'literature-code' => 'lf', |
587 |
'biography' => 'bio', |
588 |
'ff8-34' => 'bio', |
589 |
'biography-code' => 'bio', |
590 |
'l-format' => 'ff7-01-02', |
591 |
'lex' => 'lexile-number', |
592 |
'hi' => 'host-item-number', |
593 |
'itu' => 'index-term-uncontrolled', |
594 |
'itg' => 'index-term-genre', |
528 |
); |
595 |
); |
|
|
596 |
my $field_name_pattern = '[\w\-]+'; |
597 |
my $multi_field_pattern = "(?:\\.$field_name_pattern)*"; |
529 |
|
598 |
|
530 |
sub _convert_index_fields { |
599 |
sub _convert_index_fields { |
531 |
my ( $self, @indexes ) = @_; |
600 |
my ( $self, @indexes ) = @_; |
Lines 538-551
sub _convert_index_fields {
Link Here
|
538 |
# when joining things, to indicate we make it an 'OR' join. |
607 |
# when joining things, to indicate we make it an 'OR' join. |
539 |
# (Sorry, this got a bit ugly after special cases were found.) |
608 |
# (Sorry, this got a bit ugly after special cases were found.) |
540 |
grep { $_->{field} } map { |
609 |
grep { $_->{field} } map { |
541 |
my ( $f, $t ) = split /,/; |
610 |
# Lower case all field names |
|
|
611 |
my ( $f, $t ) = map(lc, split /,/); |
542 |
my $mc = ''; |
612 |
my $mc = ''; |
543 |
if ($f =~ /^mc-/) { |
613 |
if ($f =~ /^mc-/) { |
544 |
$mc = 'mc-'; |
614 |
$mc = 'mc-'; |
545 |
$f =~ s/^mc-//; |
615 |
$f =~ s/^mc-//; |
546 |
} |
616 |
} |
547 |
my $r = { |
617 |
my $r = { |
548 |
field => $index_field_convert{$f}, |
618 |
field => exists $index_field_convert{$f} ? $index_field_convert{$f} : $f, |
549 |
type => $index_type_convert{ $t // '__default' } |
619 |
type => $index_type_convert{ $t // '__default' } |
550 |
}; |
620 |
}; |
551 |
$r->{field} = ($mc . $r->{field}) if $mc && $r->{field}; |
621 |
$r->{field} = ($mc . $r->{field}) if $mc && $r->{field}; |
Lines 597-608
second part is stripped off as we can't yet handle that. Making it work
Link Here
|
597 |
will have to wait for a real query parser. |
667 |
will have to wait for a real query parser. |
598 |
|
668 |
|
599 |
=cut |
669 |
=cut |
600 |
|
|
|
601 |
sub _convert_index_strings_freeform { |
670 |
sub _convert_index_strings_freeform { |
602 |
my ( $self, $search ) = @_; |
671 |
my ( $self, $search ) = @_; |
603 |
while ( my ( $zeb, $es ) = each %index_field_convert ) { |
672 |
# @TODO: Currenty will alter also fields contained within quotes: |
604 |
$search =~ s/\b$zeb(?:,[\w\-]*)?:/$es:/g; |
673 |
# `searching for "stuff cn:123"` for example will become |
605 |
} |
674 |
# `searching for "stuff local-number:123" |
|
|
675 |
# |
676 |
# Fixing this is tricky, one possibility: |
677 |
# https://stackoverflow.com/questions/19193876/perl-regex-to-match-a-string-that-is-not-enclosed-in-quotes |
678 |
# Still not perfect, and will not handle escaped quotes within quotes and assumes balanced quotes. |
679 |
# |
680 |
# Another, not so elegant, solution could be to replace all quoted content with placeholders, and put |
681 |
# them back when processing is done. |
682 |
|
683 |
# Lower case field names |
684 |
$search =~ s/($field_name_pattern)(?:,[\w-]*)?($multi_field_pattern):/\L$1\E$2:/og; |
685 |
# Resolve possible field aliases |
686 |
$search =~ s/($field_name_pattern)($multi_field_pattern):/(exists $index_field_convert{$1} ? $index_field_convert{$1} : $1)."$2:"/oge; |
606 |
return $search; |
687 |
return $search; |
607 |
} |
688 |
} |
608 |
|
689 |
|
Lines 802-813
operands and double quoted strings.
Link Here
|
802 |
|
883 |
|
803 |
=cut |
884 |
=cut |
804 |
|
885 |
|
|
|
886 |
my $tokenize_split_re = qr/((?:${field_name_pattern}${multi_field_pattern}:)?"[^"]+"|\s+)/; |
805 |
sub _truncate_terms { |
887 |
sub _truncate_terms { |
806 |
my ( $self, $query ) = @_; |
888 |
my ( $self, $query ) = @_; |
807 |
|
889 |
|
808 |
# '"donald duck" title:"the mouse" and peter" get split into |
890 |
# '"donald duck" title:"the mouse" and peter" get split into |
809 |
# ['', '"donald duck"', '', ' ', '', 'title:"the mouse"', '', ' ', 'and', ' ', 'pete'] |
891 |
# ['', '"donald duck"', '', ' ', '', 'title:"the mouse"', '', ' ', 'and', ' ', 'pete'] |
810 |
my @tokens = split /((?:[\w\-.]+:)?"[^"]+"|\s+)/, $query; |
892 |
my @tokens = split $tokenize_split_re, $query; |
811 |
|
893 |
|
812 |
# Filter out empty tokens |
894 |
# Filter out empty tokens |
813 |
my @words = grep { $_ !~ /^\s*$/ } @tokens; |
895 |
my @words = grep { $_ !~ /^\s*$/ } @tokens; |