Skip to content

fix: malformed search facet generation - #18

Open
RowenStipe wants to merge 1 commit into
gorilla-devs:masterfrom
RowenStipe:master
Open

fix: malformed search facet generation#18
RowenStipe wants to merge 1 commit into
gorilla-devs:masterfrom
RowenStipe:master

Conversation

@RowenStipe

Copy link
Copy Markdown

Fixes #17

@CLAassistant

CLAassistant commented Aug 22, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@RowenStipe

RowenStipe commented Aug 22, 2026

Copy link
Copy Markdown
Author

Got ahead of myself... While this does fix the incorrect formatting (Modrinth doesn't have a space included in their documentation for search facets https://docs.modrinth.com/api/operations/searchprojects/ ) it doesn't fully fix #17 as the URL generated isn't properly formatted. This was figured out by shoving a println!() into line 90 here

pub async fn search(
&self,
query: &str,
sort: &Sort,
mut facets: Vec<Vec<Facet>>,
) -> Result<Response> {
let mut url = API_BASE_URL
.join_all(vec!["search"])
.with_query("query", query)
.with_query("index", sort);
facets.retain(|e| !e.is_empty());
if !facets.is_empty() {
url = url.with_query_json("facets", facets)?
}
self.client.get(url).custom_send_json().await
}
}
to see what the url created looks like and opening that URL with firefox.

This sample code with a println! at L90

use ferinth::{self, structures::{project::ProjectType::Mod, search::{Facet::{Categories, ProjectType, Versions}, Sort}}};

#[tokio::main]
async fn main() {
    let client = ferinth::Ferinth::default();

    let search = client.search(&"knowlogy", &Sort::Relevance, vec![vec![ProjectType(Mod)], vec![Categories("neoforge".to_string())], vec![Versions("1.21.1".to_string())]]).await;

    match search {
        Ok(response) => {
            println!("Search results: {:?}", response);
        }
        Err(e) => {
            eprintln!("Error searching modrinth: {:?}", e);
        }
    }
}

will produce

URL: https://api.modrinth.com/v2/search?query=knowlogy&index=relevance&facets=%5B%5B%22project_type%3AMod%22%5D%2C%5B%22categories%3Aneoforge%22%5D%2C%5B%22versions%3A1.21.1%22%5D%5D
Search results: Response { hits: [], offset: 0, limit: 10, total_hits: 0 }

@vektrace

vektrace commented Sep 1, 2026

Copy link
Copy Markdown

I encountered the same issue about a month ago. The problem is actually that the project_type variable is debug formatted instead of serialized:

Facet::ProjectType(project_type) => {
format!("project_type:{project_type:?}",)
}

The ProjectType enum derives Deserialize and Serialize and serde would rename all variants to snake case.

#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ProjectType {
Mod,
Modpack,
Resourcepack,
Shader,
Plugin,
Datapack,
MinecraftJavaServer,
#[serde(other)]
Other,
}

However, this never happens because, like I said, instead of being serialized it's just debug formatted.

This is how the fix would look like:
https://github.com/paul8711-code/ferinth/blob/a905f308017ca2d4e32733cdae7688fb67c8d721/src/structures/search.rs#L53-L58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Search Facet produces incorect strings

3 participants