Line 0
Link Here
|
|
|
1 |
var url_request = '/cgi-bin/koha/svc/elasticsearch/opac-autocomplete.pl?q='; |
2 |
|
3 |
const url_param = '_search?filter_path=hits.total&source_content_type=application/json' |
4 |
/* Regex pour tous les URL avec un recherche */ |
5 |
var regex_es_link = "/cgi-bin/koha/opac-search.pl?q="; |
6 |
/* key API */ |
7 |
var key_display = 'nb_notice'; |
8 |
/* idx de recherche */ |
9 |
var es_builder = { |
10 |
'an' : 'koha-auth-number', |
11 |
'Provider' : 'provider', |
12 |
'se,phr' : 'title-series', |
13 |
'au' : 'author', |
14 |
'su,complete-subfield' : 'subject' |
15 |
} |
16 |
/* On remplace tous les caractères suivants */ |
17 |
//https://www.obkb.com/dcljr/charstxt.html |
18 |
var not_symbols = { |
19 |
'\'':'%27', |
20 |
'.':'%2E', |
21 |
'+': '', |
22 |
',': '%2C', |
23 |
';': '%3B', |
24 |
'-': '', |
25 |
'=': '', |
26 |
'&': '%26', |
27 |
'|': '', |
28 |
'>': '', |
29 |
'<': '', |
30 |
'!': '', |
31 |
'(': '', |
32 |
')': '', |
33 |
'{': '', |
34 |
'}': '', |
35 |
'[': '', |
36 |
']': '', |
37 |
'^': '', |
38 |
'"': '', |
39 |
'~': '', |
40 |
'*': '', |
41 |
'?': '', |
42 |
':': '%3A', |
43 |
'/': '', |
44 |
"\\": '%5C' |
45 |
}; |
46 |
|
47 |
function NumberResultsRecord(){ |
48 |
|
49 |
var regex = `a[href*="${regex_es_link}"]`; |
50 |
var all_link = $(regex); |
51 |
/* array json data to server */ |
52 |
var json_data=[]; |
53 |
|
54 |
$.each( all_link, function( i, val ) { |
55 |
var url = ''; |
56 |
var str = val.href; |
57 |
/* on prend param de q= */ |
58 |
str = decodeURIComponent(str.split('?q=').pop()); |
59 |
/* split query for fields for search [0] */ |
60 |
var es_search = str.split(':'); |
61 |
/* Remplacement pour un requete */ |
62 |
var str_search = str.substring(str.indexOf(":") + 1); |
63 |
/* [0] this is field for search */ |
64 |
str_search = str_search.replace(/[&\/\\#,+()$~%.'":;*?<>{}]/g, function(matched){ |
65 |
return not_symbols[matched]; |
66 |
}); |
67 |
es_search[0] = es_search[0][0] == '(' ? es_search[0].substring(1) : es_search[0]; |
68 |
var json = {}; |
69 |
json[es_builder[es_search[0]]] = str_search; |
70 |
json_data.push(json); |
71 |
}); |
72 |
|
73 |
$.ajax({ |
74 |
type: 'GET', |
75 |
url: url_request + JSON.stringify(json_data) + '&key=' + key_display, |
76 |
success: function (data) { |
77 |
console.log(data); |
78 |
jQuery.each( all_link, function( i, val ) { |
79 |
$(val).after(" <span style=\"color:black\"><b>["+data[i]+"]</b></span>"); |
80 |
console.log(val); |
81 |
}); |
82 |
}, |
83 |
error: function (data) { |
84 |
console.log(data); |
85 |
}, |
86 |
}); |
87 |
|
88 |
} |