Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Search overhaul (#771)
Browse files Browse the repository at this point in the history
* started work; switching context

* working!

* fmt clippy prepare

* fixes

* fixes

* revs

* merge fixes

* changed comments

* merge issues
  • Loading branch information
thesuzerain authored Dec 3, 2023
1 parent a70df06 commit b2be4a7
Show file tree
Hide file tree
Showing 18 changed files with 892 additions and 595 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ pub fn app_setup(

let pool_ref = pool.clone();
let search_config_ref = search_config.clone();
let redis_pool_ref = redis_pool.clone();
scheduler.run(local_index_interval, move || {
let pool_ref = pool_ref.clone();
let redis_pool_ref = redis_pool_ref.clone();
let search_config_ref = search_config_ref.clone();
async move {
info!("Indexing local database");
let result = index_projects(pool_ref, &search_config_ref).await;
let result = index_projects(pool_ref, redis_pool_ref.clone(), &search_config_ref).await;
if let Err(e) = result {
warn!("Local project indexing failed: {:?}", e);
}
Expand Down
74 changes: 52 additions & 22 deletions src/models/v2/search.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use itertools::Itertools;
use serde::{Deserialize, Serialize};

use crate::search::ResultSearchProject;
use crate::{routes::v2_reroute, search::ResultSearchProject};

#[derive(Serialize, Deserialize, Debug)]
pub struct LegacySearchResults {
Expand Down Expand Up @@ -44,15 +45,25 @@ impl LegacyResultSearchProject {
if categories.contains(&"mrpack".to_string()) {
if let Some(mrpack_loaders) = result_search_project.loader_fields.get("mrpack_loaders")
{
categories.extend(mrpack_loaders.clone());
categories.extend(
mrpack_loaders
.iter()
.filter_map(|c| c.as_str())
.map(String::from),
);
categories.retain(|c| c != "mrpack");
}
}
let mut display_categories = result_search_project.display_categories;
if display_categories.contains(&"mrpack".to_string()) {
if let Some(mrpack_loaders) = result_search_project.loader_fields.get("mrpack_loaders")
{
display_categories.extend(mrpack_loaders.clone());
categories.extend(
mrpack_loaders
.iter()
.filter_map(|c| c.as_str())
.map(String::from),
);
display_categories.retain(|c| c != "mrpack");
}
}
Expand Down Expand Up @@ -84,37 +95,56 @@ impl LegacyResultSearchProject {
project_type
};

Self {
project_type,
client_side: result_search_project
.loader_fields
.get("client_side")
.cloned()
.unwrap_or_default()
.join(","),
server_side: result_search_project
.loader_fields
.get("server_side")
let loader_fields = result_search_project.loader_fields.clone();
let get_one_bool_loader_field = |key: &str| {
loader_fields
.get(key)
.cloned()
.unwrap_or_default()
.join(","),
versions: result_search_project
.loader_fields
.get("game_versions")
.cloned()
.unwrap_or_default(),
.first()
.and_then(|s| s.as_bool())
};

let singleplayer = get_one_bool_loader_field("singleplayer");
let client_only = get_one_bool_loader_field("client_only").unwrap_or(false);
let server_only = get_one_bool_loader_field("server_only").unwrap_or(false);
let client_and_server = get_one_bool_loader_field("client_and_server");

let (client_side, server_side) = v2_reroute::convert_side_types_v2_bools(
singleplayer,
client_only,
server_only,
client_and_server,
);
let client_side = client_side.to_string();
let server_side = server_side.to_string();

let versions = result_search_project
.loader_fields
.get("game_versions")
.cloned()
.unwrap_or_default()
.into_iter()
.filter_map(|s| s.as_str().map(String::from))
.collect_vec();

Self {
project_type,
client_side,
server_side,
versions,
latest_version: result_search_project.version_id,
categories,

project_id: result_search_project.project_id,
slug: result_search_project.slug,
author: result_search_project.author,
title: result_search_project.name,
description: result_search_project.description,
description: result_search_project.summary,
display_categories,
downloads: result_search_project.downloads,
follows: result_search_project.follows,
icon_url: result_search_project.icon_url,
icon_url: result_search_project.icon_url.unwrap_or_default(),
license: result_search_project.license,
date_created: result_search_project.date_created,
date_modified: result_search_project.date_modified,
Expand Down
Loading

0 comments on commit b2be4a7

Please sign in to comment.