@@ -49,6 +49,7 @@ fn parse_txt_file(file_path: &Path) -> Result<String, ()> {
4949 Ok ( content)
5050}
5151
52+ /* Parse all the text from the PDF File with Poppler */
5253fn parse_pdf_files ( file_path : & Path ) -> Result < String , ( ) > {
5354 let mut content = String :: new ( ) ;
5455
@@ -108,6 +109,8 @@ fn save_model_as_json(model: &InMemoryModel, index_path: &str) -> Result<(), ()>
108109 Ok ( ( ) )
109110}
110111
112+ const ALLOWED_FILE_TYPE_EXTENSIONS : [ & str ; 5 ] = [ "xml" , "xhtml" , "txt" , "md" , "pdf" ] ;
113+
111114/* Indexes a folder as a json file and adds to model, Processed is the number of file indexed */
112115fn append_folder_to_model ( dir_path : & Path , model : Arc < Mutex < InMemoryModel > > , processed : & mut usize ) -> Result < ( ) , ( ) > {
113116 let dir = fs:: read_dir ( dir_path) . map_err ( |err| {
@@ -136,25 +139,29 @@ fn append_folder_to_model(dir_path: &Path, model: Arc<Mutex<InMemoryModel>>, pro
136139
137140 // Skip unsupported files
138141 if let Some ( ext) = file_ext {
139- const ALLOWED_EXTS : [ & str ; 5 ] = [ "xml" , "xhtml" , "txt" , "md" , "pdf" ] ;
140- if !ALLOWED_EXTS . contains ( & ext. to_str ( ) . unwrap ( ) ) {
142+ if !ALLOWED_FILE_TYPE_EXTENSIONS . contains ( & ext. to_str ( ) . unwrap ( ) ) {
141143 println ! ( "{}: Skipping unsupported file {}" , "INFO" . cyan( ) , file_path_str. bright_yellow( ) ) ;
142144 continue ' step;
143145 }
144146 }
145147
148+ // Skip dot files or folders
149+ let dot_files = file_path
150+ . file_name ( )
151+ . and_then ( |s| s. to_str ( ) )
152+ . map ( |s| s. starts_with ( "." ) )
153+ . unwrap ( ) ;
154+ if dot_files {
155+ continue ' step;
156+ }
157+
146158 // If file is another directory recursively index it too
147159 let file_type = file. file_type ( ) . map_err ( |err| {
148160 eprintln ! ( "{err}: Failed to determine file type for {file_path} as {msg}" , err = "ERROR" . bold( ) . red( ) , file_path = file_path_str. bold( ) . bright_blue( ) , msg = err. to_string( ) . red( ) ) ;
149161 } ) ?;
150162
151163 // Recursively index all the folders
152164 if file_type. is_dir ( ) {
153- // Skip the .git folder
154- if file_path. file_name ( ) . unwrap ( ) == ".git" {
155- continue ' step;
156- }
157-
158165 append_folder_to_model ( & file_path, Arc :: clone ( & model) , processed) ?;
159166 continue ' step;
160167 }
@@ -173,10 +180,7 @@ fn append_folder_to_model(dir_path: &Path, model: Arc<Mutex<InMemoryModel>>, pro
173180
174181 model. add_document ( file_path, & content, last_modified) ?;
175182 * processed += 1 ;
176- } else {
177- println ! ( "{}: Ignoring {} as already indexed ..." , "INFO" . cyan( ) , file_path_str. bright_cyan( ) ) ;
178- }
179-
183+ }
180184 }
181185 Ok ( ( ) )
182186}
@@ -314,11 +318,11 @@ fn entry() -> Result<(), ()> {
314318 println ! ( "{}: Finished indexing ..." , "INFO" . cyan( ) ) ;
315319 } ) ;
316320 }
321+ // TODO: Print the information of server start at the end of logging
317322 return server:: start ( & address, Arc :: clone ( & model) ) ;
318323 }
319324
320325 _ => {
321-
322326 usage ( & program) ;
323327 eprintln ! ( "{}: Unknown subcommand {}" , "ERROR" . bold( ) . red( ) , subcommand. bold( ) . bright_blue( ) ) ;
324328 return Err ( ( ) ) ;
0 commit comments