Nick Clemens
7bbf4f7b5f
Previously we put all the servers into an object with keys of the server id This patch converts it to an array of objects to preserve order, and adjusts code to use the array index where necessary and store the server id within the array To test: 1 - Add some new Z3950 servers, they don't need to be valid FIRST SECOND THIRD FOURTH 2 - Adjust the ranking so FOURTH:1 THIRD:2 SECOND:3 FIRST:4 3 - Enable and launch the advanced editor 4 - Click 'Advanced' under search on the left 5 - Note the list displays in the order you entered the servers 6 - Apply patch 7 - Reload 8 - Order is correct 9 - With valid servers, confirm that searching still works and servers can be checked or unchecked to include/remove from results https://bugs.koha-community.org/show_bug.cgi?id=17515 Signed-off-by: B Johnson <barbara.johnson@bedfordtx.gov> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
123 lines
3.8 KiB
JavaScript
123 lines
3.8 KiB
JavaScript
/**
|
|
* Copyright 2015 ByWater Solutions
|
|
*
|
|
* This file is part of Koha.
|
|
*
|
|
* Koha is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Koha is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
*/
|
|
|
|
define( [ 'koha-backend', 'marc-record' ], function( KohaBackend, MARC ) {
|
|
var _options;
|
|
var _records = {};
|
|
var _last;
|
|
|
|
var _pqfMapping = {
|
|
author: '1=1003', // s=al',
|
|
cn_dewey: '1=13',
|
|
cn_lc: '1=16',
|
|
date: '1=30', // r=r',
|
|
isbn: '1=7',
|
|
issn: '1=8',
|
|
lccn: '1=9',
|
|
local_number: '1=12',
|
|
music_identifier: '1=51',
|
|
standard_identifier: '1=1007',
|
|
subject: '1=21', // s=al',
|
|
term: '1=1016', // t=l,r s=al',
|
|
title: '1=4', // s=al',
|
|
}
|
|
|
|
var Search = {
|
|
Init: function( options ) {
|
|
_options = options;
|
|
},
|
|
JoinTerms: function( terms ) {
|
|
var q = '';
|
|
|
|
$.each( terms, function( i, term ) {
|
|
var term = '@attr ' + _pqfMapping[ term[0] ] + ' "' + term[1].replace( '"', '\\"' ) + '"'
|
|
|
|
if ( q ) {
|
|
q = '@and ' + q + ' ' + term;
|
|
} else {
|
|
q = term;
|
|
}
|
|
} );
|
|
|
|
return q;
|
|
},
|
|
Run: function( servers, q, options ) {
|
|
options = $.extend( {
|
|
offset: 0,
|
|
page_size: 20,
|
|
}, _options, options );
|
|
|
|
Search.includedServers = [];
|
|
_records = {};
|
|
_last = {
|
|
servers: servers,
|
|
q: q,
|
|
options: options,
|
|
};
|
|
|
|
var itemTag = KohaBackend.GetSubfieldForKohaField('items.itemnumber')[0];
|
|
|
|
$.each( servers, function ( index, info ) {
|
|
if ( info.checked ) Search.includedServers.push( info.server_id );
|
|
} );
|
|
|
|
if ( Search.includedServers.length == 0 ) return false;
|
|
|
|
$.get(
|
|
'/cgi-bin/koha/svc/cataloguing/metasearch',
|
|
{
|
|
q: q,
|
|
servers: Search.includedServers.join( ',' ),
|
|
offset: options.offset,
|
|
page_size: options.page_size,
|
|
sort_direction: options.sort_direction,
|
|
sort_key: options.sort_key,
|
|
resultset: options.resultset,
|
|
}
|
|
)
|
|
.done( function( data ) {
|
|
_last.options.resultset = data.resultset;
|
|
$.each( data.hits, function( undef, hit ) {
|
|
var record = new MARC.Record();
|
|
record.loadMARCXML( hit.record );
|
|
hit.record = record;
|
|
|
|
if ( hit.server == 'koha:biblioserver' ) {
|
|
// Remove item tags
|
|
while ( record.removeField(itemTag) );
|
|
}
|
|
} );
|
|
|
|
_options.onresults( data );
|
|
} )
|
|
.fail( function( error ) {
|
|
_options.onerror( error );
|
|
} );
|
|
|
|
return true;
|
|
},
|
|
Fetch: function( options ) {
|
|
if ( !_last ) return;
|
|
$.extend( _last.options, options );
|
|
return Search.Run( _last.servers, _last.q, _last.options );
|
|
}
|
|
};
|
|
|
|
return Search;
|
|
} );
|