|
Lines 810-821
Returns a query which can be used to search for all component parts of MARC21 bi
Link Here
|
| 810 |
sub get_components_query { |
810 |
sub get_components_query { |
| 811 |
my ($self) = @_; |
811 |
my ($self) = @_; |
| 812 |
|
812 |
|
| 813 |
my $builder = Koha::SearchEngine::QueryBuilder->new( |
813 |
# MARC21 Only for now |
| 814 |
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
814 |
return if ( C4::Context->preference('marcflavour') ne 'MARC21' ); |
|
|
815 |
|
| 815 |
my $marc = $self->metadata->record; |
816 |
my $marc = $self->metadata->record; |
|
|
817 |
|
| 818 |
my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
| 816 |
my $component_sort_field = C4::Context->preference('ComponentSortField') // "title"; |
819 |
my $component_sort_field = C4::Context->preference('ComponentSortField') // "title"; |
| 817 |
my $component_sort_order = C4::Context->preference('ComponentSortOrder') // "asc"; |
820 |
my $component_sort_order = C4::Context->preference('ComponentSortOrder') // "asc"; |
| 818 |
my $sort = $component_sort_field . "_" . $component_sort_order; |
821 |
my $sort = $component_sort_field . "_" . $component_sort_order; |
| 819 |
|
822 |
|
| 820 |
my $searchstr; |
823 |
my $searchstr; |
| 821 |
if ( C4::Context->preference('UseControlNumber') ) { |
824 |
if ( C4::Context->preference('UseControlNumber') ) { |
|
Lines 826-836
sub get_components_query {
Link Here
|
| 826 |
my $pf003 = $marc->field('003') || undef; |
829 |
my $pf003 = $marc->field('003') || undef; |
| 827 |
|
830 |
|
| 828 |
if ( !defined($pf003) ) { |
831 |
if ( !defined($pf003) ) { |
|
|
832 |
|
| 829 |
# search for 773$w='Host001' |
833 |
# search for 773$w='Host001' |
| 830 |
$searchstr .= "rcn:\"" . $pf001->data()."\""; |
834 |
$searchstr .= "rcn:\"" . $pf001->data() . "\""; |
| 831 |
} |
835 |
} else { |
| 832 |
else { |
|
|
| 833 |
$searchstr .= "("; |
836 |
$searchstr .= "("; |
|
|
837 |
|
| 834 |
# search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' |
838 |
# search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' |
| 835 |
$searchstr .= "(rcn:\"" . $pf001->data() . "\" AND cni:\"" . $pf003->data() . "\")"; |
839 |
$searchstr .= "(rcn:\"" . $pf001->data() . "\" AND cni:\"" . $pf003->data() . "\")"; |
| 836 |
$searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; |
840 |
$searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; |
|
Lines 841-860
sub get_components_query {
Link Here
|
| 841 |
$searchstr .= " AND (bib-level:a OR bib-level:b)"; |
845 |
$searchstr .= " AND (bib-level:a OR bib-level:b)"; |
| 842 |
$searchstr .= ")"; |
846 |
$searchstr .= ")"; |
| 843 |
} |
847 |
} |
| 844 |
} |
848 |
} else { |
| 845 |
else { |
849 |
my $cleaned_title = $marc->subfield( '245', "a" ); |
| 846 |
my $cleaned_title = $marc->subfield('245', "a"); |
|
|
| 847 |
$cleaned_title =~ tr|/||; |
850 |
$cleaned_title =~ tr|/||; |
| 848 |
$cleaned_title = $builder->clean_search_term($cleaned_title); |
851 |
$cleaned_title = $builder->clean_search_term($cleaned_title); |
| 849 |
$searchstr = qq#Host-item:("$cleaned_title")#; |
852 |
$searchstr = qq#Host-item:("$cleaned_title")#; |
|
|
853 |
$searchstr .= " AND (bib-level:a OR bib-level:b)"; |
| 850 |
} |
854 |
} |
| 851 |
my ($error, $query ,$query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 ); |
855 |
my ( $error, $query, $query_str ) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 ); |
| 852 |
if( $error ){ |
856 |
if ($error) { |
| 853 |
warn $error; |
857 |
warn $error; |
| 854 |
return; |
858 |
return; |
| 855 |
} |
859 |
} |
| 856 |
|
860 |
|
| 857 |
return ($query, $query_str, $sort); |
861 |
return ( $query, $query_str, $sort ); |
| 858 |
} |
862 |
} |
| 859 |
|
863 |
|
| 860 |
=head3 get_marc_volumes |
864 |
=head3 get_marc_volumes |
| 861 |
- |
|
|