Skip to content

Commit 4c2ac00

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

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

server/src/data/models.rs

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

20+
use crate::handlers::group_handler::AutocompleteSearchOverGroupsReqPayload;
2021
use crate::handlers::page_handler::PublicPageParameters;
2122
use crate::operators::analytics_operator::{
2223
CTRRecommendationsWithClicksResponse, CTRRecommendationsWithoutClicksResponse,
@@ -4105,6 +4106,32 @@ impl ApiKeyRequestParams {
41054106
}
41064107
}
41074108

4109+
pub fn combine_with_autocomplete_search_over_groups(
4110+
self,
4111+
payload: AutocompleteSearchOverGroupsReqPayload,
4112+
) -> AutocompleteSearchOverGroupsReqPayload {
4113+
AutocompleteSearchOverGroupsReqPayload {
4114+
search_type: self.search_type.unwrap_or(payload.search_type),
4115+
extend_results: payload.extend_results,
4116+
query: payload.query,
4117+
page_size: self.page_size.or(payload.page_size),
4118+
filters: self.filters.or(payload.filters),
4119+
sort_options: payload.sort_options,
4120+
scoring_options: payload.scoring_options,
4121+
highlight_options: self.highlight_options.or(payload.highlight_options),
4122+
score_threshold: self.score_threshold.or(payload.score_threshold),
4123+
slim_chunks: self.slim_chunks.or(payload.slim_chunks),
4124+
use_quote_negated_terms: self
4125+
.use_quote_negated_terms
4126+
.or(payload.use_quote_negated_terms),
4127+
group_size: payload.group_size,
4128+
remove_stop_words: self.remove_stop_words.or(payload.remove_stop_words),
4129+
user_id: payload.user_id,
4130+
typo_options: self.typo_options.or(payload.typo_options),
4131+
metadata: payload.metadata,
4132+
}
4133+
}
4134+
41084135
pub fn combine_with_search_chunks(
41094136
self,
41104137
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::{
@@ -391,6 +394,15 @@ pub async fn insert_api_key_payload(
391394
let body_bytes = serde_json::to_vec(&web::Json(new_body)).unwrap();
392395
req.set_payload(bytes_to_payload(body_bytes.into()));
393396
}
397+
"/api/chunk_group/group_oriented_autocomplete" => {
398+
let body = req
399+
.extract::<Json<AutocompleteSearchOverGroupsReqPayload>>()
400+
.await?;
401+
let new_body =
402+
api_key_params.combine_with_autocomplete_search_over_groups(body.into_inner());
403+
let body_bytes = serde_json::to_vec(&web::Json(new_body)).unwrap();
404+
req.set_payload(bytes_to_payload(body_bytes.into()));
405+
}
394406
"/api/chunk_group/search" => {
395407
let body = req.extract::<Json<SearchWithinGroupReqPayload>>().await?;
396408
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
@@ -3071,6 +3071,11 @@ pub async fn autocomplete_search_over_groups_query(
30713071
data.sort_options,
30723072
));
30733073

3074+
reranked_chunks = reranked_chunks
3075+
.into_iter()
3076+
.dedup_by(|a, b| a.group_id == b.group_id)
3077+
.collect::<Vec<GroupScoreChunk>>();
3078+
30743079
reranked_chunks.truncate(data.page_size.unwrap_or(10) as usize);
30753080

30763081
result_chunks.group_chunks = reranked_chunks;

0 commit comments

Comments
 (0)