@@ -2,12 +2,13 @@ use std:: {
22 fs:: { self , File } , io:: { self , BufReader , BufWriter , Read } , path:: Path , process:: { exit, ExitCode } , str:: { self } , sync:: { Arc , Mutex } , thread
33} ;
44
5-
6- use clap:: { Parser , Subcommand , ValueEnum } ;
5+ use parser :: { Cli , Commands } ;
6+ use clap:: { Parser , ValueEnum } ;
77use xml:: { self , reader:: XmlEvent , EventReader } ;
88use xml:: common:: { TextPosition , Position } ;
99use colored:: { Colorize } ;
1010
11+ mod parser;
1112mod lexer;
1213mod server;
1314mod model;
@@ -127,6 +128,7 @@ fn append_folder_to_model(dir_path: &Path, model: Arc<Mutex<InMemoryModel>>, pro
127128 eprintln ! ( "{}: Failed to read directory {dir_path} as \" {err}\" " , "ERROR" . bold( ) . red( ) ,
128129 dir_path = dir_path. to_str( ) . unwrap( ) . bold( ) . bright_blue( ) ,
129130 err = err. to_string( ) . red( ) ) ;
131+ exit ( -1 ) ;
130132 } ) ?;
131133
132134 ' step: for file in dir {
@@ -232,58 +234,13 @@ fn fetch_model(index_path: &str) -> Result<InMemoryModel, ()> {
232234 return Ok ( model) ;
233235}
234236
235- #[ derive( Parser ) ]
236- #[ command( name = "DocSense" , version, author, about, long_about = None ) ]
237- #[ command( about = "A fast document indexing and search engine which runs locally on your machine." , long_about = None ) ]
238- struct Cli {
239- #[ command( subcommand) ]
240- command : Commands ,
241- }
242237
243238#[ derive( ValueEnum , Clone , Debug , PartialEq ) ]
244239enum RankMethod {
245240 Tfidf ,
246241 Bm25
247242}
248243
249- #[ derive( Subcommand ) ]
250- enum Commands {
251- #[ command(
252- about = "Search for a query string in an indexed file" ,
253- long_about = "Search for a prompt string using BM25 (or TF-IDF) ranking algorithm across previously indexed documents."
254- ) ]
255- Search {
256- #[ arg( help = "Path to the .json index file (e.g., index.docsense.json)" ) ]
257- index_file_path : String ,
258- #[ arg( help = "Search prompt string (e.g., 'deep neural networks')" ) ]
259- prompt : String ,
260- #[ arg( short, long, default_value = "tfidf" , value_enum, help = "Ranking algorithm to use" ) ]
261- rank_method : RankMethod ,
262- } ,
263-
264- #[ command(
265- about = "Check how many files are indexed" ,
266- long_about = "Display number of documents currently indexed in the specified index file. Useful for verifying the index state."
267- ) ]
268- Check {
269- #[ arg( default_value="index.json" , help="Path to index file to inspect" ) ]
270- index_file_path : String ,
271- } ,
272-
273- #[ command(
274- about = "Serve directory over HTTP with search interface" ,
275- long_about = "Indexes the provided directory recursively and starts a web server for querying indexed files through a UI."
276- ) ]
277- Serve {
278- #[ arg( help = "Path to directory to index and serve" ) ]
279- dir_path : String ,
280- #[ arg( default_value = "127.0.0.1:6969" , help = "IP:PORT to bind HTTP server (e.g., 0.0.0.0:8080)" ) ]
281- address : String ,
282- #[ arg( short, long, default_value = "tfidf" , value_enum, help = "Ranking algorithm to use" ) ]
283- rank_method : RankMethod ,
284- }
285- }
286-
287244fn entry ( ) -> Result < ( ) , ( ) > {
288245 let cli = Cli :: parse ( ) ;
289246
0 commit comments