server: use query for search

This commit is contained in:
nym21
2025-03-05 16:55:37 +01:00
parent b27297cdc6
commit d2ca6f1d46
10 changed files with 104 additions and 155 deletions

View File

@@ -5,9 +5,14 @@ use serde::Deserialize;
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Deserialize)]
pub enum Format {
#[serde(alias = "json")]
JSON,
#[serde(alias = "csv")]
CSV,
#[serde(alias = "tsv")]
TSV,
#[serde(alias = "md", alias = "markdown")]
#[value(alias("markdown"))]
MD,
}

View File

@@ -68,7 +68,7 @@ impl Index {
impl TryFrom<&str> for Index {
type Error = color_eyre::Report;
fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(match value {
Ok(match value.to_lowercase().as_str() {
v if (Self::Dateindex).possible_values().contains(&v) => Self::Dateindex,
v if (Self::Height).possible_values().contains(&v) => Self::Height,
v if (Self::Txindex).possible_values().contains(&v) => Self::Txindex,

View File

@@ -60,8 +60,17 @@ impl<'a> Query<'a> {
) -> color_eyre::Result<Output> {
let tuples = ids
.iter()
.map(|s| {
let mut id = s.to_lowercase().replace("_", "-");
.flat_map(|s| {
s.to_lowercase()
.replace("_", "-")
.split_whitespace()
.flat_map(|s| {
s.split(',')
.flat_map(|s| s.split('+').map(|s| s.to_string()))
})
.collect::<Vec<_>>()
})
.map(|mut id| {
let mut res = self.vecid_to_index_to_vec.get(&id);
if res.is_none() {
if let Ok(index) = Index::try_from(id.as_str()) {