-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve log analysis insertion and sorting
- Loading branch information
Showing
3 changed files
with
58 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package nearest | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/lithammer/fuzzysearch/fuzzy" | ||
) | ||
|
||
const MAX_CLOSEST_FILE_DISTANCE = 6 | ||
|
||
func FilenameNearest(filePath string, indices map[string]int, filenames []string) string { | ||
if _, ok := indices[filePath]; !ok { | ||
// check if the filePath is already an alias | ||
found := fuzzy.RankFindNormalizedFold(filePath, filenames) | ||
|
||
// if the file path is not found, return the file path | ||
if len(found) == 0 { | ||
return filePath | ||
} | ||
|
||
// find the closest file name first before adding the value | ||
foundPath := found[0].Target | ||
distance := found[0].Distance | ||
|
||
if distance <= MAX_CLOSEST_FILE_DISTANCE && (strings.HasPrefix(foundPath, filePath) || strings.HasPrefix(filePath, foundPath)) { | ||
return foundPath | ||
} | ||
} | ||
|
||
return filePath | ||
} |