Skip to content

Commit f160a33

Browse files
densumeshcdxker
authored andcommitted
feature: dedup autocomplete by group and add api key filtering for that route
1 parent ff47290 commit f160a33

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

server/src/data/models.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::handlers::message_handler::{
1818
CreateMessageReqPayload, EditMessageReqPayload, RegenerateMessageReqPayload,
1919
};
2020

21+
use crate::handlers::group_handler::AutocompleteSearchOverGroupsReqPayload;
2122
use crate::handlers::page_handler::PublicPageParameters;
2223
use crate::operators::analytics_operator::{
2324
CTRRecommendationsWithClicksResponse, CTRRecommendationsWithoutClicksResponse,
@@ -4623,6 +4624,32 @@ impl ApiKeyRequestParams {
46234624
}
46244625
}
46254626

4627+
pub fn combine_with_autocomplete_search_over_groups(
4628+
self,
4629+
payload: AutocompleteSearchOverGroupsReqPayload,
4630+
) -> AutocompleteSearchOverGroupsReqPayload {
4631+
AutocompleteSearchOverGroupsReqPayload {
4632+
search_type: self.search_type.unwrap_or(payload.search_type),
4633+
extend_results: payload.extend_results,
4634+
query: payload.query,
4635+
page_size: self.page_size.or(payload.page_size),
4636+
filters: self.filters.or(payload.filters),
4637+
sort_options: payload.sort_options,
4638+
scoring_options: payload.scoring_options,
4639+
highlight_options: self.highlight_options.or(payload.highlight_options),
4640+
score_threshold: self.score_threshold.or(payload.score_threshold),
4641+
slim_chunks: self.slim_chunks.or(payload.slim_chunks),
4642+
use_quote_negated_terms: self
4643+
.use_quote_negated_terms
4644+
.or(payload.use_quote_negated_terms),
4645+
group_size: payload.group_size,
4646+
remove_stop_words: self.remove_stop_words.or(payload.remove_stop_words),
4647+
user_id: payload.user_id,
4648+
typo_options: self.typo_options.or(payload.typo_options),
4649+
metadata: payload.metadata,
4650+
}
4651+
}
4652+
46264653
pub fn combine_with_search_chunks(
46274654
self,
46284655
payload: SearchChunksReqPayload,

server/src/middleware/auth_middleware.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use crate::{
66
handlers::{
77
auth_handler::{AdminOnly, LoggedUser, OrganizationRole, OwnerOnly},
88
chunk_handler::{AutocompleteReqPayload, ScrollChunksReqPayload, SearchChunksReqPayload},
9-
group_handler::{SearchOverGroupsReqPayload, SearchWithinGroupReqPayload},
9+
group_handler::{
10+
AutocompleteSearchOverGroupsReqPayload, SearchOverGroupsReqPayload,
11+
SearchWithinGroupReqPayload,
12+
},
1013
message_handler::CreateMessageReqPayload,
1114
},
1215
operators::{
@@ -404,6 +407,15 @@ pub async fn insert_api_key_payload(
404407
let body_bytes = serde_json::to_vec(&web::Json(new_body)).unwrap();
405408
req.set_payload(bytes_to_payload(body_bytes.into()));
406409
}
410+
"/api/chunk_group/group_oriented_autocomplete" => {
411+
let body = req
412+
.extract::<Json<AutocompleteSearchOverGroupsReqPayload>>()
413+
.await?;
414+
let new_body =
415+
api_key_params.combine_with_autocomplete_search_over_groups(body.into_inner());
416+
let body_bytes = serde_json::to_vec(&web::Json(new_body)).unwrap();
417+
req.set_payload(bytes_to_payload(body_bytes.into()));
418+
}
407419
"/api/chunk_group/search" => {
408420
let body = req.extract::<Json<SearchWithinGroupReqPayload>>().await?;
409421
let new_body = api_key_params.combine_with_search_within_group(body.into_inner());

server/src/operators/search_operator.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,11 @@ pub async fn autocomplete_search_over_groups_query(
30763076
data.sort_options,
30773077
));
30783078

3079+
reranked_chunks = reranked_chunks
3080+
.into_iter()
3081+
.dedup_by(|a, b| a.group_id == b.group_id)
3082+
.collect::<Vec<GroupScoreChunk>>();
3083+
30793084
reranked_chunks.truncate(data.page_size.unwrap_or(10) as usize);
30803085

30813086
result_chunks.group_chunks = reranked_chunks;

0 commit comments

Comments
 (0)