Add deduplication and normalization for tender recommendations
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced a new function `dedupeRecommendationResponsesByTenderID` to remove duplicate tender recommendations based on their IDs, ensuring unique entries in the recommendation list. - Updated the `mergeRecommendedTenders` function to utilize the new deduplication logic, streamlining the merging process of recommendation lists. - Enhanced the `fetchAIRecommendations` method to apply deduplication on the fetched recommendations, improving data integrity. - Added unit tests for the new deduplication function to validate its behavior and ensure correct handling of various input scenarios. This update enhances the recommendation handling by ensuring that duplicate tender entries are effectively managed, improving the overall quality of the recommendations provided to users.
This commit is contained in:
@@ -44,23 +44,10 @@ func normalizeRecommendationCompanyIDs(companyIDs []string) []string {
|
||||
|
||||
func mergeRecommendedTenders(recommendationLists ...[]RecommendedTenderResponse) []RecommendedTenderResponse {
|
||||
merged := make([]RecommendedTenderResponse, 0)
|
||||
seen := make(map[string]struct{})
|
||||
for _, recommendations := range recommendationLists {
|
||||
for _, recommendation := range recommendations {
|
||||
tenderID := strings.TrimSpace(recommendation.TenderID)
|
||||
if tenderID == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[tenderID]; ok {
|
||||
continue
|
||||
}
|
||||
seen[tenderID] = struct{}{}
|
||||
recommendation.TenderID = tenderID
|
||||
recommendation.Analysis = strings.TrimSpace(recommendation.Analysis)
|
||||
merged = append(merged, recommendation)
|
||||
}
|
||||
merged = append(merged, recommendations...)
|
||||
}
|
||||
return merged
|
||||
return dedupeRecommendationResponsesByTenderID(merged)
|
||||
}
|
||||
|
||||
func aiRecommendationCacheKey(companyID string) string {
|
||||
@@ -382,6 +369,10 @@ func (s *companyService) fetchAIRecommendations(ctx context.Context, companyID s
|
||||
return nil, fmt.Errorf("failed to fetch AI recommendations: %w", err)
|
||||
}
|
||||
|
||||
return dedupeRecommendationResponsesByTenderID(itemsToRecommendationResponses(items)), nil
|
||||
}
|
||||
|
||||
func itemsToRecommendationResponses(items []ai_summarizer.RecommendedTender) []RecommendedTenderResponse {
|
||||
responses := make([]RecommendedTenderResponse, 0, len(items))
|
||||
for _, item := range items {
|
||||
responses = append(responses, RecommendedTenderResponse{
|
||||
@@ -390,8 +381,26 @@ func (s *companyService) fetchAIRecommendations(ctx context.Context, companyID s
|
||||
Analysis: item.Analysis,
|
||||
})
|
||||
}
|
||||
return responses
|
||||
}
|
||||
|
||||
return responses, nil
|
||||
func dedupeRecommendationResponsesByTenderID(responses []RecommendedTenderResponse) []RecommendedTenderResponse {
|
||||
seen := make(map[string]struct{}, len(responses))
|
||||
out := make([]RecommendedTenderResponse, 0, len(responses))
|
||||
for _, recommendation := range responses {
|
||||
tenderID := strings.TrimSpace(recommendation.TenderID)
|
||||
if tenderID == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[tenderID]; ok {
|
||||
continue
|
||||
}
|
||||
seen[tenderID] = struct{}{}
|
||||
recommendation.TenderID = tenderID
|
||||
recommendation.Analysis = strings.TrimSpace(recommendation.Analysis)
|
||||
out = append(out, recommendation)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *companyService) getCachedAIRecommendations(ctx context.Context, companyID string) ([]RecommendedTenderResponse, bool) {
|
||||
|
||||
Reference in New Issue
Block a user