implementazione ricerca testo, in progress

This commit is contained in:
cesare 2024-02-12 12:01:19 +01:00
parent 17d7627e97
commit fd859f3463
1 changed files with 99 additions and 42 deletions

View File

@ -40,7 +40,7 @@ $(document).ready(function() {
var commentsArray = []
var commentsJson = {}
var resultSentences = new Set()
var cantiche=["Inferno", "Purgatorio","Paradiso"]
const cantiche=["Inferno", "Purgatorio","Paradiso"]
var loadedCanti=new Set();
const openSTag="{"
const closeSTag="}"
@ -1409,7 +1409,26 @@ function resetFrasi(){
return
}
if (jsonQuery['Clausola0']['lemma_forma'] == 'testo'){
searchwords = jsonQuery['Clausola0']['queryText'].split(' ')
searchwords = jsonQuery['Clausola0']['queryText'].trim().split(' ')
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 (listarisultati.length){
//evidenzia risultati
for (ris of listarisultati) {
idris = '#' + ris
$(idris).addClass("font-weight-bold mark ")
}
}
var totResultN=showBadgeInCantica(resultsInCantica)
showBadgeInCanto(resultsInCanto)
return
}
jsonQuery = buildSQ(jsonQuery)
@ -1420,6 +1439,32 @@ function resetFrasi(){
}
function executeLocalSearch(testo, forme, limit, cantica, resultsInCantica, resultsInCanto){
for (var ip=0; ip<=limit; ip++){
var fnd=true
for (var frind=0; frind<testo.length; frind++){
if (testo[frind].toLowerCase()!=forme[ip+frind].split('_')[0].toLowerCase()){
fnd=false;
break
}
}
if (fnd){
//console.log('ipfound: '+forme[ip].split('_')[2]+' - '+forme[(ip+testo.length-1)].split('_')[2])
resultsInCantica.push(cantica)
resultsInCanto.push(cantica+'Canto '+forme[ip].split('_')[1])
var tstar= parseInt(forme[ip].split('_')[2])
var tstop=parseInt(forme[(ip+testo.length-1)].split('_')[2])
for (var mpo=tstar;mpo<tstop+1; mpo++){
listarisultati.push(mpo)
}
}
}
}
//manage sentence and clauses
@ -1654,7 +1699,7 @@ function resetFrasi(){
function createAllDivCanti() {
var cantiche=["Inferno", "Purgatorio","Paradiso"]
//var cantiche=["Inferno", "Purgatorio","Paradiso"]
var divFrasi = $('<div />')
var divDialoghi = $('<div />')
var divMetafore = $('<div />')
@ -1781,7 +1826,7 @@ function resetFrasi(){
listarisultati = Array.from(result)
var listaclausole=Array.from(resultClauses)
cantiche = ["Inferno", "Purgatorio", "Paradiso"]
//cantiche = ["Inferno", "Purgatorio", "Paradiso"]
listaPeriodiRisultato=[]
listaClausoleRisultato=[]
//Unità di ricerca è 'frase'
@ -1858,23 +1903,11 @@ function resetFrasi(){
listarisultati.sort(function(a, b){return a - b});
//aggiunge badge con totale risultati accanto alle cantiche
i = 0
var totResultN=0;
var listIcon = '<ion-icon name="list-outline"></ion-icon>';
for (cantica of cantiche) {
i += 1
let count = resultsInCantica.reduce((n, x) => n + (x === cantica), 0);
if (count>0){
totResultN+=count
var spanbadgecantica = $('<span />');
spanbadgecantica.attr('class', 'badge badge-warning badge-pill mx-2');
spanbadgecantica.append(count)
spanbadgecantica.appendTo($('#cantica' + i + '-badge'))
//$('#cantica' + i).after(spanbadgecantica)
}
}
var totResultN=showBadgeInCantica(resultsInCantica)
//aggiunge badge con totale risultati nel bottone lista risultati
var listIcon = '<ion-icon name="list-outline"></ion-icon>';
if (totResultN>0){
$("#headingZero").closest('.card').attr('style', 'display: d-flex;')
var spanbadgelista = $('<span />');
@ -1882,30 +1915,10 @@ function resetFrasi(){
spanbadgelista.append(totResultN+listIcon)
spanbadgelista.appendTo($('#cantica0-badge'))
}
//aggiunge badge con totale risultati accanto ai canti
showBadgeInCanto(resultsInCanto)
console.log('results end...')
//console.log(sid)
var $nctags= $(' .navig-canto')
for (cantica of cantiche) {
for (k of Array(35).keys()) {
if (k == 0)
continue
let count = resultsInCanto.reduce((n, x) => n + (x === cantica + 'Canto ' + k), 0);
if (count>0){
var spanbadge = $('<span />');
spanbadge.attr('class', cantobadgeclass);
spanbadge.append(count)
//spanbadge.appendTo($('[name="' + cantica + 'Canto ' + k + '"]'))
spanbadge.appendTo($nctags.filter('[name="' + cantica + 'Canto ' + k + '"]'))
//spanbadge.insertAfter($('[name="'+cantica+'Canto '+k+'"]'))
}
}
}
console.log('badge end...')
//calcolo numero dei contesti
countResultContexts()
@ -1926,6 +1939,50 @@ function resetFrasi(){
};
//VISUALIZZAZIONE BADGE RISULTATI IN CANTICA
function showBadgeInCantica(resultsInCantica) {
var i = 0, totResultN = 0
//var listIcon = '<ion-icon name="list-outline"></ion-icon>';
for (cantica of cantiche) {
i += 1
let count = resultsInCantica.reduce((n, x) => n + (x === cantica), 0);
if (count > 0) {
totResultN += count
var spanbadgecantica = $('<span />');
spanbadgecantica.attr('class', 'badge badge-warning badge-pill mx-2');
spanbadgecantica.append(count)
spanbadgecantica.appendTo($('#cantica' + i + '-badge'))
//$('#cantica' + i).after(spanbadgecantica)
}
}
return (totResultN)
}
//VISUALIZZAZIONE BADGE RISULTATI IN CANTO
function showBadgeInCanto(resultsInCanto) {
var $nctags = $(' .navig-canto')
for (cantica of cantiche) {
for (k of Array(35).keys()) {
if (k == 0)
continue
let count = resultsInCanto.reduce((n, x) => n + (x === cantica + 'Canto ' + k), 0);
if (count > 0) {
var spanbadge = $('<span />');
spanbadge.attr('class', cantobadgeclass);
spanbadge.append(count)
//spanbadge.appendTo($('[name="' + cantica + 'Canto ' + k + '"]'))
spanbadge.appendTo($nctags.filter('[name="' + cantica + 'Canto ' + k + '"]'))
//spanbadge.insertAfter($('[name="'+cantica+'Canto '+k+'"]'))
}
}
}
}
/*
* REGOLE DI PARSING PER VISUALIZZAZIONE CATEGORIE GRAMMATICALI
*/