Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search photos by description #94

Open
wants to merge 1 commit into
base: preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/entity/photo_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ var PhotoFixtures = PhotoMap{
TypeSrc: "",
PhotoTitle: "phototobebatchapproved2",
TitleSrc: SrcName,
PhotoDescription: "",
PhotoDescription: "phototobebatchapproved2",
DescriptionSrc: "",
PhotoPath: "2000/12",
PhotoName: "PhotoToBeBatchApproved2",
Expand Down
2 changes: 2 additions & 0 deletions internal/form/search_photos.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type SearchPhotos struct {
Offset int `form:"offset" serialize:"-"` // Result FILE offset
Order string `form:"order" serialize:"-"` // Sort order
Merged bool `form:"merged" serialize:"-"` // Merge FILES in response

Description string `form:"description" example:"description:\"Lake*\"" notes:"Description, OR search with |"`
}

func (f *SearchPhotos) GetQuery() string {
Expand Down
3 changes: 3 additions & 0 deletions internal/form/search_photos_geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ type SearchPhotosGeo struct {
Lens int `form:"lens"`
Count int `form:"count" serialize:"-"`
Offset int `form:"offset" serialize:"-"`

// Additional, non-upstreamed filters.
Description string `form:"description"`
}

// GetQuery returns the query parameter as string.
Expand Down
13 changes: 13 additions & 0 deletions internal/form/search_photos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ func TestParseQueryString(t *testing.T) {

assert.Equal(t, "123abc/,EFG", form.Path)
})
t.Run("description", func(t *testing.T) {
form := &SearchPhotos{Query: "description:123abc"}

err := form.ParseQueryString()

// log.Debugf("%+v\n", form)

if err != nil {
t.Fatal(err)
}

assert.Equal(t, "123abc", form.Description)
})
t.Run("valid query", func(t *testing.T) {
form := &SearchPhotos{Query: "label:cat q:\"fooBar baz\" before:2019-01-15 camera:23 favorite:false dist:25000 lat:33.45343166666667"}

Expand Down
6 changes: 6 additions & 0 deletions internal/search/photos.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,12 @@ func searchPhotos(f form.SearchPhotos, resultCols string) (results PhotoResults,
s = s.Where(where, values...)
}

// Filter by photo description?
if txt.NotEmpty(f.Description) {
where, values := OrLike("photos.photo_description", f.Description)
s = s.Where(where, values...)
}

// Filter by file hash?
if txt.NotEmpty(f.Hash) {
s = s.Where("files.file_hash IN (?)", SplitOr(strings.ToLower(f.Hash)))
Expand Down
6 changes: 6 additions & 0 deletions internal/search/photos_geo.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ func PhotosGeo(f form.SearchPhotosGeo) (results GeoResults, err error) {
s = s.Where(where, values...)
}

// Filter by photo description?
if f.Description != "" {
where, values := OrLike("photos.photo_description", f.Description)
s = s.Where(where, values...)
}

// Filter by status?
if f.Archived {
s = s.Where("photos.photo_quality > -1")
Expand Down
18 changes: 18 additions & 0 deletions internal/search/photos_geo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,24 @@ func TestGeo(t *testing.T) {
assert.NotEmpty(t, r.ID)
}
})
t.Run("f.Description = \"photo*\"", func(t *testing.T) {
var frm form.SearchPhotosGeo

frm.Description = "photo*"

photos, err := PhotosGeo(frm)

if err != nil {
t.Fatal(err)
}

assert.LessOrEqual(t, 1, len(photos))

for _, r := range photos {
assert.IsType(t, GeoResult{}, r)
assert.NotEmpty(t, r.ID)
}
})
t.Run("QueryP", func(t *testing.T) {
var frm form.SearchPhotosGeo
frm.Query = "p"
Expand Down
36 changes: 36 additions & 0 deletions internal/search/photos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,26 @@ func TestPhotos(t *testing.T) {

//t.Logf("results: %+v", photos)
assert.GreaterOrEqual(t, len(photos), 1)
})
t.Run("form.description", func(t *testing.T) {
var f form.SearchPhotos
f.Query = "description:*lake"
f.Count = 10
f.Offset = 0

// Parse query string and filter.
if err := f.ParseQueryString(); err != nil {
t.Fatal(err)
}

photos, _, err := Photos(f)

if err != nil {
t.Fatal(err)
}

//t.Logf("results: %+v", photos)
assert.GreaterOrEqual(t, len(photos), 1)
})
t.Run("form.keywords", func(t *testing.T) {
var f form.SearchPhotos
Expand Down Expand Up @@ -979,6 +998,23 @@ func TestPhotos(t *testing.T) {
}
assert.LessOrEqual(t, 1, len(photos))
})
t.Run("search for description", func(t *testing.T) {
var f form.SearchPhotos
f.Description = "*lake"

// Parse query string and filter.
if err := f.ParseQueryString(); err != nil {
t.Fatal(err)
}

photos, _, err := Photos(f)

if err != nil {
t.Fatal(err)
}

assert.LessOrEqual(t, 1, len(photos))
})
t.Run("search for state", func(t *testing.T) {
var f form.SearchPhotos
f.State = "KwaZulu-Natal"
Expand Down