You've already forked AstralRinth
forked from didirus/AstralRinth
Follows (#172)
* Follows initial * Fix #171, Fix #170, Fix #169, Fix #164 * More work on follows * Fix compile error * Upgrade meili version, add follows to search
This commit is contained in:
@@ -15,7 +15,7 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
|
||||
|
||||
let mut mods = sqlx::query!(
|
||||
"
|
||||
SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug, m.license, m.client_side, m.server_side FROM mods m
|
||||
SELECT m.id, m.title, m.description, m.downloads, m.follows, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.status, m.slug, m.license, m.client_side, m.server_side FROM mods m
|
||||
"
|
||||
).fetch(&pool);
|
||||
|
||||
@@ -55,7 +55,7 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
|
||||
|
||||
let loaders = sqlx::query!(
|
||||
"
|
||||
SELECT loaders.loader FROM versions
|
||||
SELECT DISTINCT loaders.loader FROM versions
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = versions.id
|
||||
INNER JOIN loaders ON loaders.id = lv.loader_id
|
||||
WHERE versions.mod_id = $1
|
||||
@@ -151,6 +151,7 @@ pub async fn index_local(pool: PgPool) -> Result<Vec<UploadSearchMod>, IndexingE
|
||||
description: mod_data.description,
|
||||
categories,
|
||||
versions,
|
||||
follows: mod_data.follows,
|
||||
downloads: mod_data.downloads,
|
||||
page_url: format!("https://modrinth.com/mod/{}", mod_id),
|
||||
icon_url,
|
||||
@@ -179,7 +180,7 @@ pub async fn query_one(
|
||||
) -> Result<UploadSearchMod, IndexingError> {
|
||||
let mod_data = sqlx::query!(
|
||||
"
|
||||
SELECT m.id, m.title, m.description, m.downloads, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug, m.license, m.client_side, m.server_side
|
||||
SELECT m.id, m.title, m.description, m.downloads, m.follows, m.icon_url, m.body_url, m.published, m.updated, m.team_id, m.slug, m.license, m.client_side, m.server_side
|
||||
FROM mods m
|
||||
WHERE id = $1
|
||||
",
|
||||
@@ -203,7 +204,7 @@ pub async fn query_one(
|
||||
|
||||
let loaders = sqlx::query!(
|
||||
"
|
||||
SELECT loaders.loader FROM versions
|
||||
SELECT DISTINCT loaders.loader FROM versions
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = versions.id
|
||||
INNER JOIN loaders ON loaders.id = lv.loader_id
|
||||
WHERE versions.mod_id = $1
|
||||
@@ -299,6 +300,7 @@ pub async fn query_one(
|
||||
description: mod_data.description,
|
||||
categories,
|
||||
versions,
|
||||
follows: mod_data.follows,
|
||||
downloads: mod_data.downloads,
|
||||
page_url: format!("https://modrinth.com/mod/{}", mod_id),
|
||||
icon_url,
|
||||
|
||||
@@ -8,7 +8,7 @@ use meilisearch_sdk::client::Client;
|
||||
use meilisearch_sdk::indexes::Index;
|
||||
use meilisearch_sdk::settings::Settings;
|
||||
use sqlx::postgres::PgPool;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::collections::VecDeque;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
@@ -100,6 +100,14 @@ pub async fn reconfigure_indices(config: &SearchConfig) -> Result<(), IndexingEr
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Follows Index
|
||||
update_index(&client, "follows_mods", {
|
||||
let mut follows_rules = default_rules();
|
||||
follows_rules.push_front("desc(follows)".to_string());
|
||||
follows_rules.into()
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Updated Index
|
||||
update_index(&client, "updated_mods", {
|
||||
let mut updated_rules = default_rules();
|
||||
@@ -242,6 +250,7 @@ fn default_settings() -> Settings {
|
||||
"categories".to_string(),
|
||||
"versions".to_string(),
|
||||
"downloads".to_string(),
|
||||
"follows".to_string(),
|
||||
"page_url".to_string(),
|
||||
"icon_url".to_string(),
|
||||
"author_url".to_string(),
|
||||
@@ -262,8 +271,6 @@ fn default_settings() -> Settings {
|
||||
Settings::new()
|
||||
.with_displayed_attributes(displayed_attributes)
|
||||
.with_searchable_attributes(searchable_attributes)
|
||||
.with_stop_words(vec![])
|
||||
.with_synonyms(HashMap::new())
|
||||
.with_attributes_for_faceting(vec![
|
||||
String::from("categories"),
|
||||
String::from("host"),
|
||||
|
||||
@@ -68,6 +68,7 @@ pub struct UploadSearchMod {
|
||||
pub description: String,
|
||||
pub categories: Vec<Cow<'static, str>>,
|
||||
pub versions: Vec<String>,
|
||||
pub follows: i32,
|
||||
pub downloads: i32,
|
||||
pub page_url: String,
|
||||
pub icon_url: String,
|
||||
@@ -160,6 +161,7 @@ pub async fn search_for_mod(
|
||||
let index = match index {
|
||||
"relevance" => "relevance_mods",
|
||||
"downloads" => "downloads_mods",
|
||||
"follows" => "follows_mods",
|
||||
"updated" => "updated_mods",
|
||||
"newest" => "newest_mods",
|
||||
i => return Err(SearchError::InvalidIndex(i.to_string())),
|
||||
|
||||
Reference in New Issue
Block a user