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