Improved results filtering by lat lng

This commit is contained in:
Nedim Uka
2019-06-20 10:57:37 +02:00
parent 0f630e9ea4
commit c8ee848f0e

View File

@@ -183,27 +183,24 @@ module.exports = class OlxCrawler {
} }
async crawl() { async crawl() {
// TODO create URLS from db
const filteredResults = []; const filteredResults = [];
const realestateRequests = await allRERequest() const realestateRequests = await allRERequest()
const urls = this.createRequestUrls(realestateRequests); const urls = this.createRequestUrls(realestateRequests);
let results = await this.indexPages(urls, this.fromPage, this.toPage, this.maxResults); let results = await this.indexPages(urls, this.fromPage, this.toPage, this.maxResults);
for (const result of results) { for (const result of results) {
console.log(result);
for (const re1 of result) { for (const re1 of result) {
if (re1.lat !== undefined) { if (re1.lat !== undefined && re1.lat !== null && re1.lat !== "") {
console.log(re1.lat);
const pointInsideBoundingBox = await findPointInsideBoundingBox([re1.lng, re1.lat]); const pointInsideBoundingBox = await findPointInsideBoundingBox([re1.lng, re1.lat]);
console.log(pointInsideBoundingBox);
if (pointInsideBoundingBox[0].length !== 0) {
filteredResults.push(result);
}
} }
} }
} }
// console.log(results); return filteredResults;
return results;
} }
createRequestUrls(realestateRequests) { createRequestUrls(realestateRequests) {
@@ -218,8 +215,6 @@ module.exports = class OlxCrawler {
const priceMin = "od=" + request.priceMin; const priceMin = "od=" + request.priceMin;
const priceMax = "do=" + request.priceMax; const priceMax = "do=" + request.priceMax;
const olxUrl = "https://www.olx.ba/pretraga?" + realsestateType + "&id=2&stanje=0&vrstapregleda=tabela&sort_order=desc&" + region + "&" + municipality + "&" + priceMin + "&" + priceMax + "&vrsta=samoprodaja&" + sizeMin + "&" + sizeMax const olxUrl = "https://www.olx.ba/pretraga?" + realsestateType + "&id=2&stanje=0&vrstapregleda=tabela&sort_order=desc&" + region + "&" + municipality + "&" + priceMin + "&" + priceMax + "&vrsta=samoprodaja&" + sizeMin + "&" + sizeMax
console.log(olxUrl); console.log(olxUrl);
urls.push(olxUrl); urls.push(olxUrl);