Commits

Anonymous committed 958a26f

maching symbols near separator has the greates influence on match results

Comments (0)

Files changed (1)

 func (p *Paths) find(hints []string) string {
 	var bestPath string
 	bestWeight := 0
+	bestSep := 0
 	if len(hints) == 0 {
 		return ""
 	}
 			continue // skip non-existing paths
 		}
 		w := 0
+		sep := 0
 		hintIndex := len(hints)
 		for i := len(path) - 1; i >= 0; i-- {
 			if strings.HasPrefix(path[i:], hints[hintIndex-1]) {
 				w = w + i + len(hints[hintIndex-1])
 				if i > 0 && path[i-1] == '/' {
-					w = w + 2*i // bonus for mathing the separator
+					sep = sep + 1 // bonus for mathing the separator
 				}
 				hintIndex = hintIndex - 1
 				if hintIndex == 0 {
 		if len(bestPath) == 0 {
 			bestPath = path
 			bestWeight = w
+			bestSep = sep
 			continue
 		}
 
-		a := w / len(path)
-		b := bestWeight / len(bestPath)
-		if a > b || (a == b && len(path) <= len(bestPath)) {
+		a := w * 100 / len(path)
+		b := bestWeight * 100 / len(bestPath)
+
+		c := sep * 100 / len(strings.Split(path, "/"))
+		d := bestSep * 100 / len(strings.Split(bestPath, "/"))
+
+		if c > d || (c == d && a > b) || (c == d && a == b &&
+				len(path) < len(bestPath)) {
 			bestPath = path
 			bestWeight = w
+			bestSep = sep
 		}
 	}
 	return bestPath
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.