mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Search: Allow searching for labels that only have an emoji as name #4761
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -257,44 +257,54 @@ func TestLikeAllNames(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAnySlug(t *testing.T) {
|
||||
t.Run("table spoon usa img json", func(t *testing.T) {
|
||||
t.Run("Multiple", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "table spoon usa img json", " ")
|
||||
assert.Equal(t, "custom_slug = 'table' OR custom_slug = 'spoon' OR custom_slug = 'usa' OR custom_slug = 'img' OR custom_slug = 'json'", where)
|
||||
})
|
||||
|
||||
t.Run("cat dog", func(t *testing.T) {
|
||||
t.Run("CatDog", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "cat dog", " ")
|
||||
assert.Equal(t, "custom_slug = 'cat' OR custom_slug = 'dog'", where)
|
||||
})
|
||||
|
||||
t.Run("cats dogs", func(t *testing.T) {
|
||||
t.Run("CatsDogs", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "cats dogs", " ")
|
||||
assert.Equal(t, "custom_slug = 'cats' OR custom_slug = 'cat' OR custom_slug = 'dogs' OR custom_slug = 'dog'", where)
|
||||
})
|
||||
|
||||
t.Run("spoon", func(t *testing.T) {
|
||||
t.Run("Spoon", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "spoon", " ")
|
||||
assert.Equal(t, "custom_slug = 'spoon'", where)
|
||||
})
|
||||
|
||||
t.Run("img", func(t *testing.T) {
|
||||
t.Run("Img", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "img", " ")
|
||||
assert.Equal(t, "custom_slug = 'img'", where)
|
||||
})
|
||||
|
||||
t.Run("Space", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", " ", "")
|
||||
assert.Equal(t, "custom_slug = '' OR custom_slug = ''", where)
|
||||
})
|
||||
|
||||
t.Run("Empty", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "", " ")
|
||||
assert.Equal(t, "", where)
|
||||
})
|
||||
|
||||
t.Run("comma separated", func(t *testing.T) {
|
||||
t.Run("CommaSeparated", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "botanical-garden|landscape|bay", txt.Or)
|
||||
assert.Equal(t, "custom_slug = 'botanical-garden' OR custom_slug = 'landscape' OR custom_slug = 'bay'", where)
|
||||
})
|
||||
|
||||
t.Run("len = 0", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", " ", "")
|
||||
assert.Equal(t, "custom_slug = '' OR custom_slug = ''", where)
|
||||
t.Run("Emoji", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "💐", "|")
|
||||
assert.Equal(t, "custom_slug = '_5cpzfea'", where)
|
||||
})
|
||||
|
||||
t.Run("EmojiSlug", func(t *testing.T) {
|
||||
where := AnySlug("custom_slug", "_5cpzfea", "|")
|
||||
assert.Equal(t, "custom_slug = '_5cpzfea'", where)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,17 @@ func ContainsASCIILetters(s string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ContainsAlnumLower reports if the string only contains lower case ascii letters or numbers.
|
||||
func ContainsAlnumLower(s string) bool {
|
||||
for _, r := range s {
|
||||
if (r < 48 || r > 57) && (r < 97 || r > 122) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// ContainsSymbols reports whether the string only contains symbolic characters.
|
||||
func ContainsSymbols(s string) bool {
|
||||
if s == "" {
|
||||
|
||||
@@ -95,3 +95,19 @@ func TestContainsASCIILetters(t *testing.T) {
|
||||
assert.False(t, ContainsASCIILetters("réseau"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestContainsAlnumLower(t *testing.T) {
|
||||
t.Run("True", func(t *testing.T) {
|
||||
assert.True(t, ContainsAlnumLower(""))
|
||||
assert.True(t, ContainsAlnumLower("a"))
|
||||
assert.True(t, ContainsAlnumLower("3kmib24yr3"))
|
||||
assert.True(t, ContainsAlnumLower("123"))
|
||||
})
|
||||
t.Run("False", func(t *testing.T) {
|
||||
assert.False(t, ContainsAlnumLower("-"))
|
||||
assert.False(t, ContainsAlnumLower(" "))
|
||||
assert.False(t, ContainsAlnumLower("B"))
|
||||
assert.False(t, ContainsAlnumLower("3Km"))
|
||||
assert.False(t, ContainsAlnumLower("_3kmib24yr3"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,8 +16,12 @@ var SlugEncoding = base32.NewEncoding(SlugCharset).WithPadding(base32.NoPadding)
|
||||
func Slug(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
if s == "" {
|
||||
return ""
|
||||
if s == "" || s == "-" {
|
||||
return s
|
||||
}
|
||||
|
||||
if s[0] == SlugEncoded && ContainsAlnumLower(s[1:]) {
|
||||
return Clip(s, ClipSlug)
|
||||
}
|
||||
|
||||
result := slug.Make(s)
|
||||
|
||||
@@ -25,6 +25,12 @@ func TestSlug(t *testing.T) {
|
||||
assert.Equal(t, "_5cpzfea", Slug(" 💐 "))
|
||||
assert.Equal(t, "_5cpzfdxqt5jja", Slug("💎💐"))
|
||||
assert.Equal(t, "photoprism", Slug("PhotoPrism 💎"))
|
||||
assert.Equal(t, "_3kmib24yr3", Slug("_3kmib24yr3"))
|
||||
assert.Equal(t, "-", Slug("-"))
|
||||
assert.Equal(t, "_", Slug("_"))
|
||||
assert.Equal(t, "_a", Slug("_a"))
|
||||
assert.Equal(t, "_5cpzfea", Slug("_5cpzfea"))
|
||||
assert.Equal(t, "_5cpzfdxqt5jja", Slug("_5cpzfdxqt5jja"))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user