use C4::Debug;
require C4::Context;
-use Test::More tests => 78;
+use Test::More tests => 79;
use Test::MockModule;
use MARC::Record;
use File::Spec;
my $QueryWeightFields = 0;
my $QueryFuzzy = 0;
my $QueryRemoveStopwords = 0;
+my $UseQueryParser = 0;
my $contextmodule = new Test::MockModule('C4::Context');
$contextmodule->mock('_new_dbh', sub {
my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
return $dbh });
$contextmodule->mock('preference', sub {
my ($self, $pref) = @_;
- if ($pref eq 'NoZebra') {
- return 0;
- } elsif ($pref eq 'marcflavour') {
+ if ($pref eq 'marcflavour') {
return 'MARC21';
} elsif ($pref eq 'QueryStemming') {
return $QueryStemming;
return $QueryFuzzy;
} elsif ($pref eq 'QueryRemoveStopwords') {
return $QueryRemoveStopwords;
+ } elsif ($pref eq 'UseQueryParser') {
+ return $UseQueryParser;
} elsif ($pref eq 'maxRecordsForFacets') {
return 20;
} elsif ($pref eq 'FacetLabelTruncationLength') {
return '490av';
} else {
warn "The syspref $pref was requested but I don't know what to say; this indicates that the test requires updating"
- unless $pref =~ m/(XSLT|item|branch|holding|image|insecure)/i;
+ unless $pref =~ m/(XSLT|item|branch|holding|image)/i;
return 0;
}
});
);
return \%hash;
});
+$contextmodule->mock('queryparser', sub {
+ my $QParser = Koha::QueryParser::Driver::PQF->new();
+ $QParser->load_config("$datadir/etc/searchengine/queryparser.yaml");
+ return $QParser;
+});
my $context = new C4::Context("$datadir/etc/koha-conf.xml");
$context->set_context();
$dbh->{mock_add_resultset} = {
sql => 'SHOW COLUMNS FROM items',
results => [
+ [ 'rows' ], # seems like $sth->rows is getting called
+ # implicitly, so we need this to make
+ # DBD::Mock return all of the results
[ 'itemnumber' ], [ 'biblionumber' ], [ 'biblioitemnumber' ],
[ 'barcode' ], [ 'dateaccessioned' ], [ 'booksellerid' ],
[ 'homebranch' ], [ 'price' ], [ 'replacementprice' ],
$results_hashref->{'biblioserver'}->{"RECORDS"});
is($newresults[0]->{'alternateholdings_count'}, 1, 'Alternate holdings filled in correctly');
+
+## Regression test for Bug 10741
+
+# make one of the test items appear to be in transit
+my $circ_module = new Test::MockModule('C4::Circulation');
+$circ_module->mock('GetTransfers', sub {
+ my $itemnumber = shift;
+ if ($itemnumber == 11) {
+ return ('2013-07-19', 'MPL', 'CPL');
+ } else {
+ return;
+ }
+});
+
+($error, $results_hashref, $facets_loop) = getRecords("TEST12121212","TEST12121212",[ ], [ 'biblioserver' ],20,0,undef,\%branches,\%itemtypes,$query_type,0);
+@newresults = searchResults('intranet', $query_desc, $results_hashref->{'biblioserver'}->{'hits'}, 17, 0, 0,
+ $results_hashref->{'biblioserver'}->{"RECORDS"});
+ok(!exists($newresults[0]->{norequests}), 'presence of a transit does not block hold request action (bug 10741)');
+
END {
if ($child) {
kill 9, $child;
$searchmodule->mock('SimpleSearch', sub {
my $query = shift;
- is($query, "Heading,wrdl=$term", "Searching for expected term '$term' for exploding") or return '', [], 0;
+ is($query, "he:$term", "Searching for expected term '$term' for exploding") or return '', [], 0;
my $record = MARC::Record->new;
if ($query =~ m/Arizona/) {
return '', [ $record->as_usmarc() ], 1;
});
+$UseQueryParser = 1;
$term = 'Arizona';
( $error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
( $error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
-$stopwords_removed, $query_type ) = buildQuery([], [ "su-br:$term" ], [ ], [ ], [], 0, 'en');
+$stopwords_removed, $query_type ) = buildQuery([], [ "su-br($term)" ], [ ], [ ], [], 0, 'en');
matchesExplodedTerms("Simple search for broader subjects", $query, 'Arizona', 'United States');
( $error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
-$stopwords_removed, $query_type ) = buildQuery([], [ "su-na:$term" ], [ ], [ ], [], 0, 'en');
+$stopwords_removed, $query_type ) = buildQuery([], [ "su-na($term)" ], [ ], [ ], [], 0, 'en');
matchesExplodedTerms("Simple search for narrower subjects", $query, 'Arizona', 'Maricopa County', 'Navajo County', 'Pima County');
( $error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
-$stopwords_removed, $query_type ) = buildQuery([], [ "su-rl:$term" ], [ ], [ ], [], 0, 'en');
+$stopwords_removed, $query_type ) = buildQuery([], [ "su-rl($term)" ], [ ], [ ], [], 0, 'en');
matchesExplodedTerms("Simple search for related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
( $error, $query, $simple_query, $query_cgi,
$query_desc, $limit, $limit_cgi, $limit_desc,
-$stopwords_removed, $query_type ) = buildQuery([], [ "history and su-rl:$term" ], [ ], [ ], [], 0, 'en');
+$stopwords_removed, $query_type ) = buildQuery([], [ "history && su-rl($term)" ], [ ], [ ], [], 0, 'en');
matchesExplodedTerms("Simple search for related subjects and keyword 'history' searches related subjects", $query, 'Arizona', 'United States', 'Maricopa County', 'Navajo County', 'Pima County');
like($query, qr/history/, "Simple search for related subjects and keyword 'history' searches for 'history'");
sub matchesExplodedTerms {
my ($message, $query, @terms) = @_;
- my $match = "(( or )?\\((" . join ('|', map { "su=\"$_\"" } @terms) . ")\\)){" . scalar(@terms) . "}";
+ my $match = '(' . join ('|', map { " \@attr 1=Subject \@attr 4=1 \"$_\"" } @terms) . "){" . scalar(@terms) . "}";
like($query, qr/$match/, $message);
}