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 }

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

2 participants