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