Skip to content

Commit

Permalink
refactor: 検索するときにクエリの所有権を要求しないように
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Sep 25, 2024
1 parent 53ab2b7 commit fad8b55
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions server/domain/src/repository/search_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::{
#[automock]
#[async_trait]
pub trait SearchRepository: Send + Sync + 'static {
async fn search_users(&self, query: String) -> Result<Vec<User>, Error>;
async fn search_forms(&self, query: String) -> Result<Vec<Form>, Error>;
async fn search_labels_for_forms(&self, query: String) -> Result<Vec<Label>, Error>;
async fn search_labels_for_answers(&self, query: String) -> Result<Vec<Label>, Error>;
async fn search_answers(&self, query: String) -> Result<Vec<Answer>, Error>;
async fn search_comments(&self, query: String) -> Result<Vec<Comment>, Error>;
async fn search_users(&self, query: &str) -> Result<Vec<User>, Error>;
async fn search_forms(&self, query: &str) -> Result<Vec<Form>, Error>;
async fn search_labels_for_forms(&self, query: &str) -> Result<Vec<Label>, Error>;
async fn search_labels_for_answers(&self, query: &str) -> Result<Vec<Label>, Error>;
async fn search_answers(&self, query: &str) -> Result<Vec<Answer>, Error>;
async fn search_comments(&self, query: &str) -> Result<Vec<Comment>, Error>;
}
12 changes: 6 additions & 6 deletions server/infra/resource/src/database/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ pub trait UserDatabase: Send + Sync {
#[automock]
#[async_trait]
pub trait SearchDatabase: Send + Sync {
async fn search_users(&self, query: String) -> Result<Vec<User>, InfraError>;
async fn search_forms(&self, query: String) -> Result<Vec<Form>, InfraError>;
async fn search_labels_for_forms(&self, query: String) -> Result<Vec<Label>, InfraError>;
async fn search_labels_for_answers(&self, query: String) -> Result<Vec<Label>, InfraError>;
async fn search_answers(&self, query: String) -> Result<Vec<Answer>, InfraError>;
async fn search_comments(&self, query: String) -> Result<Vec<Comment>, InfraError>;
async fn search_users(&self, query: &str) -> Result<Vec<User>, InfraError>;
async fn search_forms(&self, query: &str) -> Result<Vec<Form>, InfraError>;
async fn search_labels_for_forms(&self, query: &str) -> Result<Vec<Label>, InfraError>;
async fn search_labels_for_answers(&self, query: &str) -> Result<Vec<Label>, InfraError>;
async fn search_answers(&self, query: &str) -> Result<Vec<Answer>, InfraError>;
async fn search_comments(&self, query: &str) -> Result<Vec<Comment>, InfraError>;
}
24 changes: 12 additions & 12 deletions server/infra/resource/src/database/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::database::{components::SearchDatabase, connection::ConnectionPool};

#[async_trait]
impl SearchDatabase for ConnectionPool {
async fn search_users(&self, query: String) -> Result<Vec<User>, InfraError> {
async fn search_users(&self, query: &str) -> Result<Vec<User>, InfraError> {
Ok(self
.meilisearch_client
.index("users")
.search()
.with_query(&query)
.with_query(query)
.with_attributes_to_highlight(Selectors::All)
.execute::<User>()
.await?
Expand All @@ -26,12 +26,12 @@ impl SearchDatabase for ConnectionPool {
.collect_vec())
}

async fn search_forms(&self, query: String) -> Result<Vec<Form>, InfraError> {
async fn search_forms(&self, query: &str) -> Result<Vec<Form>, InfraError> {
Ok(self
.meilisearch_client
.index("form_meta_data")
.search()
.with_query(query.as_str())
.with_query(query)
.with_attributes_to_highlight(Selectors::All)
.execute::<Form>()
.await?
Expand All @@ -41,12 +41,12 @@ impl SearchDatabase for ConnectionPool {
.collect_vec())
}

async fn search_labels_for_forms(&self, query: String) -> Result<Vec<Label>, InfraError> {
async fn search_labels_for_forms(&self, query: &str) -> Result<Vec<Label>, InfraError> {
Ok(self
.meilisearch_client
.index("label_for_forms")
.search()
.with_query(query.as_str())
.with_query(query)
.with_attributes_to_highlight(Selectors::All)
.execute::<Label>()
.await?
Expand All @@ -56,12 +56,12 @@ impl SearchDatabase for ConnectionPool {
.collect_vec())
}

async fn search_labels_for_answers(&self, query: String) -> Result<Vec<Label>, InfraError> {
async fn search_labels_for_answers(&self, query: &str) -> Result<Vec<Label>, InfraError> {
Ok(self
.meilisearch_client
.index("label_for_form_answers")
.search()
.with_query(query.as_str())
.with_query(query)
.with_attributes_to_highlight(Selectors::All)
.execute::<Label>()
.await?
Expand All @@ -71,12 +71,12 @@ impl SearchDatabase for ConnectionPool {
.collect_vec())
}

async fn search_answers(&self, query: String) -> Result<Vec<Answer>, InfraError> {
async fn search_answers(&self, query: &str) -> Result<Vec<Answer>, InfraError> {
Ok(self
.meilisearch_client
.index("real_answers")
.search()
.with_query(query.as_str())
.with_query(query)
.with_attributes_to_highlight(Selectors::All)
.execute::<Answer>()
.await?
Expand All @@ -86,12 +86,12 @@ impl SearchDatabase for ConnectionPool {
.collect_vec())
}

async fn search_comments(&self, query: String) -> Result<Vec<Comment>, InfraError> {
async fn search_comments(&self, query: &str) -> Result<Vec<Comment>, InfraError> {
Ok(self
.meilisearch_client
.index("form_answer_comments")
.search()
.with_query(query.as_str())
.with_query(query)
.with_attributes_to_highlight(Selectors::All)
.execute::<Comment>()
.await?
Expand Down
12 changes: 6 additions & 6 deletions server/infra/resource/src/repository/search_repository_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,47 @@ use crate::{

#[async_trait]
impl<Client: DatabaseComponents + 'static> SearchRepository for Repository<Client> {
async fn search_users(&self, query: String) -> Result<Vec<User>, Error> {
async fn search_users(&self, query: &str) -> Result<Vec<User>, Error> {
self.client
.search()
.search_users(query)
.await
.map_err(Into::into)
}

async fn search_forms(&self, query: String) -> Result<Vec<Form>, Error> {
async fn search_forms(&self, query: &str) -> Result<Vec<Form>, Error> {
self.client
.search()
.search_forms(query)
.await
.map_err(Into::into)
}

async fn search_labels_for_forms(&self, query: String) -> Result<Vec<Label>, Error> {
async fn search_labels_for_forms(&self, query: &str) -> Result<Vec<Label>, Error> {
self.client
.search()
.search_labels_for_forms(query)
.await
.map_err(Into::into)
}

async fn search_labels_for_answers(&self, query: String) -> Result<Vec<Label>, Error> {
async fn search_labels_for_answers(&self, query: &str) -> Result<Vec<Label>, Error> {
self.client
.search()
.search_labels_for_answers(query)
.await
.map_err(Into::into)
}

async fn search_answers(&self, query: String) -> Result<Vec<Answer>, Error> {
async fn search_answers(&self, query: &str) -> Result<Vec<Answer>, Error> {
self.client
.search()
.search_answers(query)
.await
.map_err(Into::into)
}

async fn search_comments(&self, query: String) -> Result<Vec<Comment>, Error> {
async fn search_comments(&self, query: &str) -> Result<Vec<Comment>, Error> {
self.client
.search()
.search_comments(query)
Expand Down
12 changes: 6 additions & 6 deletions server/usecase/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub struct SearchUseCase<'a, SearchRepo: SearchRepository> {
impl<R: SearchRepository> SearchUseCase<'_, R> {
pub async fn cross_search(&self, query: String) -> Result<CrossSearchResult, Error> {
let (forms, users, label_for_forms, label_for_answers, answers, comments) = try_join!(
self.repository.search_forms(query.to_owned()),
self.repository.search_users(query.to_owned()),
self.repository.search_labels_for_forms(query.to_owned()),
self.repository.search_labels_for_answers(query.to_owned()),
self.repository.search_answers(query.to_owned()),
self.repository.search_comments(query.to_owned())
self.repository.search_forms(&query),
self.repository.search_users(&query),
self.repository.search_labels_for_forms(&query),
self.repository.search_labels_for_answers(&query),
self.repository.search_answers(&query),
self.repository.search_comments(&query)
)?;

Ok(CrossSearchResult {
Expand Down

0 comments on commit fad8b55

Please sign in to comment.