Skip to content

Backend: improve Yes/No capabilities - #5191

Merged
lastzero merged 6 commits into
photoprism:developfrom
keif888:YesNoImprovement
Oct 10, 2025
Merged

lastzero merged 6 commits into
photoprism:developfrom
keif888:YesNoImprovement

Conversation

@keif888

@keif888 keif888 commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

Description

These changes improve the way PhotoPrism determines if a Yes or No has been provided in a query string.
It covers Yes and No for the following languages:
Czech, Danish, Dutch, English, French, German, Indonesian, Italian, Polish, Portuguese, Russian, Ukrainian.

Acceptance Criteria

  • New features or enhancements are fully implemented and do not break existing functionality, so that they can be released at any time without requiring additional work
  • Automated unit and/or acceptance tests are included to ensure that changes work as expected and to reduce repetitive manual work

Comment thread pkg/txt/bool.go Outdated
} else if strings.Contains(t, " ") {
result = false
} else {
noStrings := []string{"1", "yes", "include", "true", "positive", "please", "ano", "ja", "oui", "si", "tak", "sim", "Π”Π°", "ya", "Ρ‚Π°ΠΊ"}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should noStrings be yesStrings?

Since these functions are frequently called, we should consider defining this list of strings as a package variable. Then, it won't need to be created in memory each time. Additionally, we could use maps instead of slices for faster lookups:

var yesSet = map[string]struct{}{
  "1": {}, "y": {}, "yes": {}, "true": {}, "include": {}, "positive": {},
  "ano": {}, "ja": {}, "oui": {}, "sΓ­": {}, "si": {}, "tak": {}, "sim": {}, "Π΄Π°": {}, "ya": {}, "Ρ‚Π°ΠΊ": {},
}

var noSet = map[string]struct{}{
  "0": {}, "n": {}, "no": {}, "false": {}, "none": {}, "exclude": {}, "negative": {},
  "ΕΎΓ‘dnΓ½": {}, "nej": {}, "nee": {}, "nein": {}, "non": {}, "nie": {}, "nΓ£o": {}, "Π½Π΅Ρ‚": {}, "tidak": {}, "Π½Ρ–": {},
}

@lastzero

lastzero commented Sep 3, 2025

Copy link
Copy Markdown
Member

How about we call the new package "pkg/enum"? I don't think it's a reserved word in Go and it's much less to type than "constants".

@keif888

keif888 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

How about we call the new package "pkg/enum"? I don't think it's a reserved word in Go and it's much less to type than "constants".

I went with constants as that is what I already used for the SQL constants in #5190.
I can change both to enums if you would prefer that.
I prefer the plural, as the package will contain many enumerated values.

@lastzero

lastzero commented Sep 3, 2025

Copy link
Copy Markdown
Member

In Go, the best practice is to always use singular package names even if a package contains multiple items (most do). This way, it's better readable when you access them e.g. "enum.SQLite" or "enum.YesSet". We can make exceptions when there's a naming conflict, e.g. with a reserved word.

@keif888

keif888 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

OK, I will update both PR's to enum from constants.
I will push them when I have updated and retested.

@keif888

keif888 commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

package constants has been renamed to enum, and code refactored. All unit tests have passed.

@lastzero

lastzero commented Sep 3, 2025

Copy link
Copy Markdown
Member

Thanks a lot! In the meantime, I updated the Best Practices page in our Developer Guide to include Go naming conventions, as well as new sections on Concurrency and Caching:

I'll review and merge your changes as soon as possible! πŸ‘Œ

@lastzero

Copy link
Copy Markdown
Member

Thanks a lot! I'll go ahead and merge this for final testing :)

@lastzero
lastzero merged commit b182222 into photoprism:develop Oct 10, 2025
1 check passed
@lastzero lastzero added please-test Ready for manual testing & feedback merged Changes are merged, but may require further testing labels Oct 10, 2025
@lastzero lastzero moved this to Development 🐝 in Roadmap πŸš€βœ¨ Oct 10, 2025
lastzero added a commit that referenced this pull request Oct 10, 2025
Signed-off-by: Michael Mayer <michael@photoprism.app>
@lastzero

Copy link
Copy Markdown
Member

Our release notes have been updated to mention this improvement:

lastzero added a commit that referenced this pull request Oct 11, 2025
Signed-off-by: Michael Mayer <michael@photoprism.app>
@graciousgrey graciousgrey moved this from Development 🐝 to Preview 🐳 in Roadmap πŸš€βœ¨ Oct 13, 2025
@graciousgrey graciousgrey added tested Changes have been tested successfully and removed please-test Ready for manual testing & feedback labels Oct 13, 2025
@lastzero lastzero moved this from Preview 🐳 to Release 🌈 in Roadmap πŸš€βœ¨ Dec 1, 2025
@keif888
keif888 deleted the YesNoImprovement branch June 9, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged Changes are merged, but may require further testing tested Changes have been tested successfully

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants