diff --git a/js/cesareBrowse.js b/js/cesareBrowse.js index 6a30bb7..49ba660 100644 --- a/js/cesareBrowse.js +++ b/js/cesareBrowse.js @@ -1403,20 +1403,47 @@ function resetFrasi(){ unitaRicerca='forma' else unitaRicerca=jsonQuery['unitaRicerca'] - console.log("got json query, unita ricerca: "+unitaRicerca) - if(jsonQuery['QueryAvanzata']==0 && jsonQuery['Clausola0']['queryText']==''){ + console.log("got json query, unita ricerca: " + unitaRicerca) + if (jsonQuery['QueryAvanzata'] == 0 && jsonQuery['Clausola0']['queryText'] == '') { alert('Digitare una stringa da cercare') return } - if (jsonQuery['Clausola0']['lemma_forma'] == 'testo'){ + if (jsonQuery['Clausola0']['lemma_forma'] == 'testo') { searchwords = jsonQuery['Clausola0']['queryText'].trim().split(' ') + var contesto = JSON.parse(jsonQuery['Clausola0']['contesto']) + var inf = [] + var pur = [] + var par = [] + var noContext=true + if (!(contesto[0].every(item => item === 0) && contesto[1].every(item => item === 0) && contesto[2].every(item => item === 0))) { + //inf=contesto[0].some(item => item !== 0) + noContext=false + inf = contesto[0].reduce((a, e, i) => { + if (e === 1) + a.push(i); + return a; + }, []); + pur = contesto[1].reduce((a, e, i) => { + if (e === 1) + a.push(i); + return a; + }, []); + par = contesto[2].reduce((a, e, i) => { + if (e === 1) + a.push(i); + return a; + }, []); + } var resultsInCantica=[] var resultsInCanto=[] console.log('frase length '+searchwords.length) - executeLocalSearch(searchwords, formeprima, (formeprima.length-searchwords.length), cantiche[0], resultsInCantica, resultsInCanto) - executeLocalSearch(searchwords, formeseconda, (formeseconda.length-searchwords.length), cantiche[1], resultsInCantica, resultsInCanto) - executeLocalSearch(searchwords, formeterza, (formeterza.length-searchwords.length), cantiche[2], resultsInCantica, resultsInCanto) + if(noContext || inf.length) + executeLocalSearch(searchwords, formeprima, (formeprima.length-searchwords.length), cantiche[0], inf, resultsInCantica, resultsInCanto) + if(noContext || pur.length) + executeLocalSearch(searchwords, formeseconda, (formeseconda.length-searchwords.length), cantiche[1], pur, resultsInCantica, resultsInCanto) + if(noContext || par.length) + executeLocalSearch(searchwords, formeterza, (formeterza.length-searchwords.length), cantiche[2], par, resultsInCantica, resultsInCanto) if (listarisultati.length){ //evidenzia risultati for (ris of listarisultati) { @@ -1439,7 +1466,7 @@ function resetFrasi(){ } - function executeLocalSearch(testo, forme, limit, cantica, resultsInCantica, resultsInCanto){ + function executeLocalSearch(testo, forme, limit, cantica, cont, resultsInCantica, resultsInCanto){ for (var ip=0; ip<=limit; ip++){ var fnd=true @@ -1451,6 +1478,9 @@ function resetFrasi(){ } if (fnd){ //console.log('ipfound: '+forme[ip].split('_')[2]+' - '+forme[(ip+testo.length-1)].split('_')[2]) + if(cont.length && !(parseInt(forme[ip].split('_')[1]) in cont)){ + continue + } resultsInCantica.push(cantica) resultsInCanto.push(cantica+'Canto '+forme[ip].split('_')[1]) var tstar= parseInt(forme[ip].split('_')[2]) diff --git a/js/utils.js b/js/utils.js index fe5747a..879e229 100644 --- a/js/utils.js +++ b/js/utils.js @@ -557,51 +557,7 @@ function buildSQ(stquery) { //Crea le triple per WHERE se cerco il testo -/* -{ - "type": "filter", - "expression": { - "type": "operation", - "operator": "=", - "args": [ - { - "type": "functionCall", - "function": { - "termType": "NamedNode", - "value": "http://www.w3.org/2001/XMLSchema#int" - }, - "args": [ - { - "type": "operation", - "operator": "+", - "args": [ - { - "termType": "Variable", - "value": "pos" - }, - { - "termType": "Literal", - "value": "1", - "language": "", - "datatype": { - "termType": "NamedNode", - "value": "http://www.w3.org/2001/XMLSchema#integer" - } - } - ] - } - ], - "distinct": false - }, - { - "termType": "Variable", - "value": "Num1" - } - ] - } -} -*/ function getTestoWherePosFilter(pos1, pos2, dist){ let filterpos=new Object()