2019-12-05 19:21:35 +01:00
|
|
|
package form
|
2019-05-03 18:57:28 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-05-15 23:07:25 +02:00
|
|
|
"time"
|
2019-05-03 18:57:28 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-06-29 18:35:02 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2019-05-03 18:57:28 +02:00
|
|
|
)
|
|
|
|
|
2022-09-30 19:15:10 +02:00
|
|
|
func TestSearchPhotosForm(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{}
|
2019-05-03 18:57:28 +02:00
|
|
|
|
2021-11-26 13:59:10 +01:00
|
|
|
assert.IsType(t, new(SearchPhotos), form)
|
2019-05-03 18:57:28 +02:00
|
|
|
}
|
2019-05-15 21:51:00 +02:00
|
|
|
|
|
|
|
func TestParseQueryString(t *testing.T) {
|
2021-08-29 16:16:49 +02:00
|
|
|
t.Run("subjects", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "subjects:\"Jens & Mander\""}
|
2021-08-29 16:16:49 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Jens & Mander", form.Subjects)
|
|
|
|
})
|
2023-06-28 16:07:06 +02:00
|
|
|
t.Run("subject", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "subject:\"Jens\""}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Jens", form.Subject)
|
|
|
|
assert.Equal(t, "", form.Person)
|
|
|
|
})
|
2021-09-20 12:36:59 +02:00
|
|
|
t.Run("aliases", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "people:\"Jens & Mander\" folder:Foo person:Bar"}
|
2021-09-20 12:36:59 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "", form.Folder)
|
|
|
|
assert.Equal(t, "", form.Person)
|
|
|
|
assert.Equal(t, "", form.People)
|
|
|
|
assert.Equal(t, "Foo", form.Path)
|
|
|
|
assert.Equal(t, "Bar", form.Subject)
|
|
|
|
assert.Equal(t, "Jens & Mander", form.Subjects)
|
|
|
|
})
|
2021-08-29 16:16:49 +02:00
|
|
|
t.Run("keywords", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "keywords:\"Foo Bar\""}
|
2021-08-29 16:16:49 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "Foo Bar", form.Keywords)
|
|
|
|
})
|
|
|
|
t.Run("and query", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "\"Jens & Mander\" title:\"Tübingen\""}
|
2021-08-29 16:16:49 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.Equal(t, "jens & mander", form.GetQuery())
|
|
|
|
assert.Equal(t, "Tübingen", form.Title)
|
|
|
|
})
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Run("path", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "path:123abc/,EFG"}
|
2019-05-15 21:51:00 +02:00
|
|
|
|
2020-05-21 16:46:22 +02:00
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-05-21 16:46:22 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "123abc/,EFG", form.Path)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("folder", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "folder:123abc/,EFG"}
|
2020-05-21 16:46:22 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-05-21 16:46:22 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "123abc/,EFG", form.Path)
|
|
|
|
})
|
2019-07-16 11:17:33 +02:00
|
|
|
t.Run("valid query", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
form := &SearchPhotos{Query: "label:cat q:\"fooBar baz\" before:2019-01-15 camera:23 favorite:false dist:25000 lat:33.45343166666667"}
|
2019-05-15 21:51:00 +02:00
|
|
|
|
2019-07-16 10:41:30 +02:00
|
|
|
err := form.ParseQueryString()
|
2019-05-15 21:51:00 +02:00
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-07-16 10:41:30 +02:00
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err != nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2019-07-16 10:41:30 +02:00
|
|
|
assert.Equal(t, "cat", form.Label)
|
2020-05-21 10:03:56 +02:00
|
|
|
assert.Equal(t, "fooBar baz", form.Query)
|
2022-03-24 18:30:59 +01:00
|
|
|
assert.Equal(t, "23", form.Camera)
|
2019-07-16 10:41:30 +02:00
|
|
|
assert.Equal(t, time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC), form.Before)
|
2020-05-14 19:03:12 +02:00
|
|
|
assert.Equal(t, false, form.Favorite)
|
2019-07-16 10:41:30 +02:00
|
|
|
assert.Equal(t, uint(0x61a8), form.Dist)
|
2020-04-26 11:41:54 +02:00
|
|
|
assert.Equal(t, float32(33.45343), form.Lat)
|
2019-07-16 10:41:30 +02:00
|
|
|
})
|
2019-07-16 11:17:33 +02:00
|
|
|
t.Run("valid query 2", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "chroma:200 title:\"te:st\" after:2018-01-15 favorite:true lng:33.45343166666667"}
|
2019-07-16 11:17:33 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-07-16 11:17:33 +02:00
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("err should be nil")
|
|
|
|
}
|
|
|
|
|
2022-06-16 06:30:59 +02:00
|
|
|
assert.Equal(t, int16(200), form.Chroma)
|
2020-12-14 09:21:29 +01:00
|
|
|
assert.Equal(t, "te:st", form.Title)
|
2019-07-16 11:17:33 +02:00
|
|
|
assert.Equal(t, time.Date(2018, 01, 15, 0, 0, 0, 0, time.UTC), form.After)
|
2020-04-26 11:41:54 +02:00
|
|
|
assert.Equal(t, float32(33.45343), form.Lng)
|
2019-07-16 11:17:33 +02:00
|
|
|
})
|
2020-07-08 08:36:10 +02:00
|
|
|
t.Run("valid query with filter", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "label:cat title:\"fooBar baz\"", Filter: "label:dog"}
|
2020-07-08 08:36:10 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2020-07-08 08:36:10 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "dog", form.Label)
|
|
|
|
assert.Equal(t, "label:dog", form.Filter)
|
|
|
|
assert.Equal(t, "fooBar baz", form.Title)
|
|
|
|
})
|
2019-12-15 13:23:45 +01:00
|
|
|
t.Run("valid query with umlauts", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "title:\"tübingen\""}
|
2019-12-15 13:23:45 +01:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-12-15 13:23:45 +01:00
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err != nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 09:41:33 +01:00
|
|
|
assert.Equal(t, "tübingen", form.Title)
|
2019-12-15 13:23:45 +01:00
|
|
|
})
|
2019-07-16 10:41:30 +02:00
|
|
|
t.Run("query for invalid filter", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "xxx:false"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err == nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-07-16 10:41:30 +02:00
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Equal(t, "unknown filter: xxx", err.Error())
|
2019-07-16 10:41:30 +02:00
|
|
|
})
|
2020-01-31 15:29:06 +01:00
|
|
|
t.Run("query for favorites with uncommon bool value", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "favorite:cat"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err != nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
2020-05-14 19:03:12 +02:00
|
|
|
assert.True(t, form.Favorite)
|
2019-07-16 10:41:30 +02:00
|
|
|
})
|
2022-03-29 14:45:54 +02:00
|
|
|
t.Run("query for primary with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "primary:&cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Primary)
|
|
|
|
})
|
|
|
|
t.Run("query for stack with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "stack:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Stack)
|
|
|
|
})
|
|
|
|
t.Run("query for unstacked with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "unstacked:'cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Unstacked)
|
|
|
|
})
|
|
|
|
t.Run("query for stackable with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "stackable:mother's day"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Stackable)
|
|
|
|
})
|
|
|
|
t.Run("query for video with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "video:|cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Video)
|
|
|
|
})
|
2022-04-14 08:39:52 +02:00
|
|
|
t.Run("AnimatedYes", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "animated:yes"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.False(t, form.Vector)
|
|
|
|
assert.True(t, form.Animated)
|
|
|
|
})
|
|
|
|
t.Run("VectorYes", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "vector:yes"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
assert.False(t, form.Animated)
|
|
|
|
assert.True(t, form.Vector)
|
|
|
|
})
|
2022-03-29 14:45:54 +02:00
|
|
|
t.Run("query for photo with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "photo:cat>"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Photo)
|
|
|
|
})
|
|
|
|
t.Run("query for raw with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "raw:ca+(t"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Raw)
|
|
|
|
})
|
|
|
|
t.Run("query for live with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "live:cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Live)
|
|
|
|
})
|
|
|
|
t.Run("query for scan with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "scan:;cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Scan)
|
|
|
|
})
|
|
|
|
t.Run("query for panorama with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "panorama:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Panorama)
|
|
|
|
})
|
|
|
|
t.Run("query for error with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "error:^cat$#"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Error)
|
|
|
|
})
|
|
|
|
t.Run("query for hidden with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "hidden:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Hidden)
|
|
|
|
})
|
|
|
|
t.Run("query for archived with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "archived:`cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Archived)
|
|
|
|
})
|
|
|
|
t.Run("query for public with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "public:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Public)
|
|
|
|
})
|
|
|
|
t.Run("query for private with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "private:*c@t"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Private)
|
|
|
|
})
|
|
|
|
t.Run("query for unsorted with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "unsorted:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Unsorted)
|
|
|
|
})
|
|
|
|
t.Run("query for mono with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "mono:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Mono)
|
|
|
|
})
|
|
|
|
t.Run("query for portrait with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "portrait:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Portrait)
|
|
|
|
})
|
2022-04-13 09:48:51 +02:00
|
|
|
t.Run("PortraitLandscapeSquare", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "portrait:true landscape:yes square:jo"}
|
|
|
|
|
|
|
|
assert.False(t, form.Portrait)
|
|
|
|
assert.False(t, form.Landscape)
|
|
|
|
assert.False(t, form.Square)
|
|
|
|
assert.False(t, form.Panorama)
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Portrait)
|
|
|
|
assert.True(t, form.Landscape)
|
|
|
|
assert.True(t, form.Square)
|
|
|
|
assert.False(t, form.Panorama)
|
|
|
|
})
|
2022-03-29 14:45:54 +02:00
|
|
|
t.Run("query for geo with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "geo:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-06-29 18:35:02 +02:00
|
|
|
assert.Equal(t, "*cat", form.Geo)
|
|
|
|
assert.False(t, txt.No(form.Geo))
|
2022-03-29 14:45:54 +02:00
|
|
|
})
|
|
|
|
t.Run("query for review with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "review:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Review)
|
|
|
|
})
|
|
|
|
t.Run("query for merged with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "merged:*cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Error(t, err)
|
2022-03-29 14:45:54 +02:00
|
|
|
})
|
2022-04-20 14:49:18 +02:00
|
|
|
t.Run("query for landscape with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "landscape:test$5123"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Landscape)
|
|
|
|
})
|
|
|
|
t.Run("query for square with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "square:%abc"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Square)
|
|
|
|
})
|
|
|
|
t.Run("query for animated with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "animated:%abc"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Animated)
|
|
|
|
})
|
|
|
|
t.Run("query for vector with uncommon bool value", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "vector:%abc"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.True(t, form.Vector)
|
|
|
|
})
|
2019-07-16 10:41:30 +02:00
|
|
|
t.Run("query for lat with invalid type", func(t *testing.T) {
|
2022-03-30 18:21:43 +02:00
|
|
|
form := &SearchPhotos{Query: "lat:&cat"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err == nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-07-16 10:41:30 +02:00
|
|
|
|
2022-03-30 18:21:43 +02:00
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for lng with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "lng:^>cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
2019-07-16 10:41:30 +02:00
|
|
|
})
|
|
|
|
t.Run("query for dist with invalid type", func(t *testing.T) {
|
2022-03-30 18:21:43 +02:00
|
|
|
form := &SearchPhotos{Query: "dist:c@t"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for fmin with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "fmin:=}cat{"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for fmax with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "fmax:ca#$t"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for chroma with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "chroma:&|cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for diff with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "diff:&cat;%"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err == nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-07-16 10:41:30 +02:00
|
|
|
|
2022-03-30 18:21:43 +02:00
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for quality with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "quality:`cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
|
|
|
})
|
|
|
|
t.Run("query for count with invalid type", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
form := &SearchPhotos{Query: "dist:ca(%t"}
|
2022-03-30 18:21:43 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2022-08-01 15:57:19 +02:00
|
|
|
assert.Error(t, err)
|
2022-03-30 18:21:43 +02:00
|
|
|
})
|
|
|
|
t.Run("query for offset with invalid type", func(t *testing.T) {
|
2022-08-01 15:57:19 +02:00
|
|
|
form := &SearchPhotos{Query: "lat:&cat"}
|
2022-03-30 18:21:43 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Contains(t, err.Error(), "invalid syntax")
|
2019-07-16 10:41:30 +02:00
|
|
|
})
|
2022-03-24 18:30:59 +01:00
|
|
|
t.Run("CameraString", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "camera:cat"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2022-03-24 18:30:59 +01:00
|
|
|
if err != nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 18:30:59 +01:00
|
|
|
assert.Equal(t, "cat", form.Camera)
|
|
|
|
})
|
|
|
|
t.Run("LensString", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "lens:cat"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
2022-03-24 18:30:59 +01:00
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "cat", form.Lens)
|
2019-07-16 10:41:30 +02:00
|
|
|
})
|
|
|
|
t.Run("query for before with invalid type", func(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := &SearchPhotos{Query: "before:cat"}
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
if err == nil {
|
2022-03-30 18:21:43 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// log.Debugf("%+v\n", form)
|
|
|
|
|
|
|
|
assert.Equal(t, "Could not find format for \"cat\"", err.Error())
|
|
|
|
})
|
|
|
|
t.Run("query for after with invalid type", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "after:cat"}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err == nil {
|
2020-05-21 16:46:22 +02:00
|
|
|
t.Fatal(err)
|
2020-01-31 15:29:06 +01:00
|
|
|
}
|
|
|
|
|
2021-08-29 16:16:49 +02:00
|
|
|
// log.Debugf("%+v\n", form)
|
2019-07-16 10:41:30 +02:00
|
|
|
|
|
|
|
assert.Equal(t, "Could not find format for \"cat\"", err.Error())
|
|
|
|
})
|
2023-02-14 19:14:03 +01:00
|
|
|
t.Run("id", func(t *testing.T) {
|
|
|
|
form := &SearchPhotos{Query: "id:\"ii3e4567-e89b-hdgtr\""}
|
|
|
|
|
|
|
|
err := form.ParseQueryString()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, "ii3e4567-e89b-hdgtr", form.ID)
|
|
|
|
})
|
2019-05-15 21:51:00 +02:00
|
|
|
}
|
2020-05-06 17:05:06 +02:00
|
|
|
|
2022-09-30 19:15:10 +02:00
|
|
|
func TestNewSearchPhotos(t *testing.T) {
|
|
|
|
r := NewSearchPhotos("cat")
|
2021-11-26 13:59:10 +01:00
|
|
|
assert.IsType(t, SearchPhotos{}, r)
|
2020-05-06 17:05:06 +02:00
|
|
|
}
|
2020-05-23 20:58:58 +02:00
|
|
|
|
2022-09-30 19:15:10 +02:00
|
|
|
func TestSearchPhotos_Serialize(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := SearchPhotos{
|
2020-05-23 20:58:58 +02:00
|
|
|
Query: "foo BAR",
|
|
|
|
Private: true,
|
|
|
|
Photo: false,
|
|
|
|
Lat: 1.5,
|
|
|
|
Lng: -10.33333,
|
2021-09-20 23:32:35 +02:00
|
|
|
Year: "2002",
|
2020-05-23 20:58:58 +02:00
|
|
|
Chroma: 1,
|
|
|
|
Diff: 424242,
|
|
|
|
Before: time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
result := form.Serialize()
|
|
|
|
|
|
|
|
t.Logf("SERIALIZED: %s", result)
|
|
|
|
|
|
|
|
assert.IsType(t, "string", result)
|
|
|
|
}
|
2020-07-08 08:36:10 +02:00
|
|
|
|
2022-09-30 19:15:10 +02:00
|
|
|
func TestSearchPhotos_SerializeAll(t *testing.T) {
|
2021-11-26 13:59:10 +01:00
|
|
|
form := SearchPhotos{
|
2020-07-08 08:36:10 +02:00
|
|
|
Query: "foo BAR",
|
|
|
|
Private: true,
|
|
|
|
Photo: false,
|
|
|
|
Lat: 1.5,
|
|
|
|
Lng: -10.33333,
|
2021-09-20 23:32:35 +02:00
|
|
|
Year: "2002|2003",
|
2020-07-08 08:36:10 +02:00
|
|
|
Chroma: 1,
|
|
|
|
Diff: 424242,
|
|
|
|
Before: time.Date(2019, 01, 15, 0, 0, 0, 0, time.UTC),
|
|
|
|
}
|
|
|
|
|
|
|
|
result := form.SerializeAll()
|
|
|
|
|
|
|
|
t.Logf("SERIALIZED: %s", result)
|
|
|
|
|
|
|
|
assert.IsType(t, "string", result)
|
|
|
|
}
|
2022-09-30 19:15:10 +02:00
|
|
|
|
|
|
|
func TestSearchPhotos_Filter(t *testing.T) {
|
|
|
|
t.Run("WithScope", func(t *testing.T) {
|
|
|
|
f := &SearchPhotos{Query: "album:cat filter:\"name:foo.jpg\" s:ariqwb43p5dh9h13 search-string", Scope: "ariqwb43p5dh2244", Filter: "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777"}
|
|
|
|
|
|
|
|
err := f.ParseQueryString()
|
|
|
|
|
|
|
|
t.Logf("WithScope: %+v\n", f)
|
|
|
|
|
|
|
|
assert.ErrorContains(t, err, "unknown filter: s")
|
|
|
|
assert.Equal(t, "search-string", f.Query)
|
|
|
|
assert.Equal(t, "ariqwb43p5dh2244", f.Scope)
|
|
|
|
assert.Equal(t, "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777", f.Filter)
|
|
|
|
assert.Equal(t, "", f.Name)
|
|
|
|
assert.Equal(t, "", f.UID)
|
|
|
|
assert.Equal(t, "cat", f.Album)
|
|
|
|
})
|
|
|
|
t.Run("ScopeInQuery", func(t *testing.T) {
|
|
|
|
f := &SearchPhotos{Query: "album:cat filter:\"name:foo.jpg\" s:ariqwb43p5dh9h13 search-string", Filter: "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777"}
|
|
|
|
|
|
|
|
err := f.ParseQueryString()
|
|
|
|
|
|
|
|
t.Logf("ScopeInQuery: %+v\n", f)
|
|
|
|
|
|
|
|
assert.ErrorContains(t, err, "unknown filter: s")
|
|
|
|
assert.Equal(t, "search-string", f.Query)
|
|
|
|
assert.Equal(t, "", f.Scope)
|
|
|
|
assert.Equal(t, "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777", f.Filter)
|
|
|
|
assert.Equal(t, "", f.Name)
|
|
|
|
assert.Equal(t, "", f.UID)
|
|
|
|
assert.Equal(t, "cat", f.Album)
|
|
|
|
})
|
|
|
|
t.Run("NoScope", func(t *testing.T) {
|
|
|
|
f := &SearchPhotos{Query: "album:cat search-string", Filter: "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777"}
|
|
|
|
|
|
|
|
err := f.ParseQueryString()
|
|
|
|
|
|
|
|
t.Logf("ScopeInQuery: %+v\n", f)
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "foo", f.Query)
|
|
|
|
assert.Equal(t, "", f.Scope)
|
|
|
|
assert.Equal(t, "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777", f.Filter)
|
|
|
|
assert.Equal(t, "foo", f.Name)
|
|
|
|
assert.Equal(t, "priqwb43p5dh7777", f.UID)
|
|
|
|
assert.Equal(t, "ariqwb43p5dh5555", f.Album)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSearchPhotos_Unserialize(t *testing.T) {
|
|
|
|
t.Run("Filter", func(t *testing.T) {
|
|
|
|
f := &SearchPhotos{Query: "bar album:ariqwb43p5dh9999 uid:priqwb43p5dh4321 albums:baz s:ariqwb43p5dh1122 search-string", Scope: "ariqwb43p5dh2244"}
|
|
|
|
|
|
|
|
if err := Unserialize(f, "name:foo.jpg album:ariqwb43p5dh5555 q:foo uid:priqwb43p5dh7777"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("UnserializeFilter: %+v\n", f)
|
|
|
|
|
|
|
|
assert.Equal(t, "foo", f.Query)
|
|
|
|
assert.Equal(t, "ariqwb43p5dh2244", f.Scope)
|
|
|
|
assert.Equal(t, "", f.Filter)
|
|
|
|
assert.Equal(t, "foo.jpg", f.Name)
|
|
|
|
assert.Equal(t, "priqwb43p5dh7777", f.UID)
|
|
|
|
assert.Equal(t, "ariqwb43p5dh5555", f.Album)
|
|
|
|
})
|
|
|
|
}
|
2023-06-28 16:07:06 +02:00
|
|
|
|
|
|
|
func TestSearchPhotos_FindUidOnly(t *testing.T) {
|
|
|
|
t.Run("true", func(t *testing.T) {
|
|
|
|
f := &SearchPhotos{UID: "priqwb43p5dh7777"}
|
|
|
|
|
|
|
|
assert.True(t, f.FindUidOnly())
|
|
|
|
})
|
|
|
|
t.Run("false", func(t *testing.T) {
|
|
|
|
f := &SearchPhotos{Query: "label:cat", UID: "priqwb43p5dh7777"}
|
|
|
|
|
|
|
|
assert.False(t, f.FindUidOnly())
|
|
|
|
})
|
|
|
|
}
|