MD AL AMIN TALUKDAR commited on
Commit
9a204b2
1 Parent(s): feb5ea8

Fix page_url assignment in search route

Browse files

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.

Files changed (1) hide show
  1. src/server/routes.rs +8 -7
src/server/routes.rs CHANGED
@@ -81,11 +81,10 @@ pub async fn search(
81
  .insert_header(("location", "/"))
82
  .finish())
83
  } else {
84
- // Initialize the page url as an empty string
85
- let mut page_url = String::new();
86
 
87
- // Find whether the page is valid page number if not then return
88
- // the first page number and also construct the page_url accordingly
89
  let page = match params.page {
90
  Some(page_number) => {
91
  if page_number <= 1 {
@@ -99,7 +98,7 @@ pub async fn search(
99
  "http://{}:{}/search?q={}&page={}",
100
  config.binding_ip_addr, config.port, query, page_number
101
  );
102
-
103
  page_number
104
  }
105
  }
@@ -111,11 +110,13 @@ pub async fn search(
111
  req.uri(),
112
  1
113
  );
114
-
115
  1
116
  }
117
  };
118
-
 
 
119
  // fetch the cached results json.
120
  let cached_results_json = redis_cache.cached_results_json(&page_url);
121
  // check if fetched results was indeed fetched or it was an error and if so
 
81
  .insert_header(("location", "/"))
82
  .finish())
83
  } else {
84
+ let page_url: String; // Declare the page_url variable without initializing it
 
85
 
86
+ // ...
87
+
88
  let page = match params.page {
89
  Some(page_number) => {
90
  if page_number <= 1 {
 
98
  "http://{}:{}/search?q={}&page={}",
99
  config.binding_ip_addr, config.port, query, page_number
100
  );
101
+
102
  page_number
103
  }
104
  }
 
110
  req.uri(),
111
  1
112
  );
113
+
114
  1
115
  }
116
  };
117
+
118
+ // Use the page_url variable as needed
119
+
120
  // fetch the cached results json.
121
  let cached_results_json = redis_cache.cached_results_json(&page_url);
122
  // check if fetched results was indeed fetched or it was an error and if so