n8n-nodes-fuse-postgre-master
Version:
Node do n8n para buscas fuzzy no PostgreSQL usando Fuse.js.
25 lines (24 loc) • 1.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fuseSearch = void 0;
const fuse_js_1 = __importDefault(require("fuse.js"));
function fuseSearch(data, searchTerm, options) {
var _a, _b, _c, _d;
const fuse = new fuse_js_1.default(data, {
keys: options.keys,
threshold: (_a = options.threshold) !== null && _a !== void 0 ? _a : 0.6,
distance: (_b = options.distance) !== null && _b !== void 0 ? _b : 100,
minMatchCharLength: (_c = options.minMatchCharLength) !== null && _c !== void 0 ? _c : 1,
isCaseSensitive: (_d = options.isCaseSensitive) !== null && _d !== void 0 ? _d : false,
});
const searchResults = fuse.search(searchTerm);
const limitedResults = options.limit ? searchResults.slice(0, options.limit) : searchResults;
return {
results: limitedResults.map(r => r.item),
totalResults: searchResults.length,
};
}
exports.fuseSearch = fuseSearch;