func (q Query) Score(pathStr, text string) float64 {
	name := path.Base(pathStr)
	tokensInName := 0
	tokensMatching := 0
	totalMatches := 0
	for _, token := range q.tokens {
		if token.pattern.MatchString(name) {
			tokensInName++
		}
		count := len(token.pattern.FindAllStringIndex(text, maxMatchesPerDoc))
		if count > 0 {
			tokensMatching++
		}
		totalMatches += count
	}
	return float64(tokensInName*500) + float64(float64(tokensMatching)*50*math.Pow(4, float64(tokensMatching))) + float64(totalMatches)/float64(len(text)+1)
}
Score scores the query match against the path and text.
package query
import (
	"math"
	"path"
	"sort"
	"strings"
)
type Query struct {
	input  string  
	tokens []token
}
func Parse(queryStr string) Query {
	tokenStrs := strings.Fields(queryStr)
	uniq := make(map[string]struct{}, len(tokenStrs))
	for _, tokenStr := range tokenStrs {
		uniq[strings.ToLower(tokenStr)] = struct{}{}
	}
	tokens := make([]token, 0, len(uniq))
	for tokenStr := range uniq {
		tokens = append(tokens, newToken(tokenStr))
	}
	return Query{
		input:  queryStr,
		tokens: tokens,
	}
}
func (q Query) Match(pathStr, text string) bool {
	name := path.Base(pathStr)
	for _, token := range q.tokens {
		if token.pattern.MatchString(name) {
			return true
		}
		if token.pattern.MatchString(text) {
			return true
		}
	}
	return false
}
const maxMatchesPerDoc = 50