feat(bloomberg): enrich article content for summaries (#36)
This commit is contained in:
@ -22,6 +22,8 @@ type UserInput struct {
|
||||
type Candidate struct {
|
||||
ID, SourceID string
|
||||
Article scraper.Article
|
||||
orderDate *time.Time
|
||||
orderFrozen bool
|
||||
}
|
||||
type SourceStat struct {
|
||||
SourceID string `json:"source_id"`
|
||||
@ -201,18 +203,50 @@ func (u *useCase) Generate(ctx context.Context, userID string) (Result, error) {
|
||||
if len(articles) > stat.ArticleLimit {
|
||||
articles = articles[:stat.ArticleLimit]
|
||||
}
|
||||
for _, article := range articles {
|
||||
orderDates := make([]*time.Time, len(articles))
|
||||
for i, a := range articles {
|
||||
if a.PublishedAt != nil {
|
||||
date := *a.PublishedAt
|
||||
orderDates[i] = &date
|
||||
}
|
||||
}
|
||||
if input.RankingMode == "title_content" && *source.SourceKey == models.SourceBloomberg {
|
||||
if enricher, ok := feed.(scraper.ArticleEnricher); ok {
|
||||
enriched, enrichErr := enricher.Enrich(ctx, append([]scraper.Article(nil), articles...))
|
||||
valid := enrichErr == nil && len(enriched) == len(articles)
|
||||
if valid {
|
||||
for i, a := range enriched {
|
||||
if a.URL != articles[i].URL || a.Title != articles[i].Title {
|
||||
valid = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if valid {
|
||||
for i, a := range enriched {
|
||||
articles[i].Content = a.Content
|
||||
articles[i].ContentTruncated = a.ContentTruncated
|
||||
if a.PublishedAt != nil {
|
||||
articles[i].PublishedAt = a.PublishedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for i, article := range articles {
|
||||
stat.Candidates++
|
||||
out.TotalCandidates++
|
||||
if input.RankingMode == "title_content" && (strings.TrimSpace(article.Content) == "" || strings.TrimSpace(article.Content) == strings.TrimSpace(article.Title)) {
|
||||
stat.ContentFallbacks++
|
||||
out.ContentFallbacks++
|
||||
article.Content = ""
|
||||
article.ContentTruncated = false
|
||||
}
|
||||
if input.RankingMode == "title" {
|
||||
article.Content = ""
|
||||
article.ContentTruncated = false
|
||||
}
|
||||
candidates = append(candidates, Candidate{ID: NewID(), SourceID: source.ID, Article: article})
|
||||
candidates = append(candidates, Candidate{ID: NewID(), SourceID: source.ID, Article: article, orderDate: orderDates[i], orderFrozen: true})
|
||||
}
|
||||
}
|
||||
stats[source.ID] = len(out.SourceStats)
|
||||
|
||||
Reference in New Issue
Block a user