Skip to content

Commit

Permalink
cleanup: remove unneeded params and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
densumesh committed Apr 4, 2024
1 parent 8f053d8 commit a7bda16
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 82 deletions.
11 changes: 1 addition & 10 deletions server/src/handlers/chunk_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,6 @@ pub struct SearchChunkData {
pub highlight_results: Option<bool>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"].
pub highlight_delimiters: Option<Vec<String>>,
/// Turn on quote words and negated words to search for exact phrases and exclude words from the search results. Default is false.
pub quote_negated_words: Option<bool>,
/// Set score_threshold to a float to filter out chunks with a score below the threshold.
pub score_threshold: Option<f32>,
/// Set slim_chunks to true to avoid returning the content and chunk_html of the chunks. This is useful for when you want to reduce amount of data over the wire for latency improvement. Default is false.
Expand Down Expand Up @@ -1265,14 +1263,7 @@ pub async fn search_chunk(

let page = data.page.unwrap_or(1);

let mut parsed_query = ParsedQuery {
query: data.query.clone(),
quote_words: None,
negated_words: None,
};
if data.quote_negated_words.unwrap_or(false) {
parsed_query = parse_query(data.query.clone());
}
let parsed_query = parse_query(data.query.clone());

let tx_ctx = sentry::TransactionContext::new("search", "search_chunks");
let transaction = sentry::start_transaction(tx_ctx);
Expand Down
25 changes: 3 additions & 22 deletions server/src/handlers/group_handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
auth_handler::{AdminOnly, LoggedUser},
chunk_handler::{parse_query, ChunkFilter, ParsedQuery, ScoreChunkDTO, SearchChunkData},
chunk_handler::{parse_query, ChunkFilter, ScoreChunkDTO, SearchChunkData},
};
use crate::{
data::models::{
Expand Down Expand Up @@ -1101,8 +1101,6 @@ pub struct SearchWithinGroupData {
pub highlight_results: Option<bool>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"].
pub highlight_delimiters: Option<Vec<String>>,
/// Turn on quote words and negated words to search for exact phrases and exclude words from the search results. Default is false.
pub quote_negated_words: Option<bool>,
/// Set score_threshold to a float to filter out chunks with a score below the threshold.
pub score_threshold: Option<f32>,
/// Set slim_chunks to true to avoid returning the content and chunk_html of the chunks. This is useful for when you want to reduce amount of data over the wire for latency improvement. Default is false.
Expand All @@ -1122,7 +1120,6 @@ impl From<SearchWithinGroupData> for SearchChunkData {
get_collisions: Some(false),
highlight_results: data.highlight_results,
highlight_delimiters: data.highlight_delimiters,
quote_negated_words: data.quote_negated_words,
score_threshold: data.score_threshold,
slim_chunks: data.slim_chunks,
}
Expand Down Expand Up @@ -1194,14 +1191,7 @@ pub async fn search_within_group(
}
};

let mut parsed_query = ParsedQuery {
query: data.query.clone(),
quote_words: None,
negated_words: None,
};
if data.quote_negated_words.unwrap_or(false) {
parsed_query = parse_query(data.query.clone());
}
let parsed_query = parse_query(data.query.clone());

let result_chunks = match data.search_type.as_str() {
"fulltext" => {
Expand Down Expand Up @@ -1286,8 +1276,6 @@ pub struct SearchOverGroupsData {
pub highlight_results: Option<bool>,
/// Set highlight_delimiters to a list of strings to use as delimiters for highlighting. If not specified, this defaults to ["?", ",", ".", "!"].
pub highlight_delimiters: Option<Vec<String>>,
/// Turn on quote words and negated words to search for exact phrases and exclude words from the search results. Default is false.
pub quote_negated_words: Option<bool>,
/// Set score_threshold to a float to filter out chunks with a score below the threshold.
pub score_threshold: Option<f32>,
// Group_size is the number of chunks to fetch for each group.
Expand Down Expand Up @@ -1337,14 +1325,7 @@ pub async fn search_over_groups(
//search over the links as well
let page = data.page.unwrap_or(1);

let mut parsed_query = ParsedQuery {
query: data.query.clone(),
quote_words: None,
negated_words: None,
};
if data.quote_negated_words.unwrap_or(false) {
parsed_query = parse_query(data.query.clone());
}
let parsed_query = parse_query(data.query.clone());

let result_chunks = match data.search_type.as_str() {
"fulltext" => {
Expand Down
50 changes: 0 additions & 50 deletions server/src/operators/search_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,53 +1941,3 @@ pub async fn hybrid_search_over_groups(

Ok(result_chunks)
}

#[tracing::instrument(skip(pool))]
pub async fn get_qdrant_point_ids_from_pg_for_quote_negated_words(
quote_words: Option<Vec<String>>,
negated_words: Option<Vec<String>>,
dataset_id: uuid::Uuid,
pool: web::Data<Pool>,
) -> Result<Vec<uuid::Uuid>, ServiceError> {
use crate::data::schema::chunk_metadata::dsl as chunk_metadata_columns;
use diesel::prelude::*;
use diesel_async::RunQueryDsl;

let mut conn = pool.get().await.unwrap();
let mut query = chunk_metadata_columns::chunk_metadata
.select(chunk_metadata_columns::qdrant_point_id)
.filter(chunk_metadata_columns::qdrant_point_id.is_not_null())
.filter(chunk_metadata_columns::dataset_id.eq(dataset_id))
.into_boxed();

if let Some(quote_words) = quote_words {
for word in quote_words.iter() {
let word_without_quotes = word.trim_matches('\"');
query = query.filter(
chunk_metadata_columns::chunk_html.ilike(format!("%{}%", word_without_quotes)),
);
}
}

if let Some(negated_words) = negated_words {
for word in negated_words.iter() {
let word_without_negation = word.trim_matches('-');
query = query.filter(
chunk_metadata_columns::chunk_html
.not_ilike(format!("%{}%", word_without_negation)),
);
}
}

let matching_qdrant_point_ids: Vec<Option<uuid::Uuid>> =
query.load(&mut conn).await.map_err(|_| {
ServiceError::BadRequest("Failed to load full-text searched chunks".to_string())
})?;

let matching_qdrant_point_ids = matching_qdrant_point_ids
.into_iter()
.flatten()
.collect::<Vec<uuid::Uuid>>();

Ok(matching_qdrant_point_ids)
}

0 comments on commit a7bda16

Please sign in to comment.