Skip to content

Commit

Permalink
feat: Search scene on filename & path (xbapps#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
toshski authored Apr 2, 2024
1 parent c033891 commit 8d7855f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/api/scenes.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,31 @@ func (i SceneResource) searchSceneIndex(req *restful.Request, resp *restful.Resp
}
}

// if searching for a path/filename
lastslash := strings.LastIndex(q, "\\")
path := ""
filename := q
if lastslash > -1 {
path = strings.ReplaceAll(q[:lastslash], "\\", "_") // change backslash to _, backslash doesn't seem to work with SQL Like, replace with _ (single character)
filename = q[lastslash+1:]
}

var fileScenes []models.File
if path != "" {
db.Where("path like ? and filename like ? and scene_id > 0", "%"+path+"%", "%"+filename+"%").Find(&fileScenes)
} else {
db.Where("filename like ? and scene_id > 0", "%"+filename+"%").Find(&fileScenes)
}

for _, file := range fileScenes {
var scene models.Scene
scene.GetIfExistByPK(file.SceneID)
if scene.ID != 0 {
scenes = append(scenes, scene)
}
}

// search bleve search indexes
idx, err := tasks.NewIndex("scenes")
if err != nil {
log.Error(err)
Expand Down

0 comments on commit 8d7855f

Please sign in to comment.