Thu 1 Aug 16:08:12 CEST 2024
This commit is contained in:
parent
3e6e578a54
commit
85225e8e99
32
data.go
32
data.go
|
@ -31,7 +31,7 @@ func computeScore(term string, s string) float64 {
|
|||
splits := strings.Split(a, "/")
|
||||
term_splits := strings.Split(term, "/")
|
||||
|
||||
score := 1.0 / float64(len(splits))
|
||||
score := 0.0
|
||||
used := make([]bool, len(term_splits))
|
||||
for i, term := range term_splits {
|
||||
if used[i] {
|
||||
|
@ -49,6 +49,9 @@ func computeScore(term string, s string) float64 {
|
|||
}
|
||||
}
|
||||
}
|
||||
if score > 0 {
|
||||
score += 1.0/float64(strings.Count(a, "/")+1)
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
|
@ -106,10 +109,10 @@ func Filter(term string, targets []string) []list.Rank {
|
|||
return result
|
||||
}
|
||||
|
||||
func getPaths() []string {
|
||||
func getPathsFromFile(path string) []string {
|
||||
paths := []string{}
|
||||
|
||||
file, err := os.Open("/home/user/.cache/fzy_paths_d")
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error opening file:", err)
|
||||
return paths
|
||||
|
@ -133,10 +136,31 @@ func getPaths() []string {
|
|||
return paths
|
||||
}
|
||||
|
||||
func getPathsFromStdin() []string {
|
||||
paths := []string{}
|
||||
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text() // Get the current line
|
||||
paths = append(paths, line)
|
||||
}
|
||||
|
||||
// Check for errors during scanning
|
||||
if err := scanner.Err(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error reading from stdin:", err)
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
|
||||
func getListItems() []list.Item {
|
||||
items := []list.Item{}
|
||||
paths := getPaths()
|
||||
// paths := getPathsFromFile("/home/user/.cache/fzy_paths_d")
|
||||
paths := getPathsFromStdin()
|
||||
for _, path := range paths {
|
||||
if len(path) == 0 {
|
||||
continue
|
||||
}
|
||||
items = append(items, item{path})
|
||||
}
|
||||
return items
|
||||
|
|
Loading…
Reference in New Issue