2020-01-05 14:18:40 +01:00
|
|
|
package query
|
2018-09-12 16:37:30 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-10-31 07:14:33 +01:00
|
|
|
|
2019-12-11 14:10:20 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2019-05-06 23:18:10 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2019-12-05 19:21:35 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/form"
|
2018-09-12 16:37:30 +02:00
|
|
|
)
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
/*func TestQuery_Photos(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
|
|
|
search := New(conf.OriginalsPath(), conf.Db())
|
|
|
|
|
|
|
|
t.Run("search with query", func(t *testing.T) {
|
|
|
|
query := form.NewPhotoSearch("Title:Reunion")
|
|
|
|
result, err := search.Photos(query)
|
|
|
|
|
|
|
|
t.Log(result)
|
|
|
|
t.Log(err)
|
|
|
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, 2, len(result))
|
|
|
|
assert.Equal(t, "Cake", result[1].PhotoName)
|
|
|
|
assert.Equal(t, "COW", result[0].PhotoName)
|
|
|
|
})
|
|
|
|
}*/
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_PhotoByID(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-02-02 13:03:08 +01:00
|
|
|
|
|
|
|
t.Run("photo found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
result, err := search.PhotoByID(1)
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, 2790, result.PhotoYear)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no photo found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
result, err := search.PhotoByID(99999)
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_PhotoByUUID(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-02-02 13:03:08 +01:00
|
|
|
|
|
|
|
t.Run("photo found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
result, err := search.PhotoByUUID("659")
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "Reunion", result.PhotoTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no photo found", func(t *testing.T) {
|
2020-03-28 15:29:17 +01:00
|
|
|
result, err := search.PhotoByUUID("99999")
|
2020-02-02 13:03:08 +01:00
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-03-28 17:17:41 +01:00
|
|
|
func TestQuery_PreloadPhotoByUUID(t *testing.T) {
|
2020-02-02 13:03:08 +01:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2020-02-02 13:03:08 +01:00
|
|
|
|
|
|
|
t.Run("photo found", func(t *testing.T) {
|
|
|
|
result, err := search.PreloadPhotoByUUID("659")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, "Reunion", result.PhotoTitle)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no photo found", func(t *testing.T) {
|
|
|
|
result, err := search.PreloadPhotoByUUID("99999")
|
|
|
|
assert.Error(t, err, "record not found")
|
|
|
|
t.Log(result)
|
|
|
|
})
|
|
|
|
}
|
2020-03-28 17:17:41 +01:00
|
|
|
|
|
|
|
func TestSearch_Photos(t *testing.T) {
|
2019-07-04 09:52:30 +02:00
|
|
|
conf := config.TestConfig()
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2019-07-04 09:52:30 +02:00
|
|
|
conf.CreateDirectories()
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2020-03-28 15:29:17 +01:00
|
|
|
search := New(conf.Db())
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2019-07-08 17:25:51 +02:00
|
|
|
t.Run("normal query", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "animal"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2019-07-08 17:25:51 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("label query", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "label:dog"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2018-09-12 16:37:30 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-07-08 17:25:51 +02:00
|
|
|
if err != nil {
|
2019-12-11 08:36:14 +01:00
|
|
|
// TODO: Add database fixtures to avoid failing queries
|
|
|
|
t.Logf("query failed: %s", err.Error())
|
2019-07-08 17:25:51 +02:00
|
|
|
}
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("invalid label query", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "label:xxx"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-07-08 17:25:51 +02:00
|
|
|
assert.Equal(t, err.Error(), "label \"xxx\" not found")
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.location true", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = ""
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
|
|
|
f.Location = true
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-07-08 17:25:51 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.camera", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = ""
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
|
|
|
f.Camera = 2
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.color", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = ""
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
|
|
|
f.Color = "blue"
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.favorites", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "favorites:true"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.country", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "country:de"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.title", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "title:Pug Dog"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.hash", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "hash:xxx"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.duplicate", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "duplicate:true"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.portrait", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "portrait:true"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.mono", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "mono:true"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.chroma", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "chroma:50"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
2019-07-08 17:42:06 +02:00
|
|
|
t.Run("form.fmin and Order:oldest", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "Fmin:5 Order:oldest"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
2019-07-08 17:42:06 +02:00
|
|
|
t.Run("form.fmax and Order:newest", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "Fmax:2 Order:newest"
|
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
2019-12-20 20:23:16 +01:00
|
|
|
t.Run("form.Lat and form.Lng and Order:imported", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
2019-12-20 20:23:16 +01:00
|
|
|
f.Query = "Lat:33.45343166666667 Lng:25.764711666666667 Dist:2000 Order:imported"
|
2019-12-05 19:21:35 +01:00
|
|
|
f.Count = 3
|
|
|
|
f.Offset = 0
|
2019-07-08 17:25:51 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2019-07-08 17:25:51 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
|
|
|
t.Run("form.Before and form.After", func(t *testing.T) {
|
2019-12-05 19:21:35 +01:00
|
|
|
var f form.PhotoSearch
|
|
|
|
f.Query = "Before:2005-01-01 After:2003-01-01"
|
|
|
|
f.Count = 5000
|
|
|
|
f.Offset = 0
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-05 19:21:35 +01:00
|
|
|
photos, err := search.Photos(f)
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-07-08 17:25:51 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2019-12-11 08:18:48 +01:00
|
|
|
t.Logf("results: %+v", photos)
|
2019-07-08 17:25:51 +02:00
|
|
|
})
|
2018-09-13 20:54:34 +02:00
|
|
|
|
2018-09-17 18:40:57 +02:00
|
|
|
}
|