Queries for db search changed. Needs testing.
This commit is contained in:
@@ -88,7 +88,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
adType,
|
||||
realEstateType,
|
||||
areaToSearch,
|
||||
//
|
||||
gardenSizeMin,
|
||||
gardenSizeMax,
|
||||
numberOfRoomsMin,
|
||||
@@ -102,7 +101,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
elevator,
|
||||
newBuilding,
|
||||
accessRoadType
|
||||
//
|
||||
} = searchRequest;
|
||||
|
||||
const longitudeColumn = sequelize.col("locationLong");
|
||||
@@ -131,52 +129,30 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
|
||||
const geoSearchQueryPart = sequelize.where(contains, true);
|
||||
|
||||
//Query for case of complete ads
|
||||
//General queries contain only attributes that are defined for every searchreq
|
||||
|
||||
//WIP This wont work, need to separate queries by adType and realEstateType
|
||||
//because for example flat does not have gardenSize and that can't be in query
|
||||
|
||||
//Query for case of complete ads
|
||||
const query = {
|
||||
adType,
|
||||
realEstateType,
|
||||
price: {
|
||||
[Op.lte]: priceMax,
|
||||
[Op.gte]: priceMin
|
||||
},
|
||||
area: {
|
||||
[Op.lte]: sizeMax,
|
||||
[Op.gte]: sizeMin
|
||||
},
|
||||
[Op.and]: geoSearchQueryPart,
|
||||
//
|
||||
gardenSize: {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
},
|
||||
numberOfRooms: {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
},
|
||||
numberOfFloors: {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
},
|
||||
floor: {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
},
|
||||
accessRoadType: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: 'ANY',
|
||||
[Op.eq]: accessRoadType
|
||||
}
|
||||
},
|
||||
balcony,
|
||||
newBuilding,
|
||||
elevator
|
||||
};
|
||||
adType,
|
||||
realEstateType,
|
||||
price: {
|
||||
[Op.lte]: priceMax,
|
||||
[Op.gte]: priceMin
|
||||
},
|
||||
area: {
|
||||
[Op.lte]: sizeMax,
|
||||
[Op.gte]: sizeMin
|
||||
},
|
||||
accessRoadType: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: 'ANY',
|
||||
[Op.eq]: accessRoadType
|
||||
}
|
||||
},
|
||||
[Op.and]: geoSearchQueryPart
|
||||
}
|
||||
|
||||
//Query for case of incomplete ads
|
||||
//Query for case of incomplete ads
|
||||
const queryIncludeIncomplete = {
|
||||
adType,
|
||||
realEstateType,
|
||||
@@ -198,44 +174,6 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
[Op.and]: geoSearchQueryPart,
|
||||
//
|
||||
gardenSize: {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
numberOfRooms: {
|
||||
[Op.or]: {
|
||||
[Op.and]: {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
numberOfFloors: {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
floor: {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
accessRoadType: {
|
||||
[Op.or]: {
|
||||
[Op.eq]: 'ANY',
|
||||
@@ -243,25 +181,109 @@ const findRealEstatesForSearchRequest = async (searchRequest, maxResults) => {
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
balcony: {
|
||||
[Op.and]: geoSearchQueryPart
|
||||
}
|
||||
|
||||
//Every other attribute is checked separately and included in query only if it is defined
|
||||
if (gardenSizeMax && gardenSizeMin) {
|
||||
query.gardenSize = {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
}
|
||||
queryIncludeIncomplete.gardenSize = {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: gardenSizeMax,
|
||||
[Op.gte]: gardenSizeMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfRoomsMin && numberOfRoomsMax) {
|
||||
query.numberOfRooms = {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
}
|
||||
queryIncludeIncomplete.numberOfRooms = {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: numberOfRoomsMax,
|
||||
[Op.gte]: numberOfRoomsMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfFloorsMin && numberOfFloorsMax) {
|
||||
query.numberOfFloors = {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
}
|
||||
queryIncludeIncomplete.numberOfFloors = {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: numberOfFloorsMax,
|
||||
[Op.gte]: numberOfFloorsMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (floorMin && floorMax) {
|
||||
query.floor = {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
}
|
||||
queryIncludeIncomplete.floor = {
|
||||
[Op.or] : {
|
||||
[Op.and]: {
|
||||
[Op.lte]: floorMax,
|
||||
[Op.gte]: floorMin
|
||||
},
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (balcony) {
|
||||
query.balcony = {
|
||||
[Op.eq]: balcony
|
||||
}
|
||||
queryIncludeIncomplete.balcony = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: balcony,
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
newBuilding: {
|
||||
}
|
||||
}
|
||||
|
||||
if (newBuilding) {
|
||||
query.newBuilding = {
|
||||
[Op.eq]: newBuilding
|
||||
}
|
||||
queryIncludeIncomplete.newBuilding = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: newBuilding,
|
||||
[Op.is]: null
|
||||
}
|
||||
},
|
||||
elevator: {
|
||||
}
|
||||
}
|
||||
|
||||
if (elevator) {
|
||||
query.elevator = {
|
||||
[Op.eq]: elevator
|
||||
}
|
||||
queryIncludeIncomplete.elevator = {
|
||||
[Op.or]: {
|
||||
[Op.eq]: elevator,
|
||||
[Op.is]: null
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const order = [["updatedAt", "desc"]];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user