integrate the search batcher in the search route

This commit is contained in:
Tamo 2021-10-19 19:23:11 +02:00 committed by marin postma
parent 35ffd0ec3a
commit 40eabd50d1
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9

View File

@ -116,8 +116,7 @@ pub async fn search_with_url_query(
debug!("called with params: {:?}", params); debug!("called with params: {:?}", params);
let query: SearchQuery = params.into_inner().into(); let query: SearchQuery = params.into_inner().into();
let mut analytics_value = extract_analytics_from_query(&query); analytics.start_get_search(&query, &req);
analytics_value["http_method"] = json!("get");
let search_result = meilisearch let search_result = meilisearch
.search(path.into_inner().index_uid, query) .search(path.into_inner().index_uid, query)
@ -127,12 +126,7 @@ pub async fn search_with_url_query(
#[cfg(test)] #[cfg(test)]
assert!(!search_result.exhaustive_nb_hits); assert!(!search_result.exhaustive_nb_hits);
analytics_value["response_time"] = json!(search_result.processing_time_ms as u64); analytics.end_post_search(search_result.processing_time_ms as usize);
analytics.publish(
"Documents Searched".to_string(),
analytics_value,
Some(&req),
);
debug!("returns: {:?}", search_result); debug!("returns: {:?}", search_result);
Ok(HttpResponse::Ok().json(search_result)) Ok(HttpResponse::Ok().json(search_result))
@ -148,8 +142,7 @@ pub async fn search_with_post(
let query = params.into_inner(); let query = params.into_inner();
debug!("search called with params: {:?}", query); debug!("search called with params: {:?}", query);
let mut analytics_value = extract_analytics_from_query(&query); analytics.start_post_search(&query, &req);
analytics_value["http_method"] = json!("post");
let search_result = meilisearch let search_result = meilisearch
.search(path.into_inner().index_uid, query) .search(path.into_inner().index_uid, query)
@ -159,35 +152,12 @@ pub async fn search_with_post(
#[cfg(test)] #[cfg(test)]
assert!(!search_result.exhaustive_nb_hits); assert!(!search_result.exhaustive_nb_hits);
analytics_value["response_time"] = json!(search_result.processing_time_ms as u64); analytics.end_post_search(search_result.processing_time_ms as usize);
analytics.publish(
"Documents Searched".to_string(),
analytics_value,
Some(&req),
);
debug!("returns: {:?}", search_result); debug!("returns: {:?}", search_result);
Ok(HttpResponse::Ok().json(search_result)) Ok(HttpResponse::Ok().json(search_result))
} }
fn extract_analytics_from_query(query: &SearchQuery) -> Value {
json!({
"sort": {
"total": query.sort.as_ref().map(|sort| sort.len()),
"has_geoPoint": query.sort.as_ref().map(|sort| sort.iter().any(|sort| sort.starts_with("_geoPoint"))),
},
"filter": {
"has_geoRadius": query.filter.as_ref().map(|filter| filter.to_string().contains("_geoRadius")),
// "syntax": 42,
},
"pagination": {
"offset": query.offset,
"limit": query.limit,
},
"terms_number": query.q.as_ref().map(|q| q.split_whitespace().count()).unwrap_or_default(),
})
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;