feat(patents): add year range filter to global patents page
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev There was a failure building this commit

This commit is contained in:
2026-06-27 11:30:09 +02:00
parent 163fdfaa39
commit 6fc491fd87
7 changed files with 395 additions and 70 deletions
+7 -5
View File
@@ -25,6 +25,8 @@ async def get_all_patents(
source: str | None = None,
sort_by: str = "date",
sort_direction: str = "desc",
year_from: int | None = None,
year_to: int | None = None,
client: PatentSearchClient | None = None,
ipc_client: IpcSearchClient | None = None,
) -> model.AllPatentsResponse:
@@ -34,14 +36,14 @@ async def get_all_patents(
try:
if source == "EPO":
epo_data = await all_patents_client.search_epo(
all_patents_client.epo_query(page, size, search, sort_direction)
all_patents_client.epo_query(page, size, search, sort_direction, year_from, year_to)
)
patents = parse_epo_hits(epo_data)
total = epo_data.get("hits", {}).get("total", {}).get("value", 0)
elif source == "USPTO":
uspto_data = await all_patents_client.search_uspto(
all_patents_client.uspto_query(page, size, search, sort_direction)
all_patents_client.uspto_query(page, size, search, sort_direction, year_from, year_to)
)
patents = parse_uspto_hits(uspto_data)
total = uspto_data.get("hits", {}).get("total", {}).get("value", 0)
@@ -50,10 +52,10 @@ async def get_all_patents(
half = size // 2
epo_data, uspto_data = await asyncio.gather(
all_patents_client.search_epo(
all_patents_client.epo_query(page, half, search, sort_direction)
all_patents_client.epo_query(page, half, search, sort_direction, year_from, year_to)
),
all_patents_client.search_uspto(
all_patents_client.uspto_query(page, half, search, sort_direction)
all_patents_client.uspto_query(page, half, search, sort_direction, year_from, year_to)
),
)
patents = parse_epo_hits(epo_data) + parse_uspto_hits(uspto_data)
@@ -80,4 +82,4 @@ async def get_all_patents(
page=page,
size=size,
patents=patents,
)
)
+6 -1
View File
@@ -1,3 +1,4 @@
"""Business logic for global patent listing."""
from fastapi import APIRouter
from inse.patents.all import logic
@@ -19,6 +20,8 @@ async def get_all_patents(
source: str | None = None,
sort_by: str = "date",
sort_direction: str = "desc",
year_from: int | None = None,
year_to: int | None = None,
):
return await logic.get_all_patents(
page=page,
@@ -27,4 +30,6 @@ async def get_all_patents(
source=source,
sort_by=sort_by,
sort_direction=sort_direction,
)
year_from=year_from,
year_to=year_to,
)
@@ -41,13 +41,15 @@ class AllPatentsSearchClient:
size: int = 10,
search: str | None = None,
sort_direction: str = "desc",
year_from: int | None = None,
year_to: int | None = None,
) -> dict[str, Any]:
sort = [{"date_publication": {"order": sort_direction, "missing": "_last"}}, "_doc"]
if search and search.strip():
term = search.strip()
doc_number = term.upper().removeprefix("EP")
query: dict[str, Any] = {
search_query: dict[str, Any] = {
"bool": {
"should": [
{"match_phrase": {"title_en": {"query": term}}},
@@ -58,7 +60,26 @@ class AllPatentsSearchClient:
}
}
else:
query = {"match_all": {}}
search_query = {"match_all": {}}
filters = []
if year_from or year_to:
date_range: dict[str, Any] = {}
if year_from:
date_range["gte"] = year_from * 10000
if year_to:
date_range["lte"] = (year_to * 10000) + 9999
filters.append({"range": {"date_publication": date_range}})
if filters:
query: dict[str, Any] = {
"bool": {
"must": search_query,
"filter": filters,
}
}
else:
query = search_query
return {
"from": page * size,
@@ -80,13 +101,15 @@ class AllPatentsSearchClient:
size: int = 10,
search: str | None = None,
sort_direction: str = "desc",
year_from: int | None = None,
year_to: int | None = None,
) -> dict[str, Any]:
sort = [{"publication_date": {"order": sort_direction, "missing": "_last"}}, "_doc"]
if search and search.strip():
term = search.strip()
pub_number = term.upper().removeprefix("US")
query: dict[str, Any] = {
search_query: dict[str, Any] = {
"bool": {
"should": [
{"match_phrase": {"title": {"query": term}}},
@@ -96,7 +119,26 @@ class AllPatentsSearchClient:
}
}
else:
query = {"match_all": {}}
search_query = {"match_all": {}}
filters = []
if year_from or year_to:
date_range: dict[str, Any] = {}
if year_from:
date_range["gte"] = year_from * 10000
if year_to:
date_range["lte"] = (year_to * 10000) + 9999
filters.append({"range": {"publication_date": date_range}})
if filters:
query: dict[str, Any] = {
"bool": {
"must": search_query,
"filter": filters,
}
}
else:
query = search_query
return {
"from": page * size,
+5 -6
View File
@@ -16,12 +16,6 @@ import { PatentEntry } from '../model/patentEntry';
import { PatentsByAuthorResponse } from '../model/patentsByAuthorResponse';
import { PatentsByInstitutionResponse } from '../model/patentsByInstitutionResponse';
export interface AllPatentsResponse {
total: number;
page: number;
@@ -236,6 +230,8 @@ export class PatentsService extends BaseService {
source?: string,
sortBy: string = 'date',
sortDirection: string = 'desc',
yearFrom?: number,
yearTo?: number,
): Observable<AllPatentsResponse> {
let params = new HttpParams()
.set('page', String(page))
@@ -245,6 +241,9 @@ export class PatentsService extends BaseService {
if (search) params = params.set('search', search);
if (source) params = params.set('source', source);
if (yearFrom !== undefined)
params = params.set('year_from', String(yearFrom));
if (yearTo !== undefined) params = params.set('year_to', String(yearTo));
const localVarHeaders = this.defaultHeaders;
const { basePath, withCredentials } = this.configuration;
@@ -26,13 +26,52 @@
<mat-chip-option value="USPTO">USPTO</mat-chip-option>
</mat-chip-listbox>
<div class="sorting">
<select
(change)="setSortDirection($any($event.target).value)"
[value]="sortDirection">
<option value="desc">Absteigend</option>
<option value="asc">Aufsteigend</option>
</select>
<div class="year-filter">
<div class="year-filter-top">
<span class="year-filter-label">Zeitraum</span>
<button
type="button"
class="reset-range-button"
[disabled]="!canResetYearRange"
(click)="resetYearRange()">
Zurücksetzen
</button>
</div>
<div class="year-filter-values">
<span>{{ selectedStartYear }}</span>
<span>bis</span>
<span>{{ selectedEndYear }}</span>
</div>
<div
class="year-range-slider"
[style.--range-start]="rangeStartPercent"
[style.--range-end]="rangeEndPercent">
<div class="range-track"></div>
<input
class="range-input range-input-start"
type="range"
[min]="minYear"
[max]="maxYear"
[value]="selectedStartYear"
[style.z-index]="selectedStartYear >= selectedEndYear - 5 ? 4 : 2"
(input)="onStartYearInput($event)"
aria-label="Startjahr" />
<input
class="range-input range-input-end"
type="range"
[min]="minYear"
[max]="maxYear"
[value]="selectedEndYear"
(input)="onEndYearInput($event)"
aria-label="Endjahr" />
</div>
<div class="year-filter-bounds">
<span>{{ minYear }}</span>
<span>{{ maxYear }}</span>
</div>
</div>
</div>
</div>
@@ -60,7 +99,12 @@
<dt>{{ row.label }}</dt>
<dd>
@if (row.variant === 'source') {
<span class="source-badge source-badge--{{ row.value.toLowerCase() }}">{{ row.value }}</span>
<span
class="source-badge source-badge--{{
row.value.toLowerCase()
}}"
>{{ row.value }}</span
>
} @else {
{{ row.value }}
}
@@ -97,10 +141,17 @@
}
@if (selectedPatent.ipc_descriptions.length > 0) {
<div class="detail-section classification-section classification-section--ipc">
<div
class="detail-section classification-section classification-section--ipc">
<h4>Klassifikation (IPC)</h4>
<div class="classification-cards">
@for (card of getClassificationCards(selectedPatent.ipc_descriptions, 'IPC'); track card.key) {
@for (
card of getClassificationCards(
selectedPatent.ipc_descriptions,
'IPC'
);
track card.key
) {
<article class="classification-card">
<header class="classification-card__header">
<div class="classification-card__codes">
@@ -109,17 +160,34 @@
}
</div>
<div class="classification-card__badges">
<span class="classification-badge classification-badge--system">{{ card.system }}</span>
<span class="classification-badge classification-badge--level">{{ card.levelLabel }}</span>
<span
class="classification-badge classification-badge--system"
>{{ card.system }}</span
>
<span
class="classification-badge classification-badge--level"
>{{ card.levelLabel }}</span
>
</div>
</header>
@if (card.primaryDescription) {
<p class="classification-summary">
{{ isClassificationExpanded(card.key) ? card.primaryDescription : getDescriptionPreview(card.primaryDescription) }}
{{
isClassificationExpanded(card.key)
? card.primaryDescription
: getDescriptionPreview(card.primaryDescription)
}}
</p>
@if (isLongDescription(card.primaryDescription)) {
<button type="button" class="classification-toggle" (click)="toggleClassificationExpanded(card.key)">
{{ isClassificationExpanded(card.key) ? 'Weniger anzeigen' : 'Mehr anzeigen' }}
<button
type="button"
class="classification-toggle"
(click)="toggleClassificationExpanded(card.key)">
{{
isClassificationExpanded(card.key)
? 'Weniger anzeigen'
: 'Mehr anzeigen'
}}
</button>
}
}
@@ -149,10 +217,17 @@
}
@if (selectedPatent.cpc_descriptions.length > 0) {
<div class="detail-section classification-section classification-section--cpc">
<div
class="detail-section classification-section classification-section--cpc">
<h4>Klassifikation (CPC)</h4>
<div class="classification-cards">
@for (card of getClassificationCards(selectedPatent.cpc_descriptions, 'CPC'); track card.key) {
@for (
card of getClassificationCards(
selectedPatent.cpc_descriptions,
'CPC'
);
track card.key
) {
<article class="classification-card">
<header class="classification-card__header">
<div class="classification-card__codes">
@@ -161,17 +236,34 @@
}
</div>
<div class="classification-card__badges">
<span class="classification-badge classification-badge--system">{{ card.system }}</span>
<span class="classification-badge classification-badge--level">{{ card.levelLabel }}</span>
<span
class="classification-badge classification-badge--system"
>{{ card.system }}</span
>
<span
class="classification-badge classification-badge--level"
>{{ card.levelLabel }}</span
>
</div>
</header>
@if (card.primaryDescription) {
<p class="classification-summary">
{{ isClassificationExpanded(card.key) ? card.primaryDescription : getDescriptionPreview(card.primaryDescription) }}
{{
isClassificationExpanded(card.key)
? card.primaryDescription
: getDescriptionPreview(card.primaryDescription)
}}
</p>
@if (isLongDescription(card.primaryDescription)) {
<button type="button" class="classification-toggle" (click)="toggleClassificationExpanded(card.key)">
{{ isClassificationExpanded(card.key) ? 'Weniger anzeigen' : 'Mehr anzeigen' }}
<button
type="button"
class="classification-toggle"
(click)="toggleClassificationExpanded(card.key)">
{{
isClassificationExpanded(card.key)
? 'Weniger anzeigen'
: 'Mehr anzeigen'
}}
</button>
}
}
@@ -206,12 +298,25 @@
</div>
} @else {
<div class="cards">
@for (patent of patents; track patent.patent_id + (patent.publication_date ?? '')) {
<mat-card class="card" appearance="outlined" (click)="selectPatent(patent)">
@for (
patent of patents;
track patent.patent_id + (patent.publication_date ?? '')
) {
<mat-card
class="card"
appearance="outlined"
(click)="selectPatent(patent)">
<mat-card-header>
<mat-card-title>{{ patent.title ?? patent.patent_id }}</mat-card-title>
<mat-card-title>{{
patent.title ?? patent.patent_id
}}</mat-card-title>
<mat-card-subtitle>
<span class="source-badge source-badge--{{ patent.source.toLowerCase() }}">{{ patent.source }}</span>
<span
class="source-badge source-badge--{{
patent.source.toLowerCase()
}}"
>{{ patent.source }}</span
>
</mat-card-subtitle>
</mat-card-header>
<mat-card-content class="card-content">
@@ -224,7 +329,9 @@
</mat-card-content>
<mat-card-footer>
<mat-card-actions>
<button mat-button (click)="selectPatent(patent); $event.stopPropagation()">
<button
mat-button
(click)="selectPatent(patent); $event.stopPropagation()">
<mat-icon>info</mat-icon>
Übersicht
</button>
@@ -12,20 +12,6 @@ h1 {
padding: 1rem 0 0;
}
.sorting {
display: flex;
justify-content: flex-end;
gap: 0.5rem;
select {
padding: 0.75rem;
border: 1px solid var(--sg-border);
border-radius: var(--sg-radius-sm);
font-size: 1rem;
cursor: pointer;
}
}
.search-and-filter {
padding: 0 1rem;
display: flex;
@@ -37,8 +23,140 @@ h1 {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 1rem;
}
.year-filter {
width: min(285px, 100%);
padding: 8px 10px;
border: 1px solid #dbe5f6;
border-radius: 10px;
background: #fbfdff;
box-sizing: border-box;
}
.year-filter-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 4px;
}
.year-filter-label {
color: #07163d;
font-size: 12px;
font-weight: 700;
}
.reset-range-button {
border: 0;
background: transparent;
color: #0057ff;
font-size: 11px;
cursor: pointer;
padding: 0;
font-family: inherit;
&:disabled {
color: #9aa5bc;
cursor: default;
}
}
.year-filter-values {
display: flex;
align-items: center;
justify-content: center;
gap: 7px;
margin-bottom: 5px;
color: #40506f;
font-size: 12px;
font-weight: 600;
}
.year-filter-bounds {
display: flex;
justify-content: space-between;
margin-top: 1px;
color: #7c88a3;
font-size: 10px;
}
.year-range-slider {
--range-start: 0%;
--range-end: 100%;
--accent: #0057ff;
position: relative;
height: 22px;
}
.range-track {
position: absolute;
top: 50%;
left: 0;
right: 0;
height: 5px;
transform: translateY(-50%);
border-radius: 999px;
background: linear-gradient(
to right,
#d8e2f4 0%,
#d8e2f4 var(--range-start),
var(--accent) var(--range-start),
var(--accent) var(--range-end),
#d8e2f4 var(--range-end),
#d8e2f4 100%
);
}
.range-input {
position: absolute;
inset: 0;
width: 100%;
height: 22px;
margin: 0;
appearance: none;
background: transparent;
pointer-events: none;
&::-webkit-slider-runnable-track,
&::-moz-range-track {
height: 5px;
background: transparent;
border: none;
}
&::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 15px;
margin-top: -5px;
border: 2px solid #ffffff;
border-radius: 50%;
background: #0057ff;
box-shadow: 0 0 0 1px #9ab7ff, 0 2px 6px rgba(0, 87, 255, 0.22);
cursor: pointer;
pointer-events: auto;
}
&::-moz-range-thumb {
width: 15px;
height: 15px;
border: 2px solid #ffffff;
border-radius: 50%;
background: #0057ff;
box-shadow: 0 0 0 1px #9ab7ff, 0 2px 6px rgba(0, 87, 255, 0.22);
cursor: pointer;
pointer-events: auto;
}
}
.range-input-start { z-index: 2; }
.range-input-end { z-index: 3; }
.state-message {
display: flex;
align-items: center;
@@ -58,15 +176,11 @@ h1 {
}
@media (max-width: 900px) {
.cards {
grid-template-columns: repeat(2, 1fr);
}
.cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
.cards {
grid-template-columns: 1fr;
}
.cards { grid-template-columns: 1fr; }
}
mat-paginator {
@@ -28,6 +28,7 @@ interface ClassificationCard {
}
const DESCRIPTION_PREVIEW_LENGTH = 140;
const MIN_YEAR = 1978;
@Component({
selector: 'app-patents',
@@ -62,12 +63,17 @@ export class PatentsComponent implements OnInit {
searchTerm = '';
activeFilter: SourceFilter = 'all';
sortDirection: string = 'desc';
sortDirection: string = 'asc';
// Jahr-Slider
readonly minYear = MIN_YEAR;
readonly maxYear = new Date().getFullYear();
selectedStartYear = MIN_YEAR;
selectedEndYear = new Date().getFullYear();
selectedPatent: PatentEntry | null = null;
showDetail = false;
private expandedClassificationKeys = new Set<string>();
private searchSubject = new Subject<string>();
constructor() {
@@ -92,17 +98,68 @@ export class PatentsComponent implements OnInit {
if (f === 'EPO' || f === 'USPTO') this.activeFilter = f;
const d = qp.get('sort_direction');
if (d === 'asc' || d === 'desc') this.sortDirection = d;
const sy = parseInt(qp.get('year_from') ?? '', 10);
const ey = parseInt(qp.get('year_to') ?? '', 10);
if (!isNaN(sy)) this.selectedStartYear = sy;
if (!isNaN(ey)) this.selectedEndYear = ey;
this.loadPatents();
}
get rangeStartPercent(): string {
const total = this.maxYear - this.minYear;
return `${((this.selectedStartYear - this.minYear) / total) * 100}%`;
}
get rangeEndPercent(): string {
const total = this.maxYear - this.minYear;
return `${((this.selectedEndYear - this.minYear) / total) * 100}%`;
}
get canResetYearRange(): boolean {
return this.selectedStartYear !== this.minYear || this.selectedEndYear !== this.maxYear;
}
onStartYearInput(event: Event): void {
const val = parseInt((event.target as HTMLInputElement).value, 10);
this.selectedStartYear = Math.min(val, this.selectedEndYear);
this.page = 0;
this.loadPatents();
this.updateQueryParams();
}
onEndYearInput(event: Event): void {
const val = parseInt((event.target as HTMLInputElement).value, 10);
this.selectedEndYear = Math.max(val, this.selectedStartYear);
this.page = 0;
this.loadPatents();
this.updateQueryParams();
}
resetYearRange(): void {
this.selectedStartYear = this.minYear;
this.selectedEndYear = this.maxYear;
this.page = 0;
this.loadPatents();
this.updateQueryParams();
}
private loadPatents(): void {
this.loading = true;
this.error = false;
const source = this.activeFilter === 'all' ? undefined : this.activeFilter;
this.patentsApi
.getAllPatents(this.page, this.pageSize, this.searchTerm || undefined, source, 'date', this.sortDirection)
.getAllPatents(
this.page,
this.pageSize,
this.searchTerm || undefined,
source,
'date',
this.sortDirection,
this.selectedStartYear,
this.selectedEndYear,
)
.subscribe({
next: (res) => {
this.patents = res.patents;
@@ -175,6 +232,8 @@ export class PatentsComponent implements OnInit {
size: this.pageSize,
source: this.activeFilter === 'all' ? null : this.activeFilter,
sort_direction: this.sortDirection,
year_from: this.selectedStartYear !== this.minYear ? this.selectedStartYear : null,
year_to: this.selectedEndYear !== this.maxYear ? this.selectedEndYear : null,
},
queryParamsHandling: 'merge',
replaceUrl: true,
@@ -217,10 +276,7 @@ export class PatentsComponent implements OnInit {
return value.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, (c) => c.toUpperCase());
}
getClassificationCards(
entries: IpcClassification[] | undefined,
system: ClassificationSystem,
): ClassificationCard[] {
getClassificationCards(entries: IpcClassification[] | undefined, system: ClassificationSystem): ClassificationCard[] {
if (!entries?.length) return [];
const merged = new Map<string, ClassificationCard>();
for (const entry of entries) {