diff --git a/server/main-api/src/feedback/proposed_edits/coordinate.rs b/server/main-api/src/feedback/proposed_edits/coordinate.rs index b670c4afe..67515cbdd 100644 --- a/server/main-api/src/feedback/proposed_edits/coordinate.rs +++ b/server/main-api/src/feedback/proposed_edits/coordinate.rs @@ -9,10 +9,13 @@ struct CoordinateFile { path: PathBuf, } -impl CoordinateFile { - const fn from(path: PathBuf) -> Self { +impl From for CoordinateFile { + fn from(path: PathBuf) -> Self { Self { path } } +} + +impl CoordinateFile { fn matches(&self) -> Range { let name = self.path.file_name().unwrap().to_str().unwrap(); let prefix = name diff --git a/server/main-api/src/search/search_executor/formatter.rs b/server/main-api/src/search/search_executor/formatter.rs index 2d051e8e0..8cfad2bf9 100644 --- a/server/main-api/src/search/search_executor/formatter.rs +++ b/server/main-api/src/search/search_executor/formatter.rs @@ -10,13 +10,16 @@ pub(super) struct RoomVisitor { highlighting: Highlighting, } -impl RoomVisitor { - pub(super) const fn from(parsed_input: ParsedQuery, highlighting: Highlighting) -> Self { +impl From<(ParsedQuery, Highlighting)> for RoomVisitor { + fn from((parsed_input, highlighting): (ParsedQuery, Highlighting)) -> Self { Self { parsed_input, highlighting, } } +} + +impl RoomVisitor { pub(super) fn visit(&self, item: &mut ResultEntry) { item.parsed_id = self.parse_room_formats(&item.hit); item.subtext = Self::generate_subtext(&item.hit); diff --git a/server/main-api/src/search/search_executor/mod.rs b/server/main-api/src/search/search_executor/mod.rs index 76b03440a..ad941359c 100644 --- a/server/main-api/src/search/search_executor/mod.rs +++ b/server/main-api/src/search/search_executor/mod.rs @@ -42,7 +42,7 @@ pub async fn do_geoentry_search( ) -> Vec { let parsed_input = ParsedQuery::from(q.as_str()); - match query::GeoEntryQuery::from(&parsed_input, &limits, &highlighting) + match query::GeoEntryQuery::from((&parsed_input, &limits, &highlighting)) .execute() .await { @@ -53,7 +53,7 @@ pub async fn do_geoentry_search( response.results.get(1).unwrap(), response.results.get(2).unwrap(), ); - let visitor = formatter::RoomVisitor::from(parsed_input, highlighting); + let visitor = formatter::RoomVisitor::from((parsed_input, highlighting)); section_rooms .entries .iter_mut() diff --git a/server/main-api/src/search/search_executor/query.rs b/server/main-api/src/search/search_executor/query.rs index 64b1ca618..20b5dfdd7 100644 --- a/server/main-api/src/search/search_executor/query.rs +++ b/server/main-api/src/search/search_executor/query.rs @@ -29,7 +29,8 @@ struct GeoEntryFilters { rooms: String, buildings: String, } -impl GeoEntryFilters { + +impl From<&Filter> for GeoEntryFilters { fn from(filters: &Filter) -> Self { let ms_filter = filters.as_meilisearch_filters(); let separator = if ms_filter.is_empty() { " " } else { " AND " }; @@ -43,22 +44,25 @@ impl GeoEntryFilters { pub(super) struct GeoEntryQuery { parsed_input: ParsedQuery, - args: Limits, + limits: Limits, highlighting: Highlighting, filters: GeoEntryFilters, sorting: Vec, } -impl GeoEntryQuery { - pub fn from(parsed_input: &ParsedQuery, args: &Limits, highlighting: &Highlighting) -> Self { +impl From<(&ParsedQuery, &Limits, &Highlighting)> for GeoEntryQuery { + fn from((parsed_input, limits, highlighting): (&ParsedQuery, &Limits, &Highlighting)) -> Self { Self { parsed_input: parsed_input.clone(), - args: *args, + limits: *limits, highlighting: highlighting.clone(), filters: GeoEntryFilters::from(&parsed_input.filters), sorting: parsed_input.sorting.as_meilisearch_sorting(), } } +} + +impl GeoEntryQuery { pub async fn execute(self) -> Result, Error> { let q_default = self.prompt_for_querying(); let ms_url = @@ -145,7 +149,7 @@ impl GeoEntryQuery { let mut s = self .common_query(entries) .with_query(query) - .with_limit(self.args.total_count) + .with_limit(self.limits.total_count) .build(); if !self.filters.default.is_empty() { s = s.with_filter(&self.filters.default).build(); @@ -160,7 +164,7 @@ impl GeoEntryQuery { ) -> SearchQuery<'a, meilisearch_sdk::DefaultHttpClient> { self.common_query(entries) .with_query(query) - .with_limit(2 * self.args.buildings_count) // we might do reordering later + .with_limit(2 * self.limits.buildings_count) // we might do reordering later .with_filter(&self.filters.buildings) .build() } @@ -172,7 +176,7 @@ impl GeoEntryQuery { ) -> SearchQuery<'a, meilisearch_sdk::DefaultHttpClient> { self.common_query(entries) .with_query(query) - .with_limit(self.args.rooms_count) + .with_limit(self.limits.rooms_count) .with_filter(&self.filters.rooms) .build() }