mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 09:04:55 +00:00
fix: add DEI (downloads, equality, and inequality) (#6664)
fix: add DEI
This commit is contained in:
@@ -571,6 +571,7 @@ impl Typesense {
|
|||||||
json!({"name": "indexed_name", "type": "string", "facet": false, "stem": true}),
|
json!({"name": "indexed_name", "type": "string", "facet": false, "stem": true}),
|
||||||
json!({"name": "indexed_author", "type": "string", "facet": false}),
|
json!({"name": "indexed_author", "type": "string", "facet": false}),
|
||||||
json!({"name": "log_downloads", "type": "float", "sort": true}),
|
json!({"name": "log_downloads", "type": "float", "sort": true}),
|
||||||
|
json!({"name": "downloads", "type": "int32", "sort": true}),
|
||||||
json!({"name": "follows", "type": "int32", "facet": true, "sort": true}),
|
json!({"name": "follows", "type": "int32", "facet": true, "sort": true}),
|
||||||
json!({"name": "created_timestamp", "type": "int64", "sort": true}),
|
json!({"name": "created_timestamp", "type": "int64", "sort": true}),
|
||||||
json!({"name": "modified_timestamp", "type": "int64", "sort": true}),
|
json!({"name": "modified_timestamp", "type": "int64", "sort": true}),
|
||||||
@@ -1263,9 +1264,12 @@ fn facets_to_typesense(facets_json: &str) -> Result<String> {
|
|||||||
/// Converts a single facet condition such as `"categories:mods"`,
|
/// Converts a single facet condition such as `"categories:mods"`,
|
||||||
/// `"categories=mods"`, or `"downloads!=100"` into a Typesense filter clause.
|
/// `"categories=mods"`, or `"downloads!=100"` into a Typesense filter clause.
|
||||||
fn condition_to_typesense_filter(cond: &str) -> String {
|
fn condition_to_typesense_filter(cond: &str) -> String {
|
||||||
// Handle `!=` before `=` so we don't misfire on the equality arm.
|
// Match multi-character operators before their single-character prefixes,
|
||||||
if let Some((field, value)) = cond.split_once("!=") {
|
// and range/inequality operators before the plain `=` equality arm.
|
||||||
return format!("{}:!= {}", field.trim(), value.trim());
|
for op in ["!=", ">=", "<=", ">", "<"] {
|
||||||
|
if let Some((field, value)) = cond.split_once(op) {
|
||||||
|
return format!("{}:{} {}", field.trim(), op, value.trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some((field, value)) = cond.split_once(':') {
|
if let Some((field, value)) = cond.split_once(':') {
|
||||||
return format!("{}:= {}", field.trim(), value.trim());
|
return format!("{}:= {}", field.trim(), value.trim());
|
||||||
|
|||||||
Reference in New Issue
Block a user