Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.1] - 2025-10-28
### Fixed
- Fix sorting order of results. Now sorting by `Order` field in ascending order, instead of `PathId`.

## [0.7.0] - 2025-10-24
## Changed
- Update qdrant's docker compose file name
Expand Down Expand Up @@ -46,3 +50,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.5.0]: https://github.com/scanoss/folder-hashing-api/compare/v0.4.2...v0.5.0
[0.6.0]: https://github.com/scanoss/folder-hashing-api/compare/v0.5.0...v0.6.0
[0.7.0]: https://github.com/scanoss/folder-hashing-api/compare/v0.6.0...v0.7.0
[0.7.1]: https://github.com/scanoss/folder-hashing-api/compare/v0.7.0...v0.7.1
21 changes: 18 additions & 3 deletions internal/service/scan_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package service

import (
"context"
"math"
"sort"

"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
Expand Down Expand Up @@ -221,9 +222,23 @@ func (s *ScanServiceImpl) deduplicateComponents(results []*entities.ScanResult)
}
}

sort.Slice(deduplicatedResults, func(i, j int) bool {
return deduplicatedResults[i].PathID < deduplicatedResults[j].PathID
})
sortByBestComponentOrder(deduplicatedResults)

return deduplicatedResults
}

// sortByBestComponentOrder sorts the results by the lowest order of the component groups (lower order is better).
func sortByBestComponentOrder(results []*entities.ScanResult) {
sort.SliceStable(results, func(i, j int) bool {
minOrderI := int32(math.MaxInt32)
for _, group := range results[i].ComponentGroups {
minOrderI = min(minOrderI, group.Order)
}

minOrderJ := int32(math.MaxInt32)
for _, group := range results[j].ComponentGroups {
minOrderJ = min(minOrderJ, group.Order)
}
return minOrderI < minOrderJ
})
}
Loading
Loading