From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager] server: api: resources: make search terms (ascii) case insensitive
Date: Fri, 12 Sep 2025 11:30:28 +0200 [thread overview]
Message-ID: <20250912093034.1606425-1-d.csapak@proxmox.com> (raw)
by converting both the values and the terms to (ascii) lower case.
Making the search case insensitive seems more intuitive, since most
searches i could find behave this way (except e.g. in editors)
Since all values are currently ascii only, and this is faster than
`to_lowercase` using `to_ascii_lowercase` seems better here.
Also noticed that some matches can be replaced with the respective
MatchCategory matches, so we don't have to repeat this pattern
everywhere.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
server/src/api/resources.rs | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/server/src/api/resources.rs b/server/src/api/resources.rs
index afb53f42..d1ce0421 100644
--- a/server/src/api/resources.rs
+++ b/server/src/api/resources.rs
@@ -78,10 +78,12 @@ impl std::str::FromStr for MatchCategory {
impl MatchCategory {
fn matches(&self, value: &str, search_term: &str) -> bool {
match self {
- MatchCategory::Type | MatchCategory::Status => value.starts_with(search_term),
- MatchCategory::Name | MatchCategory::Id | MatchCategory::Remote => {
- value.contains(search_term)
- }
+ MatchCategory::Type | MatchCategory::Status => value
+ .to_ascii_lowercase()
+ .starts_with(&search_term.to_ascii_lowercase()),
+ MatchCategory::Name | MatchCategory::Id | MatchCategory::Remote => value
+ .to_ascii_lowercase()
+ .contains(&search_term.to_ascii_lowercase()),
MatchCategory::Template => match (parse_boolean(value), parse_boolean(search_term)) {
(Ok(a), Ok(b)) => a == b,
_ => false,
@@ -112,7 +114,10 @@ fn resource_matches_search_term(
MatchCategory::Remote => category.matches(remote_name, &term.value),
},
Some(Err(_)) => false,
- None => resource.name().contains(&term.value) || resource.id().contains(&term.value),
+ None => {
+ MatchCategory::Name.matches(resource.name(), &term.value)
+ || MatchCategory::Id.matches(&resource.id(), &term.value)
+ }
};
Some(matches)
}
@@ -132,7 +137,10 @@ fn remote_matches_search_term(remote_name: &str, online: Option<bool>, term: &Se
MatchCategory::Template => false,
},
Some(Err(_)) => false,
- None => remote_name.contains(&term.value) || "remote".starts_with(&term.value),
+ None => {
+ MatchCategory::Name.matches(remote_name, &term.value)
+ || MatchCategory::Type.matches("remote", &term.value)
+ }
}
}
@@ -188,15 +196,14 @@ fn is_remotes_only(filters: &Search) -> bool {
if term.is_optional() {
optional_terms += 1;
}
- match term.category.as_deref() {
- Some("type") if "remote".starts_with(&term.value) => {
+ match term.category.as_deref().map(|c| c.parse::<MatchCategory>()) {
+ Some(Ok(MatchCategory::Type)) if MatchCategory::Type.matches("remote", &term.value) => {
if !term.is_optional() {
is_required = true;
} else {
optional_matches += 1;
}
}
- None => {}
_ => {}
}
// search is short-circuited, so to iterate over all, return true on required and false on optional
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next reply other threads:[~2025-09-12 9:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 9:30 Dominik Csapak [this message]
2025-09-15 14:41 ` Thomas Lamprecht
2025-09-16 9:45 ` Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250912093034.1606425-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.