chore: bump deps; fix clippy lints & cleanup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I4c4815ad145650a07f108614034d2e996a6a6964
This commit is contained in:
parent
c535650f45
commit
cd1161ee5d
41 changed files with 1528 additions and 953 deletions
|
|
@ -6,6 +6,7 @@ use winnow::{
|
|||
token::{take_till, take_while},
|
||||
};
|
||||
|
||||
/// Represents a parsed search query.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum SearchQuery {
|
||||
FullText(String),
|
||||
|
|
@ -39,6 +40,7 @@ pub enum SearchQuery {
|
|||
},
|
||||
}
|
||||
|
||||
/// Comparison operators for range queries.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum CompareOp {
|
||||
GreaterThan,
|
||||
|
|
@ -47,6 +49,7 @@ pub enum CompareOp {
|
|||
LessOrEqual,
|
||||
}
|
||||
|
||||
/// Date values for date-based queries.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum DateValue {
|
||||
Today,
|
||||
|
|
@ -61,6 +64,7 @@ pub enum DateValue {
|
|||
DaysAgo(u32),
|
||||
}
|
||||
|
||||
/// Request for executing a search.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SearchRequest {
|
||||
pub query: SearchQuery,
|
||||
|
|
@ -68,12 +72,14 @@ pub struct SearchRequest {
|
|||
pub pagination: crate::model::Pagination,
|
||||
}
|
||||
|
||||
/// Results of a search operation.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SearchResults {
|
||||
pub items: Vec<crate::model::MediaItem>,
|
||||
pub total_count: u64,
|
||||
}
|
||||
|
||||
/// Sorting options for search results.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[derive(Default)]
|
||||
|
|
@ -139,19 +145,25 @@ fn parse_date_value(s: &str) -> Option<DateValue> {
|
|||
}
|
||||
|
||||
/// Parse size strings like "10MB", "1GB", "500KB" to bytes
|
||||
///
|
||||
/// Returns `None` if the input is invalid or if the value would overflow.
|
||||
fn parse_size_value(s: &str) -> Option<i64> {
|
||||
let s = s.to_uppercase();
|
||||
if let Some(num) = s.strip_suffix("GB") {
|
||||
num.parse::<i64>().ok().map(|n| n * 1024 * 1024 * 1024)
|
||||
} else if let Some(num) = s.strip_suffix("MB") {
|
||||
num.parse::<i64>().ok().map(|n| n * 1024 * 1024)
|
||||
} else if let Some(num) = s.strip_suffix("KB") {
|
||||
num.parse::<i64>().ok().map(|n| n * 1024)
|
||||
} else if let Some(num) = s.strip_suffix('B') {
|
||||
num.parse::<i64>().ok()
|
||||
let (num_str, multiplier): (&str, i64) = if let Some(n) = s.strip_suffix("GB")
|
||||
{
|
||||
(n, 1024 * 1024 * 1024)
|
||||
} else if let Some(n) = s.strip_suffix("MB") {
|
||||
(n, 1024 * 1024)
|
||||
} else if let Some(n) = s.strip_suffix("KB") {
|
||||
(n, 1024)
|
||||
} else if let Some(n) = s.strip_suffix('B') {
|
||||
(n, 1)
|
||||
} else {
|
||||
s.parse::<i64>().ok()
|
||||
}
|
||||
(s.as_str(), 1)
|
||||
};
|
||||
|
||||
let num: i64 = num_str.parse().ok()?;
|
||||
num.checked_mul(multiplier)
|
||||
}
|
||||
|
||||
fn field_match(input: &mut &str) -> ModalResult<SearchQuery> {
|
||||
|
|
@ -332,6 +344,22 @@ fn or_expr(input: &mut &str) -> ModalResult<SearchQuery> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses a search query string into a structured query.
|
||||
///
|
||||
/// Supports full-text search, field matches, operators (AND/OR/NOT),
|
||||
/// prefixes, fuzzy matching, and type/tag filters.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `input` - Raw query string
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Parsed query tree
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns `SearchParse` error for invalid syntax
|
||||
pub fn parse_search_query(input: &str) -> crate::error::Result<SearchQuery> {
|
||||
let trimmed = input.trim();
|
||||
if trimmed.is_empty() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue