Skip to content

Commit

Permalink
reduce the debugging spam in testcases caused via SearchResult(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Nov 3, 2024
1 parent 8121e17 commit acc62c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions map/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ data/
gtfs_feeds/
martin/fonts/
martin/sprites/maki
gtfs_feeds
13 changes: 12 additions & 1 deletion server/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ pub struct SearchQueryArgs {
}

/// Returned search results by this
#[derive(Serialize, Debug)]
#[derive(Serialize)]
pub struct SearchResults {
sections: Vec<search_executor::ResultsSection>,
time_ms: u128,
}

impl Debug for SearchResults {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut base = f.debug_struct("SearchResults");
base.field("time_ms", &self.time_ms);
for section in self.sections.iter() {
base.field(&section.facet, section);
}
base.finish()
}
}

#[derive(Copy, Clone, Eq, PartialEq, Hash)]
/// Limit per facet
pub struct Limits {
Expand Down
21 changes: 19 additions & 2 deletions server/src/search/search_executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::{Debug, Formatter};
use meilisearch_sdk::client::Client;
use serde::Serialize;
use tracing::error;
Expand All @@ -14,15 +15,31 @@ mod merger;
mod parser;
mod query;

#[derive(Serialize, Debug, Clone)]
#[derive(Serialize, Clone)]
pub struct ResultsSection {
facet: String,
pub(crate) facet: String,
entries: Vec<ResultEntry>,
n_visible: usize,
#[serde(rename = "estimatedTotalHits")]
estimated_total_hits: usize,
}

impl Debug for ResultsSection {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut base = f.debug_set();
for i in 0..=3 {
if let Some(e)=self.entries.get(i) {
base.entry(e);
}
}
if self.entries.len() > 3 {
base.entry(&"...");
}
base.finish()
}

}

#[derive(Serialize, Default, Debug, Clone)]
struct ResultEntry {
#[serde(skip)]
Expand Down

0 comments on commit acc62c1

Please sign in to comment.