show preview in news with fix table size
This commit is contained in:
@@ -30,7 +30,7 @@ def get_news_page(page: int, page_size: int, sort_order: str = "desc") -> NewsPa
|
||||
|
||||
response = _run_search(
|
||||
query={"match_all": {}},
|
||||
source=["date", "maintitle", "author", "url"],
|
||||
source=["date", "maintitle", "author", "url", "intro_content", "full_content"],
|
||||
size=page_size,
|
||||
offset=offset,
|
||||
sort=[{"date_full": sort_order}],
|
||||
@@ -335,7 +335,11 @@ def _parse_hit(hit: dict) -> NewsArticle:
|
||||
source = hit.get("_source", {})
|
||||
|
||||
fragments = hit.get("highlight", {}).get("full_content")
|
||||
snippet = fragments[0] if fragments else None
|
||||
|
||||
if fragments:
|
||||
snippet = fragments[0]
|
||||
else:
|
||||
snippet = _make_preview(source)
|
||||
|
||||
return NewsArticle(
|
||||
id=hit.get("_id"),
|
||||
@@ -347,6 +351,21 @@ def _parse_hit(hit: dict) -> NewsArticle:
|
||||
)
|
||||
|
||||
|
||||
def _make_preview(source: dict) -> str | None:
|
||||
text = source.get("intro_content") or source.get("full_content")
|
||||
|
||||
if not text:
|
||||
return None
|
||||
|
||||
words = text.split()
|
||||
|
||||
PREVIEW_WORD_COUNT = 10
|
||||
preview = " ".join(words[:PREVIEW_WORD_COUNT])
|
||||
if len(words) > PREVIEW_WORD_COUNT:
|
||||
preview = preview + " …"
|
||||
return preview
|
||||
|
||||
|
||||
def _is_last_page(page: int, page_size: int, total: int) -> bool:
|
||||
return page * page_size >= total
|
||||
|
||||
@@ -394,7 +413,7 @@ def _related_articles(
|
||||
response = elasticsearch.search(
|
||||
index="aktuell",
|
||||
query={"bool": bool_query},
|
||||
source=["date", "maintitle", "author", "url"],
|
||||
source=["date", "maintitle", "author", "url", "intro_content", "full_content"],
|
||||
size=k,
|
||||
offset=0,
|
||||
cluster="inse",
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
[sortOrder]="sortOrder"
|
||||
[searchControl]="searchControl"
|
||||
extraColumnId="snippet"
|
||||
extraColumnHeader="Fundstelle"
|
||||
extraColumnHeader="Inhalt"
|
||||
[extraColumnTemplate]="snippetTpl"
|
||||
(sortChange)="onSortChange($event)"
|
||||
(pageChange)="onPage($event)">
|
||||
|
||||
@@ -44,12 +44,12 @@ export class NewsComponent implements OnInit {
|
||||
|
||||
readonly searchControl = new FormControl('', { nonNullable: true });
|
||||
|
||||
get displayedColumns(): string[] {
|
||||
if (this.isSearching) {
|
||||
return ['maintitle', 'snippet', 'relevance', 'date'];
|
||||
}
|
||||
return ['maintitle', 'relevance', 'date'];
|
||||
}
|
||||
readonly displayedColumns: string[] = [
|
||||
'maintitle',
|
||||
'snippet',
|
||||
'relevance',
|
||||
'date',
|
||||
];
|
||||
|
||||
articles: NewsArticle[] = [];
|
||||
total = 0;
|
||||
@@ -58,10 +58,6 @@ export class NewsComponent implements OnInit {
|
||||
currentPage = 1;
|
||||
sortOrder: SortOrder = DEFAULT_SORT_ORDER;
|
||||
|
||||
get isSearching(): boolean {
|
||||
return this.searchControl.value.trim().length > 0;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParamMap
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
|
||||
@@ -58,12 +58,25 @@
|
||||
table {
|
||||
width: 100%;
|
||||
min-width: 600px;
|
||||
table-layout: fixed;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0 10px;
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
::ng-deep .mat-column-maintitle {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
::ng-deep .mat-column-relevance {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
::ng-deep .mat-column-date {
|
||||
width: 110px;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
display: inline-block;
|
||||
max-width: 520px;
|
||||
@@ -187,6 +200,7 @@ table {
|
||||
color: var(--sg-text);
|
||||
border-bottom-color: var(--sg-border);
|
||||
font-size: 13px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
mat-paginator {
|
||||
|
||||
Reference in New Issue
Block a user