Delete ununsed files
This commit is contained in:
parent
e76e558a7a
commit
b608879b88
@ -1,13 +0,0 @@
|
|||||||
import { Property } from "../../db/mysql/db.config";
|
|
||||||
import { groupSimilarProperties } from "../../services/fusejs/filterProperties";
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
try {
|
|
||||||
const candidateProperties = await Property.findAll();
|
|
||||||
const properties = groupSimilarProperties(candidateProperties);
|
|
||||||
return { success: true, properties };
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error listing properties:", error);
|
|
||||||
return { success: false, message: error.message };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { Property } from "../../db/mysql/db.config";
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
try {
|
|
||||||
const body = await readBody(event);
|
|
||||||
const newProperty = await Property.create(body);
|
|
||||||
return { success: true, property: newProperty };
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating property:", error);
|
|
||||||
return { success: false, message: error.message };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
// server/models/Property.js
|
|
||||||
import { DataTypes } from "sequelize";
|
|
||||||
|
|
||||||
export default function Property (sequelize) {
|
|
||||||
return sequelize.define(
|
|
||||||
"Property",
|
|
||||||
{
|
|
||||||
id: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
unique: true,
|
|
||||||
primaryKey: true,
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
url: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
price: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
rooms: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
area: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
level: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: DataTypes.TEXT,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
pic: {
|
|
||||||
type: DataTypes.TEXT,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
baths: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
neighborhood: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
phone: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tableName: "properties",
|
|
||||||
timestamps: true, // Incluye createdAt y updatedAt
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
// utils/filterProperties.js
|
|
||||||
import Fuse from 'fuse.js';
|
|
||||||
|
|
||||||
export const filterSimilarProperties = (properties) => {
|
|
||||||
const options = {
|
|
||||||
keys: ['_title'], // Solo buscamos similitud en el título
|
|
||||||
threshold: 0.55, // 0.6 es un umbral para 40% de similitud
|
|
||||||
includeScore: true // Incluye la puntuación de similitud
|
|
||||||
};
|
|
||||||
|
|
||||||
const fuse = new Fuse(properties, options);
|
|
||||||
const uniqueProperties = [];
|
|
||||||
const seen = new Set(); // Usaremos un conjunto para rastrear propiedades vistas
|
|
||||||
|
|
||||||
properties.forEach((property) => {
|
|
||||||
const propertyData = property;
|
|
||||||
if (!seen.has(propertyData._id)) {
|
|
||||||
// Inicializa el array para IDs similares en dataValues
|
|
||||||
propertyData.similarIds = [];
|
|
||||||
|
|
||||||
// Buscamos propiedades similares por título
|
|
||||||
const result = fuse.search(propertyData._title).filter((res) => {
|
|
||||||
const similarProperty = res.item;
|
|
||||||
// Filtramos resultados que no sean la misma propiedad y sean similares en título
|
|
||||||
const isSimilar = res.item._id !== propertyData._id && res.score < options.threshold;
|
|
||||||
|
|
||||||
if (isSimilar) {
|
|
||||||
propertyData.similarIds.push(similarProperty._id);
|
|
||||||
|
|
||||||
// Enriquecer la propiedad actual con datos de la propiedad similar
|
|
||||||
// propertyData.title = getLongest(propertyData.title, similarProperty.title);
|
|
||||||
// propertyData.url = propertyData.url || similarProperty.url;
|
|
||||||
// propertyData.price = propertyData.price || similarProperty.price;
|
|
||||||
// propertyData.rooms = propertyData.rooms || similarProperty.rooms;
|
|
||||||
// propertyData.area = propertyData.area || similarProperty.area;
|
|
||||||
// propertyData.level = propertyData.level || similarProperty.level;
|
|
||||||
// propertyData.description = getLongest(propertyData.description, similarProperty.description);
|
|
||||||
// propertyData.pic = propertyData.pic || similarProperty.pic;
|
|
||||||
// propertyData.baths = propertyData.baths || similarProperty.baths;
|
|
||||||
// propertyData.neighborhood = propertyData.neighborhood || similarProperty.neighborhood;
|
|
||||||
// propertyData.phone = propertyData.phone || similarProperty.phone;
|
|
||||||
|
|
||||||
// Marcar la propiedad similar como vista
|
|
||||||
//seen.add(similarProperty.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isSimilar;
|
|
||||||
});
|
|
||||||
|
|
||||||
uniqueProperties.push(property);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return uniqueProperties;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const groupSimilarProperties = (properties) => {
|
|
||||||
const filteredProperties = filterSimilarProperties(properties);
|
|
||||||
const groups = [];
|
|
||||||
const visited = new Set();
|
|
||||||
|
|
||||||
filteredProperties.forEach((property) => {
|
|
||||||
const propertyId = property._id;
|
|
||||||
if (!visited.has(propertyId)) {
|
|
||||||
const group = [property];
|
|
||||||
visited.add(propertyId);
|
|
||||||
|
|
||||||
const queue = [...property.similarIds];
|
|
||||||
while (queue.length > 0) {
|
|
||||||
const currentId = queue.shift();
|
|
||||||
if (!visited.has(currentId)) {
|
|
||||||
const similarProperty = filteredProperties.find(prop => prop._id === currentId);
|
|
||||||
if (similarProperty) {
|
|
||||||
group.push(similarProperty);
|
|
||||||
visited.add(currentId);
|
|
||||||
queue.push(...similarProperty.similarIds.filter(id => !visited.has(id)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
groups.push(group);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Convert groups to desired output format
|
|
||||||
const groupedProperties = groups.reduce((acc, group, index) => {
|
|
||||||
acc[index] = group;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
return groupedProperties;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const getLongest = (a, b) => {
|
|
||||||
if (!a) return b;
|
|
||||||
if (!b) return a;
|
|
||||||
return a.length >= b.length ? a : b;
|
|
||||||
};
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
import stringSimilarity from 'string-similarity';
|
|
||||||
|
|
||||||
export class FuzzySearchService {
|
|
||||||
_data: any = [];
|
|
||||||
_threshold: number;
|
|
||||||
|
|
||||||
private constructor(data, threshold) {
|
|
||||||
this._data = data;
|
|
||||||
this._threshold = threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static create(data, threshold = 0.7) {
|
|
||||||
return new FuzzySearchService(data, threshold);
|
|
||||||
}
|
|
||||||
|
|
||||||
matchSimilarProperty(property) {
|
|
||||||
const groupedData: Map<string, unknown[]> = new Map();
|
|
||||||
|
|
||||||
this.data.forEach((obj) => {
|
|
||||||
let found = false;
|
|
||||||
|
|
||||||
for (const [key, group] of groupedData.entries()) {
|
|
||||||
const representativeObj: any = group[0];
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.isPropertySimilar(representativeObj[property], obj[property])
|
|
||||||
) {
|
|
||||||
group.push(obj);
|
|
||||||
groupedData.set(key, group);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
// Crea una nueva clave en el mapa para un nuevo grupo
|
|
||||||
groupedData.set(obj.id, [obj]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return groupedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
matchExactProperty(property) {
|
|
||||||
// Implement your exact property matching logic here
|
|
||||||
// Return the matched property
|
|
||||||
}
|
|
||||||
|
|
||||||
matchExactProperties(properties) {
|
|
||||||
// Implement your exact properties matching logic here
|
|
||||||
// Return the matched properties
|
|
||||||
}
|
|
||||||
|
|
||||||
isPropertySimilar(property, otherProperty: string): boolean {
|
|
||||||
const similarity = stringSimilarity.compareTwoStrings(property, otherProperty);
|
|
||||||
return similarity >= this.threshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
get data() {
|
|
||||||
return this._data;
|
|
||||||
}
|
|
||||||
|
|
||||||
get threshold() {
|
|
||||||
return this._threshold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user