ricerca testo: aggiunto contesto

This commit is contained in:
cesare 2024-02-12 13:29:19 +01:00
parent fd859f3463
commit 449b30ea64
2 changed files with 37 additions and 51 deletions

View File

@ -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])

View File

@ -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()