diff --git a/Cargo.lock b/Cargo.lock index ae401b28e..ded4d97ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1072,6 +1072,37 @@ dependencies = [ "syn", ] +[[package]] +name = "curl" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e268162af1a5fe89917ae25ba3b0a77c8da752bdc58e7dbb4f15b91fbd33756e" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi 0.3.9", +] + +[[package]] +name = "curl-sys" +version = "0.4.40+curl-7.75.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ffafc1c35958318bd7fdd0582995ce4c72f4f461a8e70499ccee83a619fd562" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi 0.3.9", +] + [[package]] name = "darling" version = "0.10.2" @@ -1298,6 +1329,18 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531a685ab99b8f60a271b44d5dd1a76e55124a8c9fa0407b7a8e9cd172d5b588" +dependencies = [ + "futures-core", + "futures-sink", + "pin-project 1.0.4", + "spinning_top", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1856,6 +1899,30 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" +[[package]] +name = "isahc" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3d0a62435883f745c825ec06a03a38d24bf5fa65c43e2c083b6a60ce0058ae" +dependencies = [ + "crossbeam-utils 0.8.1", + "curl", + "curl-sys", + "encoding_rs", + "flume", + "futures-lite", + "http", + "log", + "mime", + "once_cell", + "slab", + "sluice", + "tracing", + "tracing-futures", + "url", + "waker-fn", +] + [[package]] name = "itoa" version = "0.4.7" @@ -1957,6 +2024,28 @@ version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +[[package]] +name = "libnghttp2-sys" +version = "0.1.6+1.43.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0af55541a8827e138d59ec9e5877fb6095ece63fb6f4da45e7491b4fbd262855" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libz-sys" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "602113192b08db8f38796c4e85c39e960c145965140e918018bcde1952429655" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.4" @@ -2034,12 +2123,12 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "meilisearch-sdk" -version = "0.4.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb2081610089deb10290747b8782049f9cb64a70a4d305a28970db8b780d1448" +checksum = "f8972f69aef330566ece2a76e61ebb9383565b03c45aeb95dbd66ad672186497" dependencies = [ + "isahc", "log", - "reqwest 0.10.10", "serde", "serde_json", "wasm-bindgen", @@ -3179,6 +3268,17 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "sluice" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fa0333a60ff2e3474a6775cc611840c2a55610c831dd366503474c02f1a28f5" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", +] + [[package]] name = "smallvec" version = "1.6.1" @@ -3202,6 +3302,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spinning_top" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e529d73e80d64b5f2631f9035113347c578a1c9c7774b83a2b880788459ab36" +dependencies = [ + "lock_api", +] + [[package]] name = "sqlformat" version = "0.1.5" @@ -3701,9 +3810,21 @@ dependencies = [ "cfg-if 1.0.0", "log", "pin-project-lite 0.2.4", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a9bd1db7706f2373a190b0d067146caa39350c486f3d455b0e33b431f94c07" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.17" diff --git a/Cargo.toml b/Cargo.toml index a76bec688..5e81cbaae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ actix-multipart = "0.3.0" actix-cors = "0.4.1" actix-ratelimit = "0.3.0" -meilisearch-sdk = "0.4.0" +meilisearch-sdk = "0.6.0" reqwest = { version = "0.10.8", features = ["json"] } serde_json = "1.0" diff --git a/src/search/indexing/local_import.rs b/src/search/indexing/local_import.rs index b8ea26ad6..8b8729248 100644 --- a/src/search/indexing/local_import.rs +++ b/src/search/indexing/local_import.rs @@ -162,9 +162,9 @@ pub async fn index_local(pool: PgPool) -> Result, IndexingE date_modified: mod_data.updated, modified_timestamp: mod_data.updated.timestamp(), latest_version, - license: Some(license.short), - client_side: Some(client_side.to_string()), - server_side: Some(server_side.to_string()), + license: license.short, + client_side: client_side.to_string(), + server_side: server_side.to_string(), host: Cow::Borrowed("modrinth"), slug: mod_data.slug, }); @@ -311,9 +311,9 @@ pub async fn query_one( date_modified: mod_data.updated, modified_timestamp: mod_data.updated.timestamp(), latest_version, - license: Some(license.short), - client_side: Some(client_side.to_string()), - server_side: Some(server_side.to_string()), + license: license.short, + client_side: client_side.to_string(), + server_side: server_side.to_string(), host: Cow::Borrowed("modrinth"), slug: mod_data.slug, }) diff --git a/src/search/indexing/mod.rs b/src/search/indexing/mod.rs index 7f8d548fc..6454b4ef2 100644 --- a/src/search/indexing/mod.rs +++ b/src/search/indexing/mod.rs @@ -76,6 +76,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("updated_mods").await?; client.delete_index("newest_mods").await?; Ok(()) @@ -207,6 +208,15 @@ pub async fn add_mods( .await?; add_to_index(downloads_index, &mods).await?; + // Follows Index + let follows_index = create_index(&client, "follows_mods", || { + let mut follows_rules = default_rules(); + follows_rules.push_front("desc(follows)".to_string()); + follows_rules.into() + }) + .await?; + add_to_index(follows_index, &mods).await?; + // Updated Index let updated_index = create_index(&client, "updated_mods", || { let mut updated_rules = default_rules(); @@ -244,6 +254,7 @@ fn default_rules() -> VecDeque { fn default_settings() -> Settings { let displayed_attributes = vec![ "mod_id".to_string(), + "slug".to_string(), "author".to_string(), "title".to_string(), "description".to_string(), @@ -257,6 +268,9 @@ fn default_settings() -> Settings { "date_created".to_string(), "date_modified".to_string(), "latest_version".to_string(), + "license".to_string(), + "client_side".to_string(), + "server_side".to_string(), "host".to_string(), ]; @@ -268,11 +282,14 @@ fn default_settings() -> Settings { "author".to_string(), ]; + let stop_words: Vec = Vec::new(); + let synonyms: HashMap> = HashMap::new(); + Settings::new() .with_displayed_attributes(displayed_attributes) .with_searchable_attributes(searchable_attributes) - .with_stop_words(vec![]) - .with_synonyms(HashMap::new()) + .with_stop_words(stop_words) + .with_synonyms(synonyms) .with_attributes_for_faceting(vec![ String::from("categories"), String::from("host"), diff --git a/src/search/mod.rs b/src/search/mod.rs index 11a19f98e..3dd45c803 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -74,9 +74,9 @@ pub struct UploadSearchMod { pub icon_url: String, pub author_url: String, pub latest_version: Cow<'static, str>, - pub license: Option, - pub client_side: Option, - pub server_side: Option, + pub license: String, + pub client_side: String, + pub server_side: String, /// RFC 3339 formatted creation date of the mod pub date_created: DateTime, @@ -109,6 +109,7 @@ pub struct ResultSearchMod { // TODO: more efficient format for listing versions, without many repetitions pub versions: Vec, pub downloads: i32, + pub follows: i32, pub page_url: String, pub icon_url: String, pub author_url: String, @@ -117,9 +118,9 @@ pub struct ResultSearchMod { /// RFC 3339 formatted modification date of the mod pub date_modified: String, pub latest_version: String, - pub license: Option, - pub client_side: Option, - pub server_side: Option, + pub license: String, + pub client_side: String, + pub server_side: String, /// The host of the mod: Either `modrinth` or `curseforge` pub host: String,