mirror of
https://github.com/modrinth/code.git
synced 2026-08-25 00:55:25 +00:00
feat: add all_project_types to search results (#6654)
* feat: add all_project_types to search results * update docs
This commit is contained in:
@@ -15,6 +15,7 @@ pub struct LegacySearchResults {
|
||||
pub struct LegacyResultSearchProject {
|
||||
pub project_id: String,
|
||||
pub project_type: String,
|
||||
pub all_project_types: Vec<String>,
|
||||
pub slug: Option<String>,
|
||||
pub author: String,
|
||||
#[serde(default)]
|
||||
@@ -136,6 +137,7 @@ impl LegacyResultSearchProject {
|
||||
|
||||
Self {
|
||||
project_type,
|
||||
all_project_types: result_search_project.all_project_types,
|
||||
client_side,
|
||||
server_side,
|
||||
versions,
|
||||
|
||||
@@ -405,6 +405,14 @@ impl SearchField {
|
||||
optional: true,
|
||||
token_separators: &["-"],
|
||||
},
|
||||
SearchField::AllProjectTypes => TypesenseFieldSpec {
|
||||
path: "all_project_types",
|
||||
ty: "string[]",
|
||||
facet: true,
|
||||
sort: false,
|
||||
optional: true,
|
||||
token_separators: &["-"],
|
||||
},
|
||||
SearchField::ProjectId => TypesenseFieldSpec {
|
||||
path: "project_id",
|
||||
ty: "string",
|
||||
|
||||
@@ -495,6 +495,20 @@ async fn build_search_documents(
|
||||
.flat_map(|x| x.loaders.clone())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// all valid project types across every version of the project, so that
|
||||
// filters can exclude projects that have *any* version of a given
|
||||
// project type (unlike the version-specific `project_types` field).
|
||||
let mut all_project_types = versions
|
||||
.iter()
|
||||
.flat_map(|x| x.project_types.clone())
|
||||
.collect::<Vec<_>>();
|
||||
all_project_types.sort();
|
||||
all_project_types.dedup();
|
||||
exp::compat::correct_project_types(
|
||||
&project.components,
|
||||
&mut all_project_types,
|
||||
);
|
||||
|
||||
for version in versions {
|
||||
let version_fields = VersionField::from_query_json(
|
||||
version.version_fields,
|
||||
@@ -609,6 +623,7 @@ async fn build_search_documents(
|
||||
slug: project.slug.clone(),
|
||||
// TODO
|
||||
project_types,
|
||||
all_project_types: all_project_types.clone(),
|
||||
gallery: gallery.clone(),
|
||||
featured_gallery: featured_gallery.clone(),
|
||||
open_source,
|
||||
|
||||
@@ -202,6 +202,7 @@ pub enum SearchField {
|
||||
Author,
|
||||
License,
|
||||
ProjectTypes,
|
||||
AllProjectTypes,
|
||||
ProjectId,
|
||||
OpenSource,
|
||||
Environment,
|
||||
@@ -238,6 +239,7 @@ pub struct UploadSearchProject {
|
||||
pub project_id: String,
|
||||
//
|
||||
pub project_types: Vec<String>,
|
||||
pub all_project_types: Vec<String>,
|
||||
pub slug: Option<String>,
|
||||
pub author: String,
|
||||
pub author_id: String,
|
||||
@@ -307,6 +309,8 @@ pub struct ResultSearchProject {
|
||||
pub version_id: String,
|
||||
pub project_id: String,
|
||||
pub project_types: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub all_project_types: Vec<String>,
|
||||
pub slug: Option<String>,
|
||||
pub author: String,
|
||||
#[serde(default)]
|
||||
@@ -355,6 +359,7 @@ impl From<UploadSearchProject> for ResultSearchProject {
|
||||
version_id: source.version_id,
|
||||
project_id: source.project_id,
|
||||
project_types: source.project_types,
|
||||
all_project_types: source.all_project_types,
|
||||
slug: source.slug,
|
||||
author: source.author,
|
||||
author_id: Some(source.author_id),
|
||||
|
||||
Reference in New Issue
Block a user