- Ricerca Titolo per nome o autore o ISBN o codice articolo

This commit is contained in:
Surya Paolo
2025-03-31 23:56:01 +02:00
parent 789dc1dcae
commit 5431fe118e
9 changed files with 345 additions and 114 deletions

View File

@@ -254,55 +254,44 @@ module.exports.executeQueryPickup = async function (idapp, params) {
filterfindexact = { comune: strfind };
}
let limit = 10;
let limit = 20;
let risexact = [];
let filterfind = {
idapp,
'productInfo.name': {
$regex: `\\b${strfind}`, // Usa \\b per trovare solo le parole che iniziano con strfind
$options: 'i' // Rendi la ricerca case-insensitive
}
};
/*
let aggr1 = [
{
$lookup: {
from: 'productinfos',
localField: 'idProductInfo',
foreignField: '_id',
as: 'productInfo'
}
},
{
$lookup: {
from: 'authors',
localField: 'idAuthors',
foreignField: '_id',
as: 'authors'
}
},
{
$match: { 'productInfo.name': strfind },
},
{ $limit: 1 },
{
$project: {
name: { $concat: ["$productInfo.name", " (", "$authors", ")"] },
$or: [
{
'productInfo.name': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind
$options: 'i' // Rende la ricerca case-insensitive
}
},
},
];
if (params.filter) {
filterfind = { ...params.filter, ...filterfind };
limit = 200;
} else {
// risexact = await City.find(filterfindexact, {comune: 1, prov: 1, reg: 1}).lean();
risexact = await City.aggregate(aggr1);
}
*/
{
'productInfo.code': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind
$options: 'i' // Rende la ricerca case-insensitive
}
},
{
'productInfo.sku': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind
$options: 'i' // Rende la ricerca case-insensitive
}
},
{
'productInfo.authors.name': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind nel nome dell'autore
$options: 'i' // Rende la ricerca case-insensitive
}
},
{
'productInfo.authors.surname': {
$regex: `\\b${strfind}`, // Cerca parole che iniziano con strfind nel cognome dell'autore
$options: 'i' // Rende la ricerca case-insensitive
}
},
]
};
if (params.filter) {
filterfind = { ...params.filter, ...filterfind };
@@ -327,24 +316,34 @@ module.exports.executeQueryPickup = async function (idapp, params) {
{
$lookup: {
from: 'authors',
localField: 'idAuthors',
localField: 'productInfo.idAuthors',
foreignField: '_id',
as: 'authors'
as: 'productInfo.authors'
}
},
{
$unwind: {
path: '$authors',
preserveNullAndEmptyArrays: true,
},
},
{
$match: filterfind,
},
{ $limit: limit },
{
$project: {
name: '$productInfo.name',
},
},
name: '$productInfo.name', // Nome del prodotto
authors: '$productInfo.authors',
productInfo: {
name: '$productInfo.name', // Nome del prodotto
authors: '$productInfo.authors',
},
}
}
];
// let ris = await City.find(filterfind, {comune: 1, prov: 1, reg: 1}).lean().limit(limit);
let ris = await this.aggregate(aggr2).limit(limit);
return [...risexact, ...ris];