aggiunta euristica di ordinamento luoghi
This commit is contained in:
parent
954348a323
commit
ae46d9adee
@ -1,4 +1,4 @@
|
||||
{
|
||||
"repoId": "bc5fa7a7-7313-4845-954c-7227b0073b63",
|
||||
"lastSync": 0
|
||||
}
|
||||
}
|
||||
@ -213,7 +213,7 @@
|
||||
responsiveLayout="stack"
|
||||
scrollHeight="400px"
|
||||
[rowsPerPageOptions]="[10, 50, 100]"
|
||||
[globalFilterFields]="['struttura.nome']">
|
||||
[globalFilterFields]="['struttura.nome', 'struttura.struttureTipiStrutture']">
|
||||
<ng-template #caption>
|
||||
<div class="flex">
|
||||
<p-iconfield iconPosition="left"
|
||||
@ -253,11 +253,20 @@
|
||||
<tr>
|
||||
<ng-container *ngFor="let col of cols"
|
||||
[ngSwitch]="col.field">
|
||||
<td *ngSwitchCase="'struttura.struttureTipiStrutture'">
|
||||
<div>
|
||||
<ng-container *ngFor="let item of row.struttura.struttureTipiStrutture.split(',')">
|
||||
<span class="font-light">{{ item.trim() }}</span><br />
|
||||
</ng-container>
|
||||
</div>
|
||||
</td>
|
||||
<td *ngSwitchCase="'struttura.nome'">
|
||||
<p-rating *ngIf="row.struttura.stelline.length"
|
||||
[(ngModel)]="row.struttura.stelline.length"
|
||||
[readonly]="true" />
|
||||
<span class="font-light"> <b>{{ row.struttura.nome }}</b></span>
|
||||
<div>
|
||||
<p-rating *ngIf="row.struttura.stelline.length"
|
||||
[(ngModel)]="row.struttura.stelline.length"
|
||||
[readonly]="true" />
|
||||
<p><b>{{ row.struttura.nome }}</b></p>
|
||||
</div>
|
||||
<div *ngIf="row.struttura.sitoWeb"
|
||||
class="mt-4 ont-light">
|
||||
<a class="cursor-pointer hover:underline text-primary-700"
|
||||
|
||||
@ -124,9 +124,11 @@ export class StrutturePubblicheComponent {
|
||||
faHospital = faHospital;
|
||||
struttureConCoords: StrutturePubblicheResDto[] = [];
|
||||
|
||||
modelLuogo!: LuogoRes | null;
|
||||
|
||||
cols: TableColumn[] = [
|
||||
{
|
||||
header: 'Tipologia',
|
||||
field: 'struttura.struttureTipiStrutture',
|
||||
},
|
||||
{
|
||||
header: 'Strutture',
|
||||
field: 'struttura.nome',
|
||||
@ -196,13 +198,24 @@ export class StrutturePubblicheComponent {
|
||||
catchError((err) => {
|
||||
return of(null);
|
||||
}),
|
||||
map((res) => ({
|
||||
filteredLuoghiEsteso:
|
||||
res?.rows.map((res) => ({
|
||||
...res,
|
||||
dataKey: res.tipo + ' → ' + res.luogo,
|
||||
})) ?? [],
|
||||
})),
|
||||
map((res) => {
|
||||
const mapped =
|
||||
res?.rows.map((r) => ({
|
||||
...r,
|
||||
dataKey: r.tipo + ' → ' + r.luogo,
|
||||
})) ?? [];
|
||||
|
||||
// ⭐ ORDINAMENTO EURISTICO LOCALE
|
||||
const sorted = mapped.sort((a, b) => {
|
||||
const rankA = this.rankLuogo(a, event.query);
|
||||
const rankB = this.rankLuogo(b, event.query);
|
||||
|
||||
if (rankA !== rankB) return rankA - rankB;
|
||||
return a.luogo!.localeCompare(b.luogo!);
|
||||
});
|
||||
|
||||
return { filteredLuoghiEsteso: sorted };
|
||||
}),
|
||||
);
|
||||
this.state.connect(fetchCities$);
|
||||
}
|
||||
@ -449,4 +462,18 @@ export class StrutturePubblicheComponent {
|
||||
this.cercaStruttureForm.controls['luogo'].setValue(null);
|
||||
}
|
||||
}
|
||||
|
||||
private rankLuogo(luogo: any, query: string): number {
|
||||
const q = query.toLowerCase();
|
||||
const nome = luogo.luogo.toLowerCase();
|
||||
|
||||
// 1. Match perfetto (inizia per query)
|
||||
if (nome.startsWith(q)) return 0;
|
||||
|
||||
// 2. Match contenuto ma non all'inizio
|
||||
if (nome.includes(q)) return 1;
|
||||
|
||||
// 3. Nessun match diretto → meno rilevante
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user