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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-4 / +4 lines)
Lines 795-803 operands and double quoted strings. Link Here
795
sub _truncate_terms {
795
sub _truncate_terms {
796
    my ( $self, $query ) = @_;
796
    my ( $self, $query ) = @_;
797
797
798
    # '"donald duck" "the mouse" and peter" get split into
798
    # '"donald duck" title:"the mouse" and peter" get split into
799
    # ['', '"donald duck"', '', ' ', '', '"the mouse"', '', ' ', 'and', ' ', 'pete']
799
    # ['', '"donald duck"', '', ' ', '', 'title:"the mouse"', '', ' ', 'and', ' ', 'pete']
800
    my @tokens = split /("[^"]+"|\s+)/, $query;
800
    my @tokens = split /((?:\w+:)?"[^"]+"|\s+)/, $query;
801
801
802
    # Filter out empty tokens
802
    # Filter out empty tokens
803
    my @words = grep { $_ !~ /^\s*$/ } @tokens;
803
    my @words = grep { $_ !~ /^\s*$/ } @tokens;
Lines 806-812 sub _truncate_terms { Link Here
806
    # terminated by '*' and not a keyword
806
    # terminated by '*' and not a keyword
807
    my @terms = map {
807
    my @terms = map {
808
        my $w = $_;
808
        my $w = $_;
809
        (/^"/ or /\*$/ or grep {lc($w) eq $_} qw/and or not/) ? $_ : "$_*";
809
        (/"$/ or /\*$/ or grep {lc($w) eq $_} qw/and or not/) ? $_ : "$_*";
810
    } @words;
810
    } @words;
811
811
812
    return join ' ', @terms;
812
    return join ' ', @terms;
(-)a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t (-2 / +8 lines)
Lines 81-87 subtest 'json2marc' => sub { Link Here
81
};
81
};
82
82
83
subtest 'build_query tests' => sub {
83
subtest 'build_query tests' => sub {
84
    plan tests => 15;
84
    plan tests => 16;
85
85
86
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
86
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
87
    my $query = $builder->build_query();
87
    my $query = $builder->build_query();
Lines 171-175 subtest 'build_query tests' => sub { Link Here
171
        '(barcode:123456*)',
171
        '(barcode:123456*)',
172
        "query of specific field is truncated"
172
        "query of specific field is truncated"
173
    );
173
    );
174
175
    ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'] );
176
    is(
177
        $query->{query}{query_string}{query},
178
        '(title:"donald duck")',
179
        "query of specific field is not truncated when surrouned by quotes"
180
    );
174
};
181
};
175
182
176
- 

Return to bug 18374