feat: case insensitive search by default #415
Former-commit-id: e39d951ceaac2a3c9b055b8661c17432d746f5d2 [formerly f6a93dfc39e6edec09f19228d9d8d6cb66fbdac4] [formerly 0cecdec65555f37fab1e8773f066928cf821f6b5 [formerly 43d489c194
]]
Former-commit-id: 57fd7a80303a6044846a3e11fabe0c9402557052 [formerly 4ffe639c08a784a05d49ff615994bda5f700ec1a]
Former-commit-id: 0db3b23185991ca9f0c0dc7e3f1eff5f4c2f7a77
pull/726/head
parent
013c24733e
commit
3ed5a64cef
|
@ -147,9 +147,9 @@ var (
|
|||
type condition func(path string) bool
|
||||
|
||||
type searchOptions struct {
|
||||
CaseInsensitive bool
|
||||
Conditions []condition
|
||||
Terms []string
|
||||
CaseSensitive bool
|
||||
Conditions []condition
|
||||
Terms []string
|
||||
}
|
||||
|
||||
func extensionCondition(extension string) condition {
|
||||
|
@ -181,9 +181,9 @@ func videoCondition(path string) bool {
|
|||
|
||||
func parseSearch(value string) *searchOptions {
|
||||
opts := &searchOptions{
|
||||
CaseInsensitive: strings.Contains(value, "case:insensitive"),
|
||||
Conditions: []condition{},
|
||||
Terms: []string{},
|
||||
CaseSensitive: strings.Contains(value, "case:sensitive"),
|
||||
Conditions: []condition{},
|
||||
Terms: []string{},
|
||||
}
|
||||
|
||||
// removes the options from the value
|
||||
|
@ -215,7 +215,7 @@ func parseSearch(value string) *searchOptions {
|
|||
}
|
||||
|
||||
// If it's canse insensitive, put everything in lowercase.
|
||||
if opts.CaseInsensitive {
|
||||
if !opts.CaseSensitive {
|
||||
value = strings.ToLower(value)
|
||||
}
|
||||
|
||||
|
@ -276,7 +276,7 @@ func search(c *fb.Context, w http.ResponseWriter, r *http.Request) (int, error)
|
|||
scope = filepath.Clean(scope)
|
||||
|
||||
err = filepath.Walk(scope, func(path string, f os.FileInfo, err error) error {
|
||||
if search.CaseInsensitive {
|
||||
if !search.CaseSensitive {
|
||||
path = strings.ToLower(path)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue