Skip to content

Commit

Permalink
datashed: cleanup index command (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Nico Wagner <[email protected]>
  • Loading branch information
nwagner84 authored Jul 15, 2024
1 parent 31d9903 commit c5778ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/datashed/src/commands/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::stdout;
use std::path::PathBuf;

use clap::Parser;
use glob::{glob_with, MatchOptions};
use glob::glob_with;
use indicatif::ParallelProgressIterator;
use polars::prelude::*;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
Expand Down Expand Up @@ -62,14 +62,12 @@ impl TryFrom<&PathBuf> for Row {
impl Index {
pub(crate) fn execute(self) -> DatashedResult<()> {
let datashed = Datashed::discover()?;
let config = datashed.config()?;
let data_dir = datashed.data_dir();
let base_dir = datashed.base_dir();
let config = datashed.config()?;

let pattern = format!("{}/**/*.txt", data_dir.display());
let options = MatchOptions::default();

let files: Vec<_> = glob_with(&pattern, options)
let files: Vec<_> = glob_with(&pattern, Default::default())
.map_err(|e| DatashedError::Other(e.to_string()))?
.filter_map(Result::ok)
.collect();
Expand All @@ -84,9 +82,7 @@ impl Index {
.map(Row::try_from)
.collect::<Result<Vec<_>, _>>()
.map_err(|_| {
DatashedError::Other(
"unable to index documents!".into(),
)
DatashedError::other("unable to index documents!")
})?;

let mut idn: Vec<String> = vec![];
Expand Down
7 changes: 7 additions & 0 deletions crates/datashed/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ pub(crate) enum DatashedError {
#[error("{0}")]
Other(String),
}

impl DatashedError {
#[inline]
pub(crate) fn other<T: ToString>(s: T) -> Self {
Self::Other(s.to_string())
}
}

0 comments on commit c5778ad

Please sign in to comment.