Repository: ParthJadhav/Rust_Search (language: rust)

Issue:
[Bug]: Search input includes `location` to search for 
```rust
let search: Vec<String> = SearchBuilder::default()
        .location("/System/")
        .search_input("Syste")
        .depth(1)
        .ignore_case()
        .build()
        .collect();
```

This will return everything contained in `/System/` directory because the Regex will be matched with the path input i.e /**Syste**m/ and return everything. 

This could be solved by adding: `.split("/").last().unwrap()` to `path`

```rust
reg_exp.is_match(&path.split("/").last().unwrap())
```

@TheAwiteb , Is there a better way to do this? Or are there any implications using this approach ?
[Bug]: Search input includes `location` to search for 
```rust
let search: Vec<String> = SearchBuilder::default()
        .location("/System/")
        .search_input("Syste")
        .depth(1)
        .ignore_case()
        .build()
        .collect();
```

This will return everything contained in `/System/` directory because the Regex will be matched with the path input i.e /**Syste**m/ and return everything. 

This could be solved by adding: `.split("/").last().unwrap()` to `path`

```rust
reg_exp.is_match(&path.split("/").last().unwrap())
```

@TheAwiteb , Is there a better way to do this? Or are there any implications using this approach ?


Discussion / hints:
Yes, we can use [`Path::file_name`](https://doc.rust-lang.org/std/path/struct.Path.html#method.file_name). Assign it to me, i'll solve it
Okay @TheAwiteb , Thanks a lot
Yes, we can use [`Path::file_name`](https://doc.rust-lang.org/std/path/struct.Path.html#method.file_name). Assign it to me, i'll solve it
Okay @TheAwiteb , Thanks a lot

Fix patch:
diff --git a/src/search.rs b/src/search.rs
index f7b36c7..43a7983 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -95,23 +95,26 @@ impl Search {
 
             Box::new(move |path_entry| {
                 if let Ok(entry) = path_entry {
-                    let path: String = entry.path().display().to_string();
-
-                    if reg_exp.is_match(&path) {
-                        return match tx.send(path) {
-                            Ok(_) => {
+                    let path = entry.path();
+                    if let Some(file_name) = path.file_name() {
+                        // Lossy means that if the file name is not valid UTF-8
+                        // it will be replaced with �.
+                        // Will return the file name with extension.
+                        let file_name = file_name.to_string_lossy().to_string();
+                        if reg_exp.is_match(&file_name) {
+                            // Contunue searching if the send was successful
+                            // and there is no limit or the limit has not been reached
+                            if tx.send(path.display().to_string()).is_ok()
+                                && (limit.is_none() || counter < limit.unwrap())
+                            {
                                 counter += 1;
-                                if limit.is_some() && counter >= limit.unwrap() {
-                                    WalkState::Quit
-                                } else {
-                                    WalkState::Continue
-                                }
+                                return WalkState::Continue;
+                            } else {
+                                return WalkState::Quit;
                             }
-                            Err(_) => WalkState::Quit,
-                        };
+                        }
                     }
                 }
-
                 WalkState::Continue
             })
         });


Test patch: