commit c55b0221ad0e112dc214d5928e4282a7a3f40153 Author: Alex Wellnitz Date: Tue Oct 24 20:15:03 2023 +0200 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..25f6dde --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rustysearch" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4d74f4f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rustysearch" +authors = ["Alex Wellnitz "] +version = "0.1.0" +edition = "2021" +readme = "README.md" +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ceabb1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2023] [Alex Wellnitz] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..32c84cf --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# rustysearch +This is my attempt to implement a search index in Rust + +### Installation + +### Usage diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..2418909 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,62 @@ +use std::{fs, path::Path}; + +pub struct Rustysearch { + base_directory: String, + index_path: String, + docs_path: String, + stats_path: String, +} + +impl Rustysearch { + /// **Sets up the object & the data directory** + /// + /// Requires a ``base_directory`` parameter, which specifies the parent + /// directory the index/document/stats data will be kept in. + /// + pub fn new(path: &str) -> Self { + Self { + base_directory: path.to_string(), + index_path: format!("{}/index", path), + docs_path: format!("{}/docs", path), + stats_path: format!("{}/stats.json", path), + } + } + + /// **Handles the creation of the various data directories** + /// + /// If the paths do not exist, it will create them. As a side effect, you + /// must have read/write access to the location you're trying to create + /// the data at. + /// + fn setup(&self) { + // Create the base directory + if !Path::new(&self.base_directory).exists() { + fs::create_dir(&self.base_directory).expect("Unable to create base directory"); + } + // Create the index directory + if !Path::new(&self.index_path).exists() { + fs::create_dir(&self.index_path).expect("Unable to create index directory"); + } + // Create the docs directory + if !Path::new(&self.docs_path).exists() { + fs::create_dir(&self.docs_path).expect("Unable to create docs directory"); + } + } + + /// **Reads the index-wide stats** + /// + /// If the stats do not exist, it makes returns data with the current + /// version of ``rustysearch`` & zero docs (used in scoring). + /// + pub fn read_stats(&self) -> String { + if !Path::new(&self.stats_path).exists() { + return String::from("{\"version\": \"0.1.0\", \"docs\": 0}"); + } + + return String::from(""); + } +} + +fn main() { + println!("Hello, world!") +}