// parseQuery parses a field-separated symbol query, extracting the special
// characters listed below, and returns a matcherFunc corresponding to the AND
// of all field queries.
//
// Special characters:
//   ^  match exact prefix
//   $  match exact suffix
//   '  match exact
//
// In all three of these special queries, matches are 'smart-cased', meaning
// they are case sensitive if the symbol query contains any upper-case
// characters, and case insensitive otherwise.
parseQuery parses a field-separated symbol query, extracting the special
characters listed below, and returns a matcherFunc corresponding to the AND
of all field queries.

Special characters:
^  match exact prefix
$  match exact suffix
'  match exact

In all three of these special queries, matches are 'smart-cased', meaning
they are case sensitive if the symbol query contains any upper-case
characters, and case insensitive otherwise.
// parseQuery parses a field - separated symbol query extracting the special // characters listed below and returns a matcherFunc corresponding to the AND // of all field queries . // // Special characters : // ^ match exact prefix // $ match exact suffix // ' match exact // // In all three of these special queries matches are ' smart - cased ' meaning // they are case sensitive if the symbol query contains any upper - case // characters and case insensitive otherwise .
func parseQuery(q string) matcherFunc {
	fields := strings.Fields(q)
	if len(fields) == 0 {
		return func([]string) (int, float64) { return -1, 0 }
	}
	var funcs []matcherFunc
	for _, field := range fields {
		var f matcherFunc
		switch {
		case strings.HasPrefix(field, "^"):
			prefix := field[1:]
			f = smartCase(prefix, func(chunks []string) (int, float64) {
				s := strings.Join(chunks, "")
				if strings.HasPrefix(s, prefix) {
					return 0, 1
				}
				return -1, 0
			})
		case strings.HasPrefix(field, "'"):
			exact := field[1:]
			f = smartCase(exact, matchExact(exact))
		case strings.HasSuffix(field, "$"):
			suffix := field[0 : len(field)-1]
			f = smartCase(suffix, func(chunks []string) (int, float64) {
				s := strings.Join(chunks, "")
				if strings.HasSuffix(s, suffix) {
					return len(s) - len(suffix), 1
				}
				return -1, 0
			})
		default:
			fm := fuzzy.NewMatcher(field)
			f = func(chunks []string) (int, float64) {
				score := float64(fm.ScoreChunks(chunks))
				ranges := fm.MatchedRanges()
				if len(ranges) > 0 {
					return ranges[0], score
				}
				return -1, score
			}
		}
		funcs = append(funcs, f)
	}
	if len(funcs) == 1 {
		return funcs[0]
	}
	return comboMatcher(funcs).match
}
func parseQuery ( q string ) matcherFunc { fields := strings . Fields ( q ) if len ( fields ) == 0 { return func ( [ ] string ) ( int , float64 ) { return - 1 , 0 } } var funcs [ ] matcherFunc for _ , field := range fields { var f matcherFunc switch { case strings . HasPrefix ( field , " " ) : prefix := field [ 1 : ] f = smartCase ( prefix , func ( chunks [ ] string ) ( int , float64 ) { s := strings . Join ( chunks , " " ) if strings . HasPrefix ( s , prefix ) { return 0 , 1 } return - 1 , 0 } ) case strings . HasPrefix ( field , " " ) : exact := field [ 1 : ] f = smartCase ( exact , matchExact ( exact ) ) case strings . HasSuffix ( field , " " ) : suffix := field [ 0 : len ( field ) - 1 ] f = smartCase ( suffix , func ( chunks [ ] string ) ( int , float64 ) { s := strings . Join ( chunks , " " ) if strings . HasSuffix ( s , suffix ) { return len ( s ) - len ( suffix ) , 1 } return - 1 , 0 } ) default : fm := fuzzy . NewMatcher ( field ) f = func ( chunks [ ] string ) ( int , float64 ) { score := float64 ( fm . ScoreChunks ( chunks ) ) ranges := fm . MatchedRanges ( ) if len ( ranges ) > 0 { return ranges [ 0 ] , score } return - 1 , score } } funcs = append ( funcs , f ) } if len ( funcs ) == 1 { return funcs [ 0 ] } return comboMatcher ( funcs ) . match }
parseQuery parses a field-separated symbol query, extracting the special
characters listed below, and returns a matcherFunc corresponding to the AND
of all field queries.
parseQuery parses a field - separated symbol query extracting the special characters listed below and returns a matcherFunc corresponding to the AND of all field queries .