2021-09-18 15:32:39 +02:00
|
|
|
package txt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-10-13 16:12:56 +02:00
|
|
|
Empty = ""
|
|
|
|
Space = " "
|
|
|
|
Or = "|"
|
|
|
|
And = "&"
|
|
|
|
Plus = "+"
|
|
|
|
SpacedPlus = Space + Plus + Space
|
2021-09-18 15:32:39 +02:00
|
|
|
)
|
|
|
|
|
2021-10-13 16:12:56 +02:00
|
|
|
// Spaced returns the string padded with a space left and right.
|
|
|
|
func Spaced(s string) string {
|
|
|
|
return Space + s + Space
|
|
|
|
}
|
|
|
|
|
|
|
|
// StripOr removes or operators from a query.
|
|
|
|
func StripOr(s string) string {
|
|
|
|
s = strings.ReplaceAll(s, Or, Space)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// QueryTooShort tests if a search query is too short.
|
|
|
|
func QueryTooShort(q string) bool {
|
|
|
|
q = strings.Trim(q, "- '")
|
|
|
|
|
|
|
|
return q != Empty && len(q) < 3 && IsLatin(q)
|
|
|
|
}
|