(bug #3584) detect ccl queries

This patch C4::Search::buildQuery to detect ccl queries, and let zebra to parse them.
And set a default index "kw" if not specified.
This improve the detection of ccl queries, and do not duplicate the "ccl=" value.
Adding = as an index sign
Followup to 3037ff9e81

Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
This commit is contained in:
Henri-Damien LAURENT 2009-12-18 12:16:46 +01:00
parent 0fa37b5bb4
commit 640595651f

View file

@ -783,6 +783,194 @@ sub _build_weighted_query {
return $weighted_query; return $weighted_query;
} }
=head2 getIndexes
Return an array with available indexes.
=cut
sub getIndexes{
my @indexes = (
# biblio indexes
'ab',
'Abstract',
'acqdate',
'allrecords',
'an',
'Any',
'at',
'au',
'aub',
'aud',
'audience',
'auo',
'aut',
'Author',
'Author-in-order ',
'Author-personal-bibliography',
'Authority-Number',
'authtype',
'bc',
'biblionumber',
'bio',
'biography',
'callnum',
'cfn',
'Chronological-subdivision',
'cn-bib-source',
'cn-bib-sort',
'cn-class',
'cn-item',
'cn-prefix',
'cn-suffix',
'cpn',
'Code-institution',
'Conference-name',
'Conference-name-heading',
'Conference-name-see',
'Conference-name-seealso',
'Content-type',
'Control-number',
'copydate',
'Corporate-name',
'Corporate-name-heading',
'Corporate-name-see',
'Corporate-name-seealso',
'ctype',
'date-entered-on-file',
'Date-of-acquisition',
'Date-of-publication',
'Dewey-classification',
'extent',
'fic',
'fiction',
'Form-subdivision',
'format',
'Geographic-subdivision',
'he',
'Heading',
'Heading-use-main-or-added-entry',
'Heading-use-series-added-entry ',
'Heading-use-subject-added-entry',
'Host-item',
'id-other',
'Illustration-code',
'ISBN',
'ISSN',
'itemtype',
'kw',
'Koha-Auth-Number',
'l-format',
'language',
'lc-card',
'LC-card-number',
'lcn',
'llength',
'ln',
'Local-classification',
'Local-number',
'Match-heading',
'Match-heading-see-from',
'Material-type',
'mc-itemtype',
'mc-rtype',
'mus',
'Name-geographic',
'Name-geographic-heading',
'Name-geographic-see',
'Name-geographic-seealso',
'nb',
'Note',
'ns',
'nt',
'pb',
'Personal-name',
'Personal-name-heading',
'Personal-name-see',
'Personal-name-seealso',
'pl',
'Place-publication',
'pn',
'popularity',
'pubdate',
'Publisher',
'Record-type',
'rtype',
'se',
'See',
'See-also',
'sn',
'Stock-number',
'su',
'Subject',
'Subject-heading-thesaurus',
'Subject-name-personal',
'Subject-subdivision',
'Summary',
'Suppress',
'su-geo',
'su-na',
'su-to',
'su-ut',
'ut',
'Term-genre-form',
'Term-genre-form-heading',
'Term-genre-form-see',
'Term-genre-form-seealso',
'ti',
'Title',
'Title-cover',
'Title-series',
'Title-uniform',
'Title-uniform-heading',
'Title-uniform-see',
'Title-uniform-seealso',
'totalissues',
'yr',
# items indexes
'acqsource',
'barcode',
'bc',
'branch',
'ccode',
'classification-source',
'cn-sort',
'coded-location-qualifier',
'copynumber',
'damaged',
'datelastborrowed',
'datelastseen',
'holdingbranch',
'homebranch',
'issues',
'itemnumber',
'itype',
'Local-classification',
'location',
'lost',
'materials-specified',
'mc-ccode',
'mc-itype',
'mc-loc',
'notforloan',
'onloan',
'price',
'renewals',
'replacementprice',
'replacementpricedate',
'reserves',
'restricted',
'stack',
'uri',
'withdrawn',
# subject related
);
return \@indexes;
}
=head2 buildQuery =head2 buildQuery
( $error, $query, ( $error, $query,
@ -838,6 +1026,17 @@ sub buildQuery {
my $stopwords_removed; # flag to determine if stopwords have been removed my $stopwords_removed; # flag to determine if stopwords have been removed
my $cclq;
my $cclindexes = getIndexes();
if( $query !~ /\s*ccl=/ ){
for my $index (@$cclindexes){
if($query =~ /($index)(,?\w)*[:=]/){
$cclq = 1;
}
}
$query = "ccl=$query" if($cclq);
}
# for handling ccl, cql, pqf queries in diagnostic mode, skip the rest of the steps # for handling ccl, cql, pqf queries in diagnostic mode, skip the rest of the steps
# DIAGNOSTIC ONLY!! # DIAGNOSTIC ONLY!!
if ( $query =~ /^ccl=/ ) { if ( $query =~ /^ccl=/ ) {
@ -914,6 +1113,11 @@ sub buildQuery {
) = ( 0, 0, 0, 0, 0 ); ) = ( 0, 0, 0, 0, 0 );
} }
if(not $index){
$index = 'kw';
}
# Set default structure attribute (word list) # Set default structure attribute (word list)
my $struct_attr; my $struct_attr;
unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl)/ ) { unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl)/ ) {
@ -1094,7 +1298,7 @@ sub buildQuery {
# Normalize the query and limit strings # Normalize the query and limit strings
# This is flawed , means we can't search anything with : in it # This is flawed , means we can't search anything with : in it
# if user wants to do ccl or cql, start the query with that # if user wants to do ccl or cql, start the query with that
# $query =~ s/:/=/g; $query =~ s/:/=/g;
$limit =~ s/:/=/g; $limit =~ s/:/=/g;
for ( $query, $query_desc, $limit, $limit_desc ) { for ( $query, $query_desc, $limit, $limit_desc ) {
s/ / /g; # remove extra spaces s/ / /g; # remove extra spaces