From 712424c3398a87c09273b41cceaae25b7502d852 Mon Sep 17 00:00:00 2001 From: Mysterious_Dev <40738104+Mysterious-Dev@users.noreply.github.com> Date: Sun, 25 Apr 2021 04:44:11 +0200 Subject: [PATCH] Add alphabetically sorting (#190) --- src/search/indexing/mod.rs | 18 ++++++++++++++++++ src/search/mod.rs | 1 + 2 files changed, 19 insertions(+) diff --git a/src/search/indexing/mod.rs b/src/search/indexing/mod.rs index 6454b4ef2..b0646a20f 100644 --- a/src/search/indexing/mod.rs +++ b/src/search/indexing/mod.rs @@ -77,6 +77,7 @@ pub async fn reset_indices(config: &SearchConfig) -> Result<(), IndexingError> { client.delete_index("relevance_mods").await?; client.delete_index("downloads_mods").await?; client.delete_index("follows_mods").await?; + client.delete_index("alphabetically_mods").await?; client.delete_index("updated_mods").await?; client.delete_index("newest_mods").await?; Ok(()) @@ -109,6 +110,14 @@ pub async fn reconfigure_indices(config: &SearchConfig) -> Result<(), IndexingEr }) .await?; + // Alphabetically Index + update_index(&client, "alphabetically_mods", { + let mut alphabetically_rules = default_rules(); + alphabetically_rules.push_front("desc(title)".to_string()); + alphabetically_rules.into() + }) + .await?; + // Updated Index update_index(&client, "updated_mods", { let mut updated_rules = default_rules(); @@ -217,6 +226,15 @@ pub async fn add_mods( .await?; add_to_index(follows_index, &mods).await?; + // Alphabetically Index + let alphabetically_index = create_index(&client, "alphabetically_mods", || { + let mut alphabetically_rules = default_rules(); + alphabetically_rules.push_front("desc(title)".to_string()); + alphabetically_rules.into() + }) + .await?; + add_to_index(alphabetically_index, &mods).await?; + // Updated Index let updated_index = create_index(&client, "updated_mods", || { let mut updated_rules = default_rules(); diff --git a/src/search/mod.rs b/src/search/mod.rs index 3dd45c803..af84c2ea6 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -163,6 +163,7 @@ pub async fn search_for_mod( "relevance" => "relevance_mods", "downloads" => "downloads_mods", "follows" => "follows_mods", + "alphabetically" => "alphabetically_mods", "updated" => "updated_mods", "newest" => "newest_mods", i => return Err(SearchError::InvalidIndex(i.to_string())),