mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
fix (plg_search_sqlitefts): exclusion field
This commit is contained in:
parent
72cebf4d6d
commit
3d5f307139
3 changed files with 36 additions and 18 deletions
|
|
@ -1,12 +1,15 @@
|
||||||
package plg_search_sqlitefts
|
package plg_search_sqlitefts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
. "github.com/mickael-kerjean/filestash/server/common"
|
. "github.com/mickael-kerjean/filestash/server/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Hooks.Register.Onload(func() {
|
Hooks.Register.Onload(func() {
|
||||||
SEARCH_ENABLE()
|
SEARCH_ENABLE()
|
||||||
|
SEARCH_EXCLUSION()
|
||||||
SEARCH_PROCESS_MAX()
|
SEARCH_PROCESS_MAX()
|
||||||
SEARCH_PROCESS_PAR()
|
SEARCH_PROCESS_PAR()
|
||||||
SEARCH_REINDEX()
|
SEARCH_REINDEX()
|
||||||
|
|
@ -16,11 +19,6 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var INDEXING_EXCLUSION = []string{
|
|
||||||
"/node_modules/", "/bower_components/",
|
|
||||||
"/.cache/", "/.npm/", "/.git/",
|
|
||||||
}
|
|
||||||
|
|
||||||
var SEARCH_ENABLE = func() bool {
|
var SEARCH_ENABLE = func() bool {
|
||||||
return Config.Get("features.search.enable").Schema(func(f *FormElement) *FormElement {
|
return Config.Get("features.search.enable").Schema(func(f *FormElement) *FormElement {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
|
|
@ -30,7 +28,7 @@ var SEARCH_ENABLE = func() bool {
|
||||||
f.Type = "enable"
|
f.Type = "enable"
|
||||||
f.Target = []string{
|
f.Target = []string{
|
||||||
"process_max", "process_par", "reindex_time",
|
"process_max", "process_par", "reindex_time",
|
||||||
"cycle_time", "max_size", "indexer_ext",
|
"cycle_time", "max_size", "indexer_ext", "folder_exclusion",
|
||||||
}
|
}
|
||||||
f.Description = "Enable/Disable full text search"
|
f.Description = "Enable/Disable full text search"
|
||||||
f.Placeholder = "Default: true"
|
f.Placeholder = "Default: true"
|
||||||
|
|
@ -39,6 +37,26 @@ var SEARCH_ENABLE = func() bool {
|
||||||
}).Bool()
|
}).Bool()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SEARCH_EXCLUSION = func() []string {
|
||||||
|
listOfFolders := Config.Get("features.search.folder_exclusion").Schema(func(f *FormElement) *FormElement {
|
||||||
|
if f == nil {
|
||||||
|
f = &FormElement{}
|
||||||
|
}
|
||||||
|
f.Id = "folder_exclusion"
|
||||||
|
f.Name = "folder_exclusion"
|
||||||
|
f.Type = "text"
|
||||||
|
f.Description = "Exclude folders during the exploration phase"
|
||||||
|
f.Placeholder = "Default: node_modules,bower_components,.cache,.npm,.git"
|
||||||
|
f.Default = "node_modules,bower_components,.cache,.npm,.git"
|
||||||
|
return f
|
||||||
|
}).String()
|
||||||
|
out := []string{}
|
||||||
|
for _, folder := range strings.Split(listOfFolders, ",") {
|
||||||
|
out = append(out, strings.TrimSpace(folder))
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
var SEARCH_PROCESS_MAX = func() int {
|
var SEARCH_PROCESS_MAX = func() int {
|
||||||
return Config.Get("features.search.process_max").Schema(func(f *FormElement) *FormElement {
|
return Config.Get("features.search.process_max").Schema(func(f *FormElement) *FormElement {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/mickael-kerjean/filestash/server/common"
|
. "github.com/mickael-kerjean/filestash/server/common"
|
||||||
|
|
@ -23,6 +24,7 @@ func (this *Crawler) Discover(tx indexer.Manager) bool {
|
||||||
this.CurrentPhase = PHASE_INDEXING
|
this.CurrentPhase = PHASE_INDEXING
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := this.Backend.Ls(doc.Path)
|
files, err := this.Backend.Ls(doc.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.CurrentPhase = ""
|
this.CurrentPhase = ""
|
||||||
|
|
@ -58,9 +60,19 @@ func (this *Crawler) Discover(tx indexer.Manager) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the newly found data within our index
|
// Insert the newly found data within our index
|
||||||
|
excluded := SEARCH_EXCLUSION()
|
||||||
for i := range files {
|
for i := range files {
|
||||||
f := files[i]
|
f := files[i]
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
|
skip := false
|
||||||
|
for i := 0; i < len(excluded); i++ {
|
||||||
|
if name == excluded[i] || strings.Contains(doc.Path, excluded[i]) {
|
||||||
|
skip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if skip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
var performPush bool = false
|
var performPush bool = false
|
||||||
p := filepath.Join(doc.Path, name)
|
p := filepath.Join(doc.Path, name)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/mickael-kerjean/filestash/server/common"
|
. "github.com/mickael-kerjean/filestash/server/common"
|
||||||
|
|
@ -16,11 +15,6 @@ func updateFile(path string, backend IBackend, tx indexer.Manager) error {
|
||||||
if err := tx.IndexTimeUpdate(path, time.Now()); err != nil {
|
if err := tx.IndexTimeUpdate(path, time.Now()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < len(INDEXING_EXCLUSION); i++ {
|
|
||||||
if strings.Contains(path, INDEXING_EXCLUSION[i]) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reader, err := backend.Cat(path)
|
reader, err := backend.Cat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.RemoveAll(path)
|
tx.RemoveAll(path)
|
||||||
|
|
@ -44,12 +38,6 @@ func updateFolder(path string, backend IBackend, tx indexer.Manager) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(INDEXING_EXCLUSION); i++ {
|
|
||||||
if strings.Contains(path, INDEXING_EXCLUSION[i]) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch list of folders as in the remote filesystem
|
// Fetch list of folders as in the remote filesystem
|
||||||
currFiles, err := backend.Ls(path)
|
currFiles, err := backend.Ls(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue