Skip to content

Implement proper species sorting via label JOIN #1905

@tphakala

Description

@tphakala

Background

Currently, species sorting uses label_id which is an auto-increment integer with no correlation to alphabetical species names. This provides stable grouping but not true alphabetical ordering.

Current State

  • Location: internal/datastore/v2/repository/filter_conversion.go:559
  • species_asc sort uses label_id ordering
  • True alphabetical sorting requires joining with the labels table

Proposed Solution

  1. Modify the detection query to JOIN with labels table when species sorting is requested
  2. Order by labels.scientific_name instead of label_id
  3. Consider performance implications (index on scientific_name may be needed)

Example Query Pattern

SELECT d.* FROM detections d
JOIN labels l ON d.label_id = l.id
WHERE ...
ORDER BY l.scientific_name ASC

Acceptance Criteria

  • Species sorting uses actual species names (scientific_name)
  • Performance is acceptable with index support
  • Both ascending and descending order work correctly
  • Tests for species sorting

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions