From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 028391FF16B for ; Fri, 12 Sep 2025 11:31:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 03B5BD55; Fri, 12 Sep 2025 11:31:09 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Fri, 12 Sep 2025 11:30:28 +0200 Message-ID: <20250912093034.1606425-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [resources.rs] Subject: [pdm-devel] [PATCH datacenter-manager] server: api: resources: make search terms (ascii) case insensitive X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" 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 --- 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, 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::()) { + 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