feat(keyword-search-works): expand rows to show matched content
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Innovation Search Engine API
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||
* https://openapi-generator.tech
|
||||
@@ -24,48 +24,49 @@ import { WorkHasContent } from './workHasContent';
|
||||
import { Location } from './location';
|
||||
import { WorkBiblio } from './workBiblio';
|
||||
|
||||
|
||||
/**
|
||||
* A scholarly document (article, book, dataset, thesis, etc.)
|
||||
*/
|
||||
export interface Work {
|
||||
id?: string | null;
|
||||
doi?: string | null;
|
||||
title?: string | null;
|
||||
display_name?: string | null;
|
||||
publication_year?: number | null;
|
||||
publication_date?: string | null;
|
||||
type?: string | null;
|
||||
language?: string | null;
|
||||
cited_by_count?: number | null;
|
||||
is_retracted?: boolean | null;
|
||||
is_paratext?: boolean | null;
|
||||
primary_location?: Location | null;
|
||||
locations?: Array<Location> | null;
|
||||
best_oa_location?: Location | null;
|
||||
open_access?: OpenAccess | null;
|
||||
authorships?: Array<Authorship> | null;
|
||||
ids?: WorkIds | null;
|
||||
biblio?: WorkBiblio | null;
|
||||
abstract_inverted_index?: object | null;
|
||||
referenced_works?: Array<string> | null;
|
||||
referenced_works_count?: number | null;
|
||||
related_works?: Array<string> | null;
|
||||
topics?: Array<WorkTopic> | null;
|
||||
primary_topic?: WorkTopic | null;
|
||||
keywords?: Array<WorkKeyword> | null;
|
||||
funders?: Array<DehydratedFunder> | null;
|
||||
awards?: Array<Award> | null;
|
||||
fwci?: Fwci | null;
|
||||
citation_normalized_percentile?: WorkCitationNormalizedPercentile | null;
|
||||
cited_by_percentile_year?: WorkCitedByPercentileYear | null;
|
||||
counts_by_year?: Array<WorkCountsByYearInner> | null;
|
||||
sustainable_development_goals?: Array<WorkSustainableDevelopmentGoalsInner> | null;
|
||||
mesh?: Array<WorkMeshInner> | null;
|
||||
indexed_in?: Array<string> | null;
|
||||
has_content?: WorkHasContent | null;
|
||||
content_url?: string | null;
|
||||
created_date?: string | null;
|
||||
updated_date?: string | null;
|
||||
export interface Work {
|
||||
id?: string | null;
|
||||
doi?: string | null;
|
||||
title?: string | null;
|
||||
display_name?: string | null;
|
||||
publication_year?: number | null;
|
||||
publication_date?: string | null;
|
||||
type?: string | null;
|
||||
language?: string | null;
|
||||
cited_by_count?: number | null;
|
||||
is_retracted?: boolean | null;
|
||||
is_paratext?: boolean | null;
|
||||
primary_location?: Location | null;
|
||||
locations?: Array<Location> | null;
|
||||
best_oa_location?: Location | null;
|
||||
open_access?: OpenAccess | null;
|
||||
authorships?: Array<Authorship> | null;
|
||||
ids?: WorkIds | null;
|
||||
biblio?: WorkBiblio | null;
|
||||
abstract_inverted_index?: object | null;
|
||||
referenced_works?: Array<string> | null;
|
||||
referenced_works_count?: number | null;
|
||||
related_works?: Array<string> | null;
|
||||
topics?: Array<WorkTopic> | null;
|
||||
primary_topic?: WorkTopic | null;
|
||||
keywords?: Array<WorkKeyword> | null;
|
||||
funders?: Array<DehydratedFunder> | null;
|
||||
awards?: Array<Award> | null;
|
||||
fwci?: Fwci | null;
|
||||
citation_normalized_percentile?: WorkCitationNormalizedPercentile | null;
|
||||
cited_by_percentile_year?: WorkCitedByPercentileYear | null;
|
||||
counts_by_year?: Array<WorkCountsByYearInner> | null;
|
||||
sustainable_development_goals?: Array<WorkSustainableDevelopmentGoalsInner> | null;
|
||||
mesh?: Array<WorkMeshInner> | null;
|
||||
indexed_in?: Array<string> | null;
|
||||
has_content?: WorkHasContent | null;
|
||||
content_url?: string | null;
|
||||
created_date?: string | null;
|
||||
updated_date?: string | null;
|
||||
snippet?: string | null;
|
||||
snippet_field?: string | null;
|
||||
matched_via?: Array<string> | null;
|
||||
}
|
||||
|
||||
|
||||
+37
-1
@@ -5,11 +5,47 @@
|
||||
[selectedAuthorsPage]="selectedAuthorsPage()"
|
||||
[showTopicFilter]="fuzzySearch()" />
|
||||
|
||||
<ng-template #snippetTmp let-work>
|
||||
<div class="snippet-detail">
|
||||
@if (snippetSegments().get(work.id); as segments) {
|
||||
<span class="snippet-label">
|
||||
Fundstelle im {{ snippetSourceLabel(work) }}
|
||||
</span>
|
||||
<p class="snippet">
|
||||
@for (segment of segments; track $index) {
|
||||
@if (segment.isSearchMatch) {
|
||||
<mark class="snippet-mark">{{ segment.text }}</mark>
|
||||
} @else {
|
||||
<span>{{ segment.text }}</span>
|
||||
}
|
||||
}
|
||||
</p>
|
||||
} @else if (work.matched_via?.length) {
|
||||
<span class="snippet-label">Kein Treffer im Text</span>
|
||||
<p class="snippet">
|
||||
Das gesuchte Keyword kommt weder im Titel noch im Abstract vor. Die
|
||||
Publikation wurde über
|
||||
{{ work.matched_via!.length === 1 ? 'das Thema' : 'die Themen' }}
|
||||
@for (name of work.matched_via; track name; let last = $last) {
|
||||
<span class="matched-topic">{{ name }}</span
|
||||
>{{ last ? '' : ', ' }}
|
||||
}
|
||||
gefunden.
|
||||
</p>
|
||||
} @else {
|
||||
<span class="empty-text">
|
||||
Für diese Publikation liegt keine Fundstelle vor.
|
||||
</span>
|
||||
}
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
<app-publication-table
|
||||
[page]="workPage()"
|
||||
[authorFilterEnabled]="true"
|
||||
[institutionFilterEnabled]="true"
|
||||
[topicFilterEnabled]="fuzzySearch()" />
|
||||
[topicFilterEnabled]="fuzzySearch()"
|
||||
[detailTemplate]="snippetTmp" />
|
||||
|
||||
<app-query-param-paginator
|
||||
[total]="total()"
|
||||
|
||||
+53
@@ -82,3 +82,56 @@
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
EXPANDED DETAIL ROW
|
||||
============================================================ */
|
||||
|
||||
:host ::ng-deep {
|
||||
.detail-row .mat-mdc-cell {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.element-row.is-expanded .mat-mdc-cell {
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
.snippet-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.375rem;
|
||||
padding: 0.875rem 1rem 1rem 4rem;
|
||||
background: var(--sg-surface-soft);
|
||||
}
|
||||
|
||||
.snippet-label {
|
||||
color: var(--sg-text-muted);
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.snippet {
|
||||
margin: 0;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
color: var(--sg-text-secondary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.snippet-mark {
|
||||
background: transparent;
|
||||
color: var(--sg-blue-highlight);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.matched-topic {
|
||||
color: var(--sg-text);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
color: var(--sg-text-muted);
|
||||
}
|
||||
|
||||
+62
-1
@@ -11,9 +11,28 @@ import { PublicationTableComponent } from '../../../../shared/ui/publication-tab
|
||||
import { WorkPageV2 } from '../../../../api/model/workPageV2';
|
||||
import { PaginationService } from '../../../../shared/services/pagination.service';
|
||||
import { QueryParamPaginatorComponent } from '../../../../shared/ui/query-param-paginator/query-param-paginator.component';
|
||||
import { AuthorPage, InstitutionPageV2, TopicPageV2 } from '../../../../api';
|
||||
import {
|
||||
AuthorPage,
|
||||
InstitutionPageV2,
|
||||
TopicPageV2,
|
||||
Work,
|
||||
} from '../../../../api';
|
||||
import { SearchResultsStateService } from '../search-results-state.service';
|
||||
|
||||
interface SnippetSegment {
|
||||
text: string;
|
||||
isSearchMatch: boolean;
|
||||
}
|
||||
|
||||
function decodeHtml(text: string): string {
|
||||
return text
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/&#(?:39|x27);/g, "'")
|
||||
.replace(/&/g, '&');
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-works-results',
|
||||
imports: [
|
||||
@@ -64,6 +83,48 @@ export class KeywordsToWorksResultsComponent implements OnInit {
|
||||
|
||||
fuzzySearch = computed(() => this.queryParamMap().get('fuzzy') === 'true');
|
||||
|
||||
readonly snippetSegments = computed(() => {
|
||||
const byWorkId = new Map<string, SnippetSegment[]>();
|
||||
|
||||
for (const work of this.elements()) {
|
||||
if (!work.id || !work.snippet) {
|
||||
continue;
|
||||
}
|
||||
byWorkId.set(work.id, this.buildSegments(work.snippet));
|
||||
}
|
||||
|
||||
return byWorkId;
|
||||
});
|
||||
|
||||
private buildSegments(snippet: string): SnippetSegment[] {
|
||||
const searchMatch = /<em>([\s\S]*?)<\/em>/g;
|
||||
const segments: SnippetSegment[] = [];
|
||||
|
||||
let lastIndex = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
|
||||
const pushPlain = (raw: string) => {
|
||||
const text = decodeHtml(raw);
|
||||
if (text) {
|
||||
segments.push({ text, isSearchMatch: false });
|
||||
}
|
||||
};
|
||||
|
||||
while ((match = searchMatch.exec(snippet)) !== null) {
|
||||
pushPlain(snippet.slice(lastIndex, match.index));
|
||||
segments.push({ text: decodeHtml(match[1]), isSearchMatch: true });
|
||||
lastIndex = searchMatch.lastIndex;
|
||||
}
|
||||
|
||||
pushPlain(snippet.slice(lastIndex));
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
snippetSourceLabel(work: Work): string {
|
||||
return work.snippet_field === 'title' ? 'Titel' : 'Abstract';
|
||||
}
|
||||
|
||||
ngOnInit(): void {}
|
||||
|
||||
clearFilters(): void {
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
mat-row
|
||||
*matRowDef="let row; columns: displayedColumns()"
|
||||
class="element-row"
|
||||
[class.is-expanded]="row === expandedElement()"
|
||||
(click)="toggleRow(row)"></tr>
|
||||
|
||||
<tr
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
<app-data-table
|
||||
[columns]="columns()"
|
||||
[data]="elements()"
|
||||
[detailTemplate]="detailTemplate()"
|
||||
queryParamSortKey="sort_by"
|
||||
queryParamSortDirectionKey="sort_direction" />
|
||||
|
||||
<ng-template #expandTmp let-work>
|
||||
@let expanded = isRowExpanded(work);
|
||||
<button
|
||||
mat-icon-button
|
||||
class="expand-toggle"
|
||||
[attr.aria-expanded]="expanded"
|
||||
[matTooltip]="expanded ? 'Fundstelle ausblenden' : 'Fundstelle anzeigen'"
|
||||
[attr.aria-label]="
|
||||
expanded ? 'Fundstelle ausblenden' : 'Fundstelle anzeigen'
|
||||
">
|
||||
<mat-icon class="expand-icon" [class.is-expanded]="expanded">
|
||||
expand_more
|
||||
</mat-icon>
|
||||
</button>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #titleTmp let-work>
|
||||
<span>{{ work.title }}</span>
|
||||
</ng-template>
|
||||
@@ -16,7 +33,7 @@
|
||||
[class.active]="isTypeActive(work.type)"
|
||||
matTooltip="Nach Typ filtern"
|
||||
matTooltipPosition="above"
|
||||
(click)="toggleTypeFilter(work.type)">
|
||||
(click)="$event.stopPropagation(); toggleTypeFilter(work.type)">
|
||||
<app-chip [color]="typeColor(work.type)">
|
||||
{{ work.type | workType }}
|
||||
</app-chip>
|
||||
@@ -34,7 +51,9 @@
|
||||
[class.active]="isYearActive(work.publication_year)"
|
||||
matTooltip="Nach Jahr filtern"
|
||||
matTooltipPosition="above"
|
||||
(click)="toggleYearFilter(work.publication_year)">
|
||||
(click)="
|
||||
$event.stopPropagation(); toggleYearFilter(work.publication_year)
|
||||
">
|
||||
{{ work.publication_year }}
|
||||
</button>
|
||||
} @else {
|
||||
@@ -50,7 +69,7 @@
|
||||
[class.active]="isLanguageActive(work.language)"
|
||||
matTooltip="Nach Sprache filtern"
|
||||
matTooltipPosition="above"
|
||||
(click)="toggleLanguageFilter(work.language)">
|
||||
(click)="$event.stopPropagation(); toggleLanguageFilter(work.language)">
|
||||
{{ work.language | languageCode }}
|
||||
</button>
|
||||
} @else {
|
||||
@@ -81,7 +100,8 @@
|
||||
<div
|
||||
class="institution-chips"
|
||||
aria-label="Institutionen"
|
||||
style="padding: 0.5rem 0">
|
||||
style="padding: 0.5rem 0"
|
||||
(click)="$event.stopPropagation()">
|
||||
@for (institution of visibleInstitutions; track institution.id) {
|
||||
<app-institution-chip
|
||||
size="mini"
|
||||
@@ -107,7 +127,11 @@
|
||||
@let workAuthorsExpanded = isWorkAuthorsExpanded(work);
|
||||
@let visibleAuthors =
|
||||
workAuthorsExpanded ? workAuthors : workAuthors.slice(0, 3);
|
||||
<div class="author-chips" aria-label="Autoren" style="padding: 0.5rem 0">
|
||||
<div
|
||||
class="author-chips"
|
||||
aria-label="Autoren"
|
||||
style="padding: 0.5rem 0"
|
||||
(click)="$event.stopPropagation()">
|
||||
@for (
|
||||
author of visibleAuthors;
|
||||
track author.id ?? 'name-' + author.display_name
|
||||
@@ -133,7 +157,11 @@
|
||||
|
||||
<ng-template #topicsTmp let-work>
|
||||
@let workTopics = work.topics ?? [];
|
||||
<div class="topic-chips" aria-label="Themen" style="display: flex">
|
||||
<div
|
||||
class="topic-chips"
|
||||
aria-label="Themen"
|
||||
style="display: flex"
|
||||
(click)="$event.stopPropagation()">
|
||||
@for (topic of workTopics; track topic.id) {
|
||||
<app-topic-chip-2
|
||||
size="mini"
|
||||
@@ -157,7 +185,8 @@
|
||||
mat-icon-button
|
||||
color="primary"
|
||||
[routerLink]="['/publication', extractRawId(work.id)]"
|
||||
matTooltip="Details anzeigen">
|
||||
matTooltip="Details anzeigen"
|
||||
(click)="$event.stopPropagation()">
|
||||
<mat-icon>{{ OPEN_IN_NEW_ICON }}</mat-icon>
|
||||
</a>
|
||||
</ng-template>
|
||||
|
||||
@@ -562,3 +562,12 @@ mat-panel-description {
|
||||
align-items: flex-start;
|
||||
max-width: 350px;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
color: var(--sg-text-muted);
|
||||
transition: transform 150ms ease-in-out;
|
||||
|
||||
&.is-expanded {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ export class PublicationTableComponent {
|
||||
rawOaAuthorId = input<string | undefined>(undefined);
|
||||
rawOaInstitutionId = input<string | undefined>(undefined);
|
||||
|
||||
detailTemplate = input<TemplateRef<any> | null>(null);
|
||||
|
||||
shouldFetchClassifications = computed(() => {
|
||||
return (
|
||||
this.rawOaAuthorId() !== undefined ||
|
||||
@@ -85,6 +87,7 @@ export class PublicationTableComponent {
|
||||
|
||||
elements = computed(() => this.page().elements ?? []);
|
||||
|
||||
expandTmp = viewChild.required<TemplateRef<any>>('expandTmp');
|
||||
titleTmp = viewChild.required<TemplateRef<any>>('titleTmp');
|
||||
typeTmp = viewChild.required<TemplateRef<any>>('typeTmp');
|
||||
yearTmp = viewChild.required<TemplateRef<any>>('yearTmp');
|
||||
@@ -202,9 +205,24 @@ export class PublicationTableComponent {
|
||||
},
|
||||
);
|
||||
|
||||
if (this.detailTemplate()) {
|
||||
baseColumns.unshift({
|
||||
id: 'expand',
|
||||
header: '',
|
||||
type: 'display',
|
||||
cellTemplate: this.expandTmp(),
|
||||
});
|
||||
}
|
||||
|
||||
return baseColumns;
|
||||
});
|
||||
|
||||
private readonly dataTable = viewChild(DataTableComponent);
|
||||
|
||||
isRowExpanded(work: Work): boolean {
|
||||
return this.dataTable()?.expandedElement() === work;
|
||||
}
|
||||
|
||||
workIds = computed(
|
||||
() =>
|
||||
this.elements()
|
||||
|
||||
Reference in New Issue
Block a user