|
5 | 5 | use crate::{ |
6 | 6 | appstate::AppState, |
7 | 7 | errors::{AtomicServerError, AtomicServerResult}, |
| 8 | + helpers::get_subject, |
8 | 9 | search::{resource_to_facet, Fields}, |
9 | 10 | }; |
10 | 11 | use actix_web::{web, HttpResponse}; |
@@ -48,6 +49,7 @@ pub async fn search_query( |
48 | 49 | appstate: web::Data<AppState>, |
49 | 50 | params: web::Query<SearchQuery>, |
50 | 51 | req: actix_web::HttpRequest, |
| 52 | + conn: actix_web::dev::ConnectionInfo, |
51 | 53 | ) -> AtomicServerResult<HttpResponse> { |
52 | 54 | let mut timer = Timer::new(); |
53 | 55 | let store = &appstate.store; |
@@ -76,19 +78,7 @@ pub async fn search_query( |
76 | 78 | let subjects = docs_to_subjects(top_docs, &fields, &searcher)?; |
77 | 79 |
|
78 | 80 | // Create a valid atomic data resource. |
79 | | - // You'd think there would be a simpler way of getting the requested URL... |
80 | | - // See https://github.com/actix/actix-web/issues/2895 |
81 | | - let subject: String = store |
82 | | - .get_self_url() |
83 | | - .ok_or("No base URL set")? |
84 | | - .url() |
85 | | - .join( |
86 | | - req.uri() |
87 | | - .path_and_query() |
88 | | - .ok_or("Add a query param")? |
89 | | - .as_str(), |
90 | | - )? |
91 | | - .to_string(); |
| 81 | + let subject: String = get_subject(&req, &conn, &appstate)?; |
92 | 82 |
|
93 | 83 | let mut results_resource = atomic_lib::plugins::search::search_endpoint().to_resource(store)?; |
94 | 84 | results_resource.set_subject(subject.clone()); |
|
0 commit comments