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