Store remaining text when parsing query

This commit is contained in:
Bill Thiede 2024-07-21 15:19:19 -07:00
parent d9d57c66f8
commit ec41f840d5

View File

@ -167,6 +167,7 @@ pub async fn thread(pool: &PgPool, thread_id: String) -> Result<Thread, ServerEr
struct Query { struct Query {
unread_only: bool, unread_only: bool,
site: Option<String>, site: Option<String>,
remainder: Vec<String>,
} }
impl FromStr for Query { impl FromStr for Query {
@ -174,15 +175,21 @@ impl FromStr for Query {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut unread_only = false; let mut unread_only = false;
let mut site = None; let mut site = None;
let mut remainder = Vec::new();
let site_prefix = format!("tag:{TAG_PREFIX}"); let site_prefix = format!("tag:{TAG_PREFIX}");
for word in s.split_whitespace() { for word in s.split_whitespace() {
if word == "is:unread" { if word == "is:unread" {
unread_only = true unread_only = true
}; } else if word.starts_with(&site_prefix) {
if word.starts_with(&site_prefix) {
site = Some(word[site_prefix.len()..].to_string()) site = Some(word[site_prefix.len()..].to_string())
} else {
remainder.push(word.to_string());
} }
} }
Ok(Query { unread_only, site }) Ok(Query {
unread_only,
site,
remainder,
})
} }
} }