Skip to content

Commit

Permalink
feat: improve species inclusion logic in RangeFilter
Browse files Browse the repository at this point in the history
- Updated the IsSpeciesIncluded function to check for scientific names, enhancing accuracy in species filtering.
- Added a prefix search mechanism to prevent partial matches by appending an underscore to the scientific name.
- Improved code readability and maintainability with clearer function documentation.
  • Loading branch information
tphakala committed Dec 19, 2024
1 parent a34a1da commit ad4cb9e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/conf/range_filter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package conf

import (
"strings"
"sync"
"time"
)
Expand All @@ -27,12 +28,17 @@ func (s *Settings) GetIncludedSpecies() []string {
return speciesCopy
}

// IsSpeciesIncluded checks if a given species is in the included list of the RangeFilter
func (s *Settings) IsSpeciesIncluded(species string) bool {
// IsSpeciesIncluded checks if a given scientific name matches the scientific name part of any included species
func (s *Settings) IsSpeciesIncluded(scientificName string) bool {
speciesListMutex.RLock()
defer speciesListMutex.RUnlock()
for _, s := range s.BirdNET.RangeFilter.Species {
if s == species {

// Add underscore to the scientific name to prevent partial matches
searchTerm := scientificName + "_"

for _, fullSpeciesString := range s.BirdNET.RangeFilter.Species {
// Check if the full species string starts with our search term
if strings.HasPrefix(fullSpeciesString, searchTerm) {
return true
}
}
Expand Down

0 comments on commit ad4cb9e

Please sign in to comment.