knowledge-search

git clone git://archive.git.mtrnord.blog/MTRNord/knowledge-search.git
Log | Files | Refs | README | LICENSE

commit 35ae8f48d6a90e84b47bde92e78d40fde2aee61c
parent fc3ad26af66cddba6002f0519315d9a869285afe
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 28 Mar 2023 01:05:53 +0200

feat: communicate available identifiers via a config file

Diffstat:
MCargo.lock | 148++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Mcrates/matrix-indexer/src/main.rs | 14+++++++++++++-
Mcrates/matrix-indexer/src/matrix.rs | 4+---
Mcrates/utils/Cargo.toml | 6++++--
Mcrates/utils/src/lib.rs | 39+++++++++++++++++++++++++++++++++++++++
5 files changed, 148 insertions(+), 63 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -143,20 +143,20 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4655ae1a7b0cdf149156f780c5bf3f1352bc53cbd9e0a361a7ef7b22947e965" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] [[package]] name = "async-trait" -version = "0.1.67" +version = "0.1.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] @@ -240,9 +240,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bb524613be645939e280b7279f7b017f98cf7f5ef084ec374df373530e73277" dependencies = [ "heck", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] @@ -488,9 +488,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a932373bab67b984c790ddf2c9ca295d8e3af3b7ef92de5a5bacdccdee4b09b" dependencies = [ "heck", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] @@ -577,9 +577,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -650,9 +650,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -662,34 +662,34 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", "once_cell", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "scratch", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] name = "cxxbridge-flags" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] @@ -710,7 +710,7 @@ checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "strsim", "syn 1.0.109", @@ -765,7 +765,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" dependencies = [ "darling", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -807,6 +807,26 @@ dependencies = [ ] [[package]] +name = "dirs" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dece029acd3353e3a58ac2e3eb3c8d6c35827a892edc6cc4138ef9c33df46ecd" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b" +dependencies = [ + "libc", + "redox_users", + "windows-sys 0.45.0", +] + +[[package]] name = "discard" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -818,7 +838,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -1006,7 +1026,7 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -1380,9 +1400,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg 1.1.0", "hashbrown", @@ -1872,7 +1892,7 @@ version = "5.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a07ad93a80d1b92bb44cb42d7c49b49c9aab1778befefad49cceb5e4c5bf460" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -2124,7 +2144,7 @@ checksum = "75a1ef20bf3193c15ac345acb32e26b3dc3223aff4d77ae4fc5359567683796b" dependencies = [ "pest", "pest_meta", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -2204,7 +2224,7 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -2254,7 +2274,7 @@ version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "syn 1.0.109", ] @@ -2279,9 +2299,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.53" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" +checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" dependencies = [ "unicode-ident", ] @@ -2326,7 +2346,7 @@ checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" dependencies = [ "anyhow", "itertools", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -2355,7 +2375,7 @@ version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", ] [[package]] @@ -2554,10 +2574,21 @@ dependencies = [ ] [[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.8", + "redox_syscall", + "thiserror", +] + +[[package]] name = "regex" -version = "1.7.2" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -2737,7 +2768,7 @@ checksum = "0f82e91eb61cd86d9287303133ee55b54618eccb75a522cc22a42c15f5bda340" dependencies = [ "once_cell", "proc-macro-crate", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "ruma-identifiers-validation", "serde", @@ -2853,9 +2884,9 @@ version = "1.0.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] @@ -3072,18 +3103,18 @@ version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.8" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9" +checksum = "5aad1363ed6d37b84299588d62d3a7d95b5a5c2d9aad5c85609fda12afaa1f40" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "unicode-ident", ] @@ -3100,7 +3131,7 @@ version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", "unicode-xid 0.2.4", @@ -3187,9 +3218,9 @@ version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", - "syn 2.0.8", + "syn 2.0.10", ] [[package]] @@ -3252,7 +3283,7 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -3358,7 +3389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bf5e9b9c0f7e0a7c027dcfaba7b2c60816c7049171f679d99ee2ff65d0de8c4" dependencies = [ "prettyplease", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "prost-build", "quote 1.0.26", "syn 1.0.109", @@ -3415,7 +3446,7 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", ] @@ -3632,8 +3663,11 @@ dependencies = [ name = "utils" version = "0.0.0" dependencies = [ + "dirs", "indradb-lib", "indradb-proto", + "serde", + "serde_json", "tokio", ] @@ -3757,7 +3791,7 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", "wasm-bindgen-shared", @@ -3791,7 +3825,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", "wasm-bindgen-backend", @@ -3988,9 +4022,9 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winnow" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deac0939bd6e4f24ab5919fbf751c97a8cfc8543bb083a305ed5c0c10bb241d1" +checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" dependencies = [ "memchr", ] @@ -4031,7 +4065,7 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" dependencies = [ - "proc-macro2 1.0.53", + "proc-macro2 1.0.54", "quote 1.0.26", "syn 1.0.109", "synstructure", diff --git a/crates/matrix-indexer/src/main.rs b/crates/matrix-indexer/src/main.rs @@ -24,6 +24,8 @@ // I am lazy. Dont blame me! #![allow(missing_docs)] +use std::collections::BTreeSet; + use color_eyre::{eyre::bail, Result}; use config::{load, write_access_token}; @@ -41,7 +43,17 @@ async fn main() -> Result<()> { // Errors in the config will crash directly. let config = load(); - // TODO: config which rewrites itself to have the data after login + // Make sure to update identifier list. These are ONLY the ones we can query aka they are indexed + let mut identifiers = BTreeSet::from([ + String::from("text_message_body"), + String::from("text_message_formatted_body"), + String::from("room_id"), + String::from("room_name"), + String::from("room_topic"), + String::from("event_id"), + ]); + utils::add_identifiers(&mut identifiers)?; + #[allow(clippy::unwrap_used)] let mut bot = match config.auth_data { config::AuthData::UsernamePassword(mxid, password) => { diff --git a/crates/matrix-indexer/src/matrix.rs b/crates/matrix-indexer/src/matrix.rs @@ -63,6 +63,7 @@ impl IndexerBot { let notice_message_event_type = utils::indradb::Identifier::new("notice_message_event")?; let event_id_type = utils::indradb::Identifier::new("event_id")?; let event_in_room_type = utils::indradb::Identifier::new("event_in_room")?; + indexer_client.index_property(room_id_type).await?; indexer_client.index_property(room_name_type).await?; indexer_client.index_property(room_topic_type).await?; indexer_client.index_property(event_id_type).await?; @@ -70,9 +71,6 @@ impl IndexerBot { .index_property(utils::indradb::Identifier::new("text_message_body")?) .await?; indexer_client - .index_property(utils::indradb::Identifier::new("text_message_format")?) - .await?; - indexer_client .index_property(utils::indradb::Identifier::new( "text_message_formatted_body", )?) diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml @@ -8,4 +8,7 @@ edition = "2021" [dependencies] indradb-lib = { version = "4.0.0", default_features = false } indradb-proto = "4.0.0" -tokio = { version = "1.26.0", features = ["time"] } -\ No newline at end of file +tokio = { version = "1.26.0", features = ["time"] } +dirs = "5.0.0" +serde_json = "1.0.94" +serde = { version = "1.0.158", features = ["derive"] } diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs @@ -24,8 +24,11 @@ // I am lazy. Dont blame me! #![allow(missing_docs)] +use std::{collections::BTreeSet, fs::OpenOptions, path::PathBuf}; + pub use indradb; pub use indradb_proto; +use serde::{Deserialize, Serialize}; use tokio::time::{sleep, Duration}; pub async fn get_client( @@ -58,3 +61,39 @@ pub async fn get_client_retrying( Err(last_err.expect("We didnt get an error even though connection failed")) } + +fn get_identifier_config() -> PathBuf { + let config_path = dirs::config_dir(); + if let Some(config_path) = config_path { + config_path.join("knowledge-search/identifier.json") + } else { + panic!("System not supported.") + } +} + +#[derive(Debug, Serialize, Deserialize)] +struct IdentifierConfig { + identifiers: BTreeSet<String>, +} + +pub fn get_identifier() -> Result<BTreeSet<String>, std::io::Error> { + let identifier_file = OpenOptions::new() + .read(true) + .create(true) + .open(get_identifier_config())?; + let identifier_config: IdentifierConfig = serde_json::from_reader(identifier_file)?; + Ok(identifier_config.identifiers) +} + +pub fn add_identifiers(identifiers: &mut BTreeSet<String>) -> Result<(), std::io::Error> { + let identifier_file = OpenOptions::new() + .read(true) + .write(true) + .create(true) + .open(get_identifier_config())?; + let mut identifier_config: IdentifierConfig = serde_json::from_reader(&identifier_file)?; + identifier_config.identifiers.append(identifiers); + serde_json::to_writer_pretty(identifier_file, &identifier_config)?; + + Ok(()) +}