feat(keyword-search-works): expand rows to show matched content
This commit is contained in:
+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 {
|
||||
|
||||
Reference in New Issue
Block a user