const findbyaddress = await hosts.findAll({
where: {
[Op.or]: [
{
mainAddress: {
[Op.substring]: querydata.search,
},
},
{ houseInfo: querydata.search },
],
},
order: [["createdAt", "DESC"]],
include: [
{
model: images,
required: false,
attributes: [
"hostId",
"postImageURL",
"thumbnailURL",
"userImageURL",
],
},
],
});
const findbytitle = await hosts.findAll({
where: {
title: {
[Op.substring]: querydata.search,
},
},
order: [["createdAt", "DESC"]],
include: [
{
model: images,
required: false,
attributes: [
"hostId",
"postImageURL",
"thumbnailURL",
"userImageURL",
],
},
],
});
let hostContent = await hosts.findAll({
where: {
hostContent: {
[Op.substring]: querydata.search,
},
},
order: [["createdAt", "DESC"]],
include: [
{
model: images,
required: false,
attributes: [
"hostId",
"postImageURL",
"thumbnailURL",
"userImageURL",
],
},
],
});
for (let h = 0; h < findbyaddress.length; h++) {
searchResult.push(findbyaddress[h]);
searchResultId.push(findbyaddress[h].hostId);
}
for (let p = 0; p < findbytitle.length; p++) {
if (searchResultId.includes(findbytitle[p].hostId)) {
} else {
searchResult.push(findbytitle[p]);
searchResultId.push(findbytitle[p].hostId);
}
}
for (let i = 0; i < hostContent.length; i++) {
if (searchResultId.includes(hostContent[i].hostId)) {
} else {
searchResult.push(hostContent[i]);
searchResultId.push(hostContent[i].hostId);
}
}