From 9a204b2f985c29020d8a177ed2894b98a1b4adc5 Mon Sep 17 00:00:00 2001 From: MD AL AMIN TALUKDAR <129589283+alamin655@users.noreply.github.com> Date: Fri, 19 May 2023 17:13:11 +0530 Subject: [PATCH 1/2] Fix page_url assignment in search route The page_url variable in the search route was not being properly assigned in certain cases. This commit fixes the issue by ensuring that page_url is assigned the correct value based on the search parameters. In the match expression, the conditions have been adjusted to correctly handle the page number and construct the appropriate page_url. This ensures that the generated URL for the search page is accurate and reflects the search query and page number. This change improves the functionality and reliability of the search route by correctly setting the page_url variable based on the provided search parameters. --- src/server/routes.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/server/routes.rs b/src/server/routes.rs index e97bc2b..5116bac 100644 --- a/src/server/routes.rs +++ b/src/server/routes.rs @@ -81,11 +81,10 @@ pub async fn search( .insert_header(("location", "/")) .finish()) } else { - // Initialize the page url as an empty string - let mut page_url = String::new(); + let page_url: String; // Declare the page_url variable without initializing it - // Find whether the page is valid page number if not then return - // the first page number and also construct the page_url accordingly + // ... + let page = match params.page { Some(page_number) => { if page_number <= 1 { @@ -99,7 +98,7 @@ pub async fn search( "http://{}:{}/search?q={}&page={}", config.binding_ip_addr, config.port, query, page_number ); - + page_number } } @@ -111,11 +110,13 @@ pub async fn search( req.uri(), 1 ); - + 1 } }; - + + // Use the page_url variable as needed + // fetch the cached results json. let cached_results_json = redis_cache.cached_results_json(&page_url); // check if fetched results was indeed fetched or it was an error and if so From ae2fdb557cd801a833e2e2c85b1dea14edd5e7c4 Mon Sep 17 00:00:00 2001 From: MD AL AMIN TALUKDAR <129589283+alamin655@users.noreply.github.com> Date: Sat, 20 May 2023 08:01:24 +0530 Subject: [PATCH 2/2] Removed unnecessary comment --- src/server/routes.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/server/routes.rs b/src/server/routes.rs index 5116bac..ed2299f 100644 --- a/src/server/routes.rs +++ b/src/server/routes.rs @@ -114,9 +114,7 @@ pub async fn search( 1 } }; - - // Use the page_url variable as needed - + // fetch the cached results json. let cached_results_json = redis_cache.cached_results_json(&page_url); // check if fetched results was indeed fetched or it was an error and if so