Replace author with "Relevant" label in news list

This commit is contained in:
Steven Tischer
2026-06-20 15:15:23 +02:00
parent dc2ef6fd20
commit 08cfec6be0
5 changed files with 96 additions and 6 deletions
+39 -2
View File
@@ -182,10 +182,21 @@ def _run_search(query: dict, source: list, size: int, offset: int, sort) -> dict
def _build_page(response: dict, page: int, page_size: int) -> NewsPage:
hits_section = response.get("hits", {})
total = hits_section.get("total", {}).get("value", 0)
hits = hits_section.get("hits", [])
news_ids = []
for hit in hits:
news_id = hit.get("_id")
if news_id:
news_ids.append(news_id)
relevance_map = _get_relevance_map(news_ids)
articles = []
for hit in hits_section.get("hits", []):
articles.append(_parse_hit(hit))
for hit in hits:
article = _parse_hit(hit)
article.relevant = relevance_map.get(article.id)
articles.append(article)
return NewsPage(
total=total,
@@ -195,6 +206,32 @@ def _build_page(response: dict, page: int, page_size: int) -> NewsPage:
)
def _get_relevance_map(news_ids: list) -> dict:
if not news_ids:
return {}
try:
response = elasticsearch.search(
index="aktuell_postproc",
query={"terms": {"news_id.keyword": news_ids}},
source=["news_id", "relevant"],
size=len(news_ids),
cluster="inse",
)
except Exception:
logger.exception("Postproc-Relevanz-Lookup fehlgeschlagen.")
return {}
relevance_map = {}
for hit in response.get("hits", {}).get("hits", []):
postproc_source = hit.get("_source", {})
news_id = postproc_source.get("news_id")
if news_id is not None:
relevance_map[news_id] = bool(postproc_source.get("relevant", 0))
return relevance_map
def _parse_hit(hit: dict) -> NewsArticle:
source = hit.get("_source", {})
+1
View File
@@ -12,6 +12,7 @@ class NewsArticle(BaseModel):
maintitle: Optional[str] = None
author: Optional[str] = None
url: Optional[str] = None
relevant: Optional[bool] = None
class NewsArticleDetail(NewsArticle):
@@ -42,10 +42,25 @@
</td>
</ng-container>
<ng-container matColumnDef="author">
<th mat-header-cell *matHeaderCellDef>Autor</th>
<ng-container matColumnDef="relevance">
<th mat-header-cell *matHeaderCellDef>Relevanz</th>
<td mat-cell *matCellDef="let article">
{{ article.author || '-' }}
@if (article.relevant === true) {
<span class="relevance-badge is-relevant">
<mat-icon>check_circle</mat-icon>
Relevant
</span>
} @else if (article.relevant === false) {
<span class="relevance-badge not-relevant">
<mat-icon>cancel</mat-icon>
Nicht relevant
</span>
} @else {
<span class="relevance-badge undetermined">
<mat-icon>help</mat-icon>
Nicht bestimmt
</span>
}
</td>
</ng-container>
@@ -114,6 +114,42 @@ table {
background: transparent;
}
.relevance-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 12px;
border-radius: 999px;
font-size: 13px;
font-weight: 600;
line-height: 1;
white-space: nowrap;
mat-icon {
font-size: 16px;
width: 16px;
height: 16px;
}
&.is-relevant {
background: #effaf3;
border: 1px solid #bdebcf;
color: #24834f;
}
&.not-relevant {
background: var(--sg-surface-muted);
border: 1px solid #e2e2e2;
color: var(--sg-text-muted);
}
&.undetermined {
background: #fff7e8;
border: 1px solid #ffd796;
color: #c67500;
}
}
::ng-deep .mat-mdc-header-cell {
color: var(--sg-text-muted);
font-size: 12px;
@@ -21,6 +21,7 @@ interface NewsArticle {
maintitle?: string | null;
author?: string | null;
url?: string | null;
relevant?: boolean | null;
}
interface NewsPage {
@@ -59,7 +60,7 @@ export class NewsComponent implements OnInit {
readonly searchControl = new FormControl('', { nonNullable: true });
displayedColumns = ['maintitle', 'author', 'date'];
displayedColumns = ['maintitle', 'relevance', 'date'];
articles: NewsArticle[] = [];
total = 0;
loading = false;