Initial Commit
This commit is contained in:
commit
c55b0221ad
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -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"
|
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "rustysearch"
|
||||||
|
authors = ["Alex Wellnitz <moin@wellnitz-alex.de>"]
|
||||||
|
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]
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -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.
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# rustysearch
|
||||||
|
This is my attempt to implement a search index in Rust
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
### Usage
|
62
src/main.rs
Normal file
62
src/main.rs
Normal file
@ -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!")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user