From 3be9f6b76d8ba5ecd00ff1852bd5f0155030ba0e Mon Sep 17 00:00:00 2001 From: PrasanKumar Date: Tue, 27 Feb 2024 17:42:33 +0530 Subject: [PATCH 1/3] adding geo search tile in solutions page --- .../getting-started-geo/index-geo-search.mdx | 92 ++++++++++--------- docs/howtos/solutions/index-solutions.mdx | 14 +++ 2 files changed, 64 insertions(+), 42 deletions(-) diff --git a/docs/howtos/solutions/geo/getting-started-geo/index-geo-search.mdx b/docs/howtos/solutions/geo/getting-started-geo/index-geo-search.mdx index 14be8f9885..a1fd881dbf 100644 --- a/docs/howtos/solutions/geo/getting-started-geo/index-geo-search.mdx +++ b/docs/howtos/solutions/geo/getting-started-geo/index-geo-search.mdx @@ -266,7 +266,7 @@ This section outlines the implementation of the `getStoreProductsByGeoFilter` AP 4. **Result Processing**: The function filters out duplicate products across different stores, ensuring unique product listings in the final output. It then formats the store locations into a more readable structure and compiles the final list of products to return. -```js +```ts import * as StoreInventoryRepo from '../../../common/models/store-inventory-repo'; interface IInventoryBodyFilter { @@ -276,7 +276,7 @@ interface IInventoryBodyFilter { userLocation?: { latitude?: number; longitude?: number; - }, + }; } const searchStoreInventoryByGeoFilter = async ( @@ -286,13 +286,14 @@ const searchStoreInventoryByGeoFilter = async ( const redisClient = getNodeRedisClient(); const repository = StoreInventoryRepo.getRepository(); let storeProducts: IStoreInventory[] = []; - const trimmedStoreProducts: IStoreInventory[] = [] // similar item of other stores are removed + const trimmedStoreProducts: IStoreInventory[] = []; // similar item of other stores are removed const uniqueProductIds = {}; - if (repository - && _inventoryFilter?.userLocation?.latitude - && _inventoryFilter?.userLocation?.longitude) { - + if ( + repository && + _inventoryFilter?.userLocation?.latitude && + _inventoryFilter?.userLocation?.longitude + ) { const lat = _inventoryFilter.userLocation.latitude; const long = _inventoryFilter.userLocation.longitude; const radiusInMiles = _inventoryFilter.searchRadiusInMiles || 500; @@ -306,17 +307,13 @@ const searchStoreInventoryByGeoFilter = async ( .gt(0) .and('storeLocation') .inRadius((circle) => { - return circle - .latitude(lat) - .longitude(long) - .radius(radiusInMiles) - .miles + return circle.latitude(lat).longitude(long).radius(radiusInMiles).miles; }); if (_inventoryFilter.productDisplayName) { queryBuilder = queryBuilder .and('productDisplayName') - .matches(_inventoryFilter.productDisplayName) + .matches(_inventoryFilter.productDisplayName); } console.log(queryBuilder.query); @@ -325,26 +322,38 @@ const searchStoreInventoryByGeoFilter = async ( FT.SEARCH "storeInventory:storeInventoryId:index" "( ( ( (@statusCode:[1 1]) (@stockQty:[(0 +inf]) ) (@storeLocation:[-73.968285 40.785091 50 mi]) ) (@productDisplayName:'puma') )" */ - // (3) --- Executing the Query + // (3) --- Executing the Query const indexName = `storeInventory:storeInventoryId:index`; const aggregator = await redisClient.ft.aggregate( indexName, queryBuilder.query, { - LOAD: ["@storeId", "@storeName", "@storeLocation", "@productId", "@productDisplayName", "@stockQty"], - STEPS: [{ - type: AggregateSteps.APPLY, - expression: `geodistance(@storeLocation, ${long}, ${lat})/1609`, - AS: 'distInMiles' - }, { - type: AggregateSteps.SORTBY, - BY: ["@distInMiles", "@productId"] - }, { - type: AggregateSteps.LIMIT, - from: 0, - size: 1000, - }] - }); + LOAD: [ + '@storeId', + '@storeName', + '@storeLocation', + '@productId', + '@productDisplayName', + '@stockQty', + ], + STEPS: [ + { + type: AggregateSteps.APPLY, + expression: `geodistance(@storeLocation, ${long}, ${lat})/1609`, + AS: 'distInMiles', + }, + { + type: AggregateSteps.SORTBY, + BY: ['@distInMiles', '@productId'], + }, + { + type: AggregateSteps.LIMIT, + from: 0, + size: 1000, + }, + ], + }, + ); /* Sample command to run on CLI FT.AGGREGATE "storeInventory:storeInventoryId:index" @@ -360,37 +369,36 @@ const searchStoreInventoryByGeoFilter = async ( if (!storeProducts.length) { // throw `Product not found with in ${radiusInMiles}mi range!`; - } - else { - - // (4) --- Result Processing + } else { + // (4) --- Result Processing storeProducts.forEach((storeProduct) => { - if (storeProduct?.productId && !uniqueProductIds[storeProduct.productId]) { + if ( + storeProduct?.productId && + !uniqueProductIds[storeProduct.productId] + ) { uniqueProductIds[storeProduct.productId] = true; - if (typeof storeProduct.storeLocation == "string") { - const location = storeProduct.storeLocation.split(","); + if (typeof storeProduct.storeLocation == 'string') { + const location = storeProduct.storeLocation.split(','); storeProduct.storeLocation = { longitude: Number(location[0]), latitude: Number(location[1]), - } + }; } - trimmedStoreProducts.push(storeProduct) + trimmedStoreProducts.push(storeProduct); } }); } - } - else { - throw "Mandatory fields like userLocation latitude / longitude missing !" + } else { + throw 'Mandatory fields like userLocation latitude / longitude missing !'; } return { storeProducts: trimmedStoreProducts, - productIds: Object.keys(uniqueProductIds) + productIds: Object.keys(uniqueProductIds), }; }; - ``` The implementation demonstrates a practical use case for Redis's Geo Location search capabilities, showcasing how to perform proximity searches combined with other filtering criteria (like product name) and present the results in a user-friendly format. diff --git a/docs/howtos/solutions/index-solutions.mdx b/docs/howtos/solutions/index-solutions.mdx index e93e8742c2..113d620e43 100644 --- a/docs/howtos/solutions/index-solutions.mdx +++ b/docs/howtos/solutions/index-solutions.mdx @@ -215,3 +215,17 @@ Learn how to easily build, test and deploy code for common microservice and cach + +## Geo Location Search + +
+ +
+ +
+ +
From 8b7ba79c3f5df29cbb34a7952a8cc30e5e982a27 Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Tue, 16 Apr 2024 13:09:38 -0700 Subject: [PATCH 2/3] redirecting to learn --- docusaurus.config.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index 9862c08843..918fd6ba8d 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -1,6 +1,7 @@ const path = require('path'); module.exports = { + clientModules: ['./redirect.js'], title: 'The Home of Redis Developers', tagline: 'Learn all the best practices to get up and running with Redis in no time. Get started and discover the power of Redis, whether on your local machines or in the cloud.', @@ -181,7 +182,7 @@ module.exports = { name: 'Tugdual Grall', title: 'Former Technical Marketing Manager at Redis', image: 'profile_pic_tugdual_grall.png', - } + }, }, }, themeConfig: @@ -202,7 +203,7 @@ module.exports = { 'elixir', 'groovy', 'sql', - 'typescript' + 'typescript', ], }, @@ -298,14 +299,14 @@ module.exports = { // Useful if you want to support a single color mode disableSwitch: false, }, - announcementBar: { - id: 'redis-7-2-release', // Any value that will identify this message. - content: - '', - backgroundColor: 'rgb(210, 215, 254)', // Defaults to `#fff`. - textColor: 'rgb(22 31 49)', // Defaults to `#000`. - isCloseable: true, // Defaults to `true`. - }, + announcementBar: { + id: 'redis-7-2-release', // Any value that will identify this message. + content: + '', + backgroundColor: 'rgb(210, 215, 254)', // Defaults to `#fff`. + textColor: 'rgb(22 31 49)', // Defaults to `#000`. + isCloseable: true, // Defaults to `true`. + }, }), presets: [ [ @@ -354,5 +355,5 @@ module.exports = { plugins: [ 'docusaurus-plugin-sass', path.resolve(__dirname, 'plugins', 'gtm'), - ] + ], }; From 73b934ea4fd25a6d4da8f6c81b712712f545b44e Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Tue, 16 Apr 2024 13:17:23 -0700 Subject: [PATCH 3/3] adding redirect.js : --- redirect.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 redirect.js diff --git a/redirect.js b/redirect.js new file mode 100644 index 0000000000..e0349d27aa --- /dev/null +++ b/redirect.js @@ -0,0 +1,40 @@ +import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; + +function tryRedirect() { + if (location.host.includes('learn.')) { + return; + } + + let path = location.pathname; + + if (!path.startsWith('/')) { + path = `/${path}`; + } + + location.replace(`https://redis.io/learn${path}`); +} + +export default (function () { + if (!ExecutionEnvironment.canUseDOM) { + return null; + } + + return { + onRouteUpdate({ location }) { + console.log(location); + + tryRedirect(); + setTimeout(tryRedirect, 50); + setTimeout(tryRedirect, 150); + setTimeout(tryRedirect, 250); + setTimeout(tryRedirect, 350); + setTimeout(tryRedirect, 450); + setTimeout(tryRedirect, 550); + setTimeout(tryRedirect, 650); + setTimeout(tryRedirect, 750); + setTimeout(tryRedirect, 850); + setTimeout(tryRedirect, 950); + setTimeout(tryRedirect, 1050); + }, + }; +})();