Lines 100-108
sub FindDuplicate {
Link Here
|
100 |
if ( $result->{isbn} ) { |
100 |
if ( $result->{isbn} ) { |
101 |
$result->{isbn} =~ s/\(.*$//; |
101 |
$result->{isbn} =~ s/\(.*$//; |
102 |
$result->{isbn} =~ s/\s+$//; |
102 |
$result->{isbn} =~ s/\s+$//; |
103 |
$query = "isbn=$result->{isbn}"; |
103 |
$query = "isbn:$result->{isbn}"; |
104 |
} |
104 |
} |
105 |
else { |
105 |
else { |
|
|
106 |
my $QParser; |
107 |
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser')); |
108 |
my $titleindex; |
109 |
my $authorindex; |
110 |
my $op; |
111 |
|
112 |
if ($QParser) { |
113 |
$titleindex = 'title|exact'; |
114 |
$authorindex = 'author|exact'; |
115 |
$op = '&&'; |
116 |
} else { |
117 |
$titleindex = 'ti,ext'; |
118 |
$authorindex = 'au,ext'; |
119 |
$op = 'and'; |
120 |
} |
121 |
|
106 |
$result->{title} =~ s /\\//g; |
122 |
$result->{title} =~ s /\\//g; |
107 |
$result->{title} =~ s /\"//g; |
123 |
$result->{title} =~ s /\"//g; |
108 |
$result->{title} =~ s /\(//g; |
124 |
$result->{title} =~ s /\(//g; |
Lines 111-117
sub FindDuplicate {
Link Here
|
111 |
# FIXME: instead of removing operators, could just do |
127 |
# FIXME: instead of removing operators, could just do |
112 |
# quotes around the value |
128 |
# quotes around the value |
113 |
$result->{title} =~ s/(and|or|not)//g; |
129 |
$result->{title} =~ s/(and|or|not)//g; |
114 |
$query = "ti,ext=$result->{title}"; |
130 |
$query = "$titleindex:\"$result->{title}\""; |
115 |
if ( $result->{author} ) { |
131 |
if ( $result->{author} ) { |
116 |
$result->{author} =~ s /\\//g; |
132 |
$result->{author} =~ s /\\//g; |
117 |
$result->{author} =~ s /\"//g; |
133 |
$result->{author} =~ s /\"//g; |
Lines 120-126
sub FindDuplicate {
Link Here
|
120 |
|
136 |
|
121 |
# remove valid operators |
137 |
# remove valid operators |
122 |
$result->{author} =~ s/(and|or|not)//g; |
138 |
$result->{author} =~ s/(and|or|not)//g; |
123 |
$query .= " and au,ext=$result->{author}"; |
139 |
$query .= " $op $authorindex:\"$result->{author}\""; |
124 |
} |
140 |
} |
125 |
} |
141 |
} |
126 |
|
142 |
|
Lines 224-234
sub SimpleSearch {
Link Here
|
224 |
my $results = []; |
240 |
my $results = []; |
225 |
my $total_hits = 0; |
241 |
my $total_hits = 0; |
226 |
|
242 |
|
|
|
243 |
my $QParser; |
244 |
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') && ! ($query =~ m/\w,\w|\w=\w/)); |
245 |
|
227 |
# Initialize & Search Zebra |
246 |
# Initialize & Search Zebra |
228 |
for ( my $i = 0 ; $i < @servers ; $i++ ) { |
247 |
for ( my $i = 0 ; $i < @servers ; $i++ ) { |
229 |
eval { |
248 |
eval { |
230 |
$zconns[$i] = C4::Context->Zconn( $servers[$i], 1 ); |
249 |
$zconns[$i] = C4::Context->Zconn( $servers[$i], 1 ); |
231 |
$zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]); |
250 |
if ($QParser) { |
|
|
251 |
$query =~ s/=/:/g; |
252 |
$QParser->parse( $query ); |
253 |
$query = $QParser->target_syntax($servers[$i]); |
254 |
$zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]); |
255 |
} else { |
256 |
$zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]); |
257 |
} |
232 |
$tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] ); |
258 |
$tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] ); |
233 |
|
259 |
|
234 |
# error handling |
260 |
# error handling |
Lines 1091-1097
on authority data).
Link Here
|
1091 |
=cut |
1117 |
=cut |
1092 |
|
1118 |
|
1093 |
sub _handle_exploding_index { |
1119 |
sub _handle_exploding_index { |
1094 |
my ( $index, $term ) = @_; |
1120 |
my ($QParser, $struct, $filter, $params, $negate, $server) = @_; |
|
|
1121 |
my $index = $filter; |
1122 |
my $term = join(' ', @$params); |
1095 |
|
1123 |
|
1096 |
return unless ($index =~ m/(su-br|su-na|su-rl)/ && $term); |
1124 |
return unless ($index =~ m/(su-br|su-na|su-rl)/ && $term); |
1097 |
|
1125 |
|
Lines 1099-1106
sub _handle_exploding_index {
Link Here
|
1099 |
|
1127 |
|
1100 |
my $codesubfield = $marcflavour eq 'UNIMARC' ? '5' : 'w'; |
1128 |
my $codesubfield = $marcflavour eq 'UNIMARC' ? '5' : 'w'; |
1101 |
my $wantedcodes = ''; |
1129 |
my $wantedcodes = ''; |
1102 |
my @subqueries = ( "(su=\"$term\")"); |
1130 |
my @subqueries = ( "su:\"$term\""); |
1103 |
my ($error, $results, $total_hits) = SimpleSearch( "Heading,wrdl=$term", undef, undef, [ "authorityserver" ] ); |
1131 |
my ($error, $results, $total_hits) = SimpleSearch( "he:$term", undef, undef, [ "authorityserver" ] ); |
1104 |
foreach my $auth (@$results) { |
1132 |
foreach my $auth (@$results) { |
1105 |
my $record = MARC::Record->new_from_usmarc($auth); |
1133 |
my $record = MARC::Record->new_from_usmarc($auth); |
1106 |
my @references = $record->field('5..'); |
1134 |
my @references = $record->field('5..'); |
Lines 1114-1124
sub _handle_exploding_index {
Link Here
|
1114 |
} |
1142 |
} |
1115 |
foreach my $reference (@references) { |
1143 |
foreach my $reference (@references) { |
1116 |
my $codes = $reference->subfield($codesubfield); |
1144 |
my $codes = $reference->subfield($codesubfield); |
1117 |
push @subqueries, '(su="' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '")' if (($codes && $codes eq $wantedcodes) || !$wantedcodes); |
1145 |
push @subqueries, 'su:"' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '"' if (($codes && $codes eq $wantedcodes) || !$wantedcodes); |
1118 |
} |
1146 |
} |
1119 |
} |
1147 |
} |
1120 |
} |
1148 |
} |
1121 |
return join(' or ', @subqueries); |
1149 |
my $query = '(' x scalar(@subqueries) . join(') || ', @subqueries) . ')'; |
|
|
1150 |
warn $query; |
1151 |
return $query; |
1122 |
} |
1152 |
} |
1123 |
|
1153 |
|
1124 |
=head2 parseQuery |
1154 |
=head2 parseQuery |
Lines 1145-1181
sub parseQuery {
Link Here
|
1145 |
my $query = $operands[0]; |
1175 |
my $query = $operands[0]; |
1146 |
my $index; |
1176 |
my $index; |
1147 |
my $term; |
1177 |
my $term; |
|
|
1178 |
my $query_desc; |
1148 |
|
1179 |
|
1149 |
# TODO: once we are using QueryParser, all this special case code for |
1180 |
my $QParser; |
1150 |
# exploded search indexes will be replaced by a callback to |
1181 |
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') || $query =~ s/^qp=//); |
1151 |
# _handle_exploding_index |
1182 |
undef $QParser if ($query =~ m/^(ccl=|pqf=|cql=)/ || grep (/\w,\w|\w=\w/, @operands) ); |
1152 |
if ( $query =~ m/^(.*)\b(su-br|su-na|su-rl)[:=](\w.*)$/ ) { |
1183 |
|
1153 |
$query = $1; |
1184 |
if ($QParser) |
1154 |
$index = $2; |
1185 |
{ |
1155 |
$term = $3; |
|
|
1156 |
} else { |
1157 |
$query = ''; |
1186 |
$query = ''; |
1158 |
for ( my $i = 0 ; $i <= @operands ; $i++ ) { |
1187 |
for ( my $ii = 0 ; $ii <= @operands ; $ii++ ) { |
1159 |
if ($operands[$i] && $indexes[$i] =~ m/(su-br|su-na|su-rl)/) { |
1188 |
next unless $operands[$ii]; |
1160 |
$index = $indexes[$i]; |
1189 |
$query .= $operators[ $ii - 1 ] eq 'or' ? ' || ' : ' && ' |
1161 |
$term = $operands[$i]; |
1190 |
if ($query); |
1162 |
} elsif ($operands[$i]) { |
1191 |
$query .= |
1163 |
$query .= $operators[$i] eq 'or' ? ' or ' : ' and ' if ($query); |
1192 |
( $operators[$ii] ? "$operators[$ii]:" : '' ) . $operands[$ii]; |
1164 |
$query .= "($indexes[$i]:$operands[$i])"; |
1193 |
} |
1165 |
} |
1194 |
foreach my $limit (@limits) { |
|
|
1195 |
} |
1196 |
foreach my $modifier (@sort_by) { |
1197 |
$query .= " #$modifier"; |
1166 |
} |
1198 |
} |
1167 |
} |
|
|
1168 |
|
1199 |
|
1169 |
if ($index) { |
1200 |
$query_desc = $query; |
1170 |
my $queryPart = _handle_exploding_index($index, $term); |
1201 |
if ( C4::Context->preference("QueryWeightFields") ) { |
1171 |
if ($queryPart) { |
|
|
1172 |
$query .= "($queryPart)"; |
1173 |
} |
1202 |
} |
1174 |
$operators = (); |
1203 |
$QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index }); |
1175 |
$operands[0] = "ccl=$query"; |
1204 |
$QParser->add_bib1_filter_map( 'biblioserver', 'su-na', { 'callback' => \&_handle_exploding_index }); |
|
|
1205 |
$QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index }); |
1206 |
$QParser->parse( $query ); |
1207 |
$operands[0] = "pqf=" . $QParser->target_syntax('biblioserver'); |
1208 |
# TODO: once we are using QueryParser, all this special case code for |
1209 |
# exploded search indexes will be replaced by a callback to |
1210 |
# _handle_exploding_index |
1176 |
} |
1211 |
} |
1177 |
|
1212 |
|
1178 |
return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang); |
1213 |
return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc); |
1179 |
} |
1214 |
} |
1180 |
|
1215 |
|
1181 |
=head2 buildQuery |
1216 |
=head2 buildQuery |
Lines 1199-1205
sub buildQuery {
Link Here
|
1199 |
|
1234 |
|
1200 |
warn "---------\nEnter buildQuery\n---------" if $DEBUG; |
1235 |
warn "---------\nEnter buildQuery\n---------" if $DEBUG; |
1201 |
|
1236 |
|
1202 |
( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang) = parseQuery($operators, $operands, $indexes, $limits, $sort_by, $scan, $lang); |
1237 |
my $query_desc; |
|
|
1238 |
( $operators, $operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc) = parseQuery($operators, $operands, $indexes, $limits, $sort_by, $scan, $lang); |
1203 |
|
1239 |
|
1204 |
# dereference |
1240 |
# dereference |
1205 |
my @operators = $operators ? @$operators : (); |
1241 |
my @operators = $operators ? @$operators : (); |
Lines 1227-1233
sub buildQuery {
Link Here
|
1227 |
|
1263 |
|
1228 |
# initialize the variables we're passing back |
1264 |
# initialize the variables we're passing back |
1229 |
my $query_cgi; |
1265 |
my $query_cgi; |
1230 |
my $query_desc; |
|
|
1231 |
my $query_type; |
1266 |
my $query_type; |
1232 |
|
1267 |
|
1233 |
my $limit; |
1268 |
my $limit; |
Lines 1262-1268
sub buildQuery {
Link Here
|
1262 |
return ( undef, $', $', "q=cql=$'", $', '', '', '', '', 'cql' ); |
1297 |
return ( undef, $', $', "q=cql=$'", $', '', '', '', '', 'cql' ); |
1263 |
} |
1298 |
} |
1264 |
if ( $query =~ /^pqf=/ ) { |
1299 |
if ( $query =~ /^pqf=/ ) { |
1265 |
return ( undef, $', $', "q=pqf=$'", $', '', '', '', '', 'pqf' ); |
1300 |
if ($query_desc) { |
|
|
1301 |
$query_cgi = "q=$query_desc"; |
1302 |
} else { |
1303 |
$query_desc = $'; |
1304 |
$query_cgi = "q=pqf=$'"; |
1305 |
} |
1306 |
return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' ); |
1266 |
} |
1307 |
} |
1267 |
|
1308 |
|
1268 |
# pass nested queries directly |
1309 |
# pass nested queries directly |