diff --git a/crawler/package.json b/crawler/package.json index f427283..5a5c698 100644 --- a/crawler/package.json +++ b/crawler/package.json @@ -21,6 +21,7 @@ "node-fetch": "^3.3.2", "puppeteer": "^22.1.0", "redis": "^4.6.13", + "redis-om": "^0.4.3", "winston": "^3.13.0", "yargs": "^17.7.2" } diff --git a/crawler/perftest.ts b/crawler/perftest.ts index df84327..672e3f4 100644 --- a/crawler/perftest.ts +++ b/crawler/perftest.ts @@ -1,5 +1,42 @@ import {createLogger,transports, format} from 'winston'; import { createClient } from 'redis'; +import { Repository, Schema, SchemaDefinition } from 'redis-om'; +const baseListingSchemaDef : SchemaDefinition = { + id: { type: 'string' }, + userId: { type: 'string' }, + listingsCategory: { type: 'string' }, + title: { type: 'string' }, + description: { type: 'string' }, + country: { type: 'string' }, + state:{ type: 'string' }, + city:{ type: 'string' }, + zipCode: { type: 'number' }, + type: { type: 'string' }, + price: { type: 'number' }, + favoritesForUser:{ type: 'string[]' }, + hideImage:{ type: 'boolean' }, + draft:{ type: 'boolean' }, + created:{ type: 'date' }, + updated:{ type: 'date' } + } +const businessListingSchemaDef : SchemaDefinition = { + ...baseListingSchemaDef, + salesRevenue: { type: 'number' }, + cashFlow: { type: 'number' }, + employees: { type: 'number' }, + established: { type: 'number' }, + internalListingNumber: { type: 'number' }, + realEstateIncluded:{ type: 'boolean' }, + leasedLocation:{ type: 'boolean' }, + franchiseResale:{ type: 'boolean' }, + supportAndTraining: { type: 'string' }, + reasonForSale: { type: 'string' }, + brokerLicencing: { type: 'string' }, + internals: { type: 'string' }, +} +const businessListingSchema = new Schema('business',businessListingSchemaDef, { + dataStructure: 'JSON' +}) const logger = createLogger({ transports: [ new transports.Console(), @@ -15,11 +52,17 @@ const logger = createLogger({ const redis = await createClient() .on('error', err => console.log('Redis Client Error', err)) .connect(); +const businessListingRepository = new Repository(businessListingSchema, redis); (async () => { logger.info(`start findBusinessListings:`); const result = await redis.ft.search('business:index','*',{LIMIT:{from:0,size:50}}); - result.documents.forEach(d=>console.log(d)); + //result.documents.forEach(d=>console.log(d)); logger.info(`end findBusinessListings:`); + + logger.info(`start businessListingRepository:`); + await businessListingRepository.search().return.all() + logger.info(`end businessListingRepository:`); + redis.disconnect(); })(); \ No newline at end of file