diff --git a/service/src/main/inse/patents/all/logic.py b/service/src/main/inse/patents/all/logic.py index 88288c91..7206fe8a 100644 --- a/service/src/main/inse/patents/all/logic.py +++ b/service/src/main/inse/patents/all/logic.py @@ -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, - ) + ) \ No newline at end of file diff --git a/service/src/main/inse/patents/all/service.py b/service/src/main/inse/patents/all/service.py index 394ab362..0d38bb5f 100644 --- a/service/src/main/inse/patents/all/service.py +++ b/service/src/main/inse/patents/all/service.py @@ -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, + ) \ No newline at end of file diff --git a/service/src/main/inse/patents/elastic_search_all_patents_client.py b/service/src/main/inse/patents/elastic_search_all_patents_client.py index 4584f40b..fa67de96 100644 --- a/service/src/main/inse/patents/elastic_search_all_patents_client.py +++ b/service/src/main/inse/patents/elastic_search_all_patents_client.py @@ -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, diff --git a/webapp/src/app/api/api/patents.service.ts b/webapp/src/app/api/api/patents.service.ts index bc1be987..9bcab67c 100644 --- a/webapp/src/app/api/api/patents.service.ts +++ b/webapp/src/app/api/api/patents.service.ts @@ -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 { 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; diff --git a/webapp/src/app/modules/patents/patents.component.html b/webapp/src/app/modules/patents/patents.component.html index 76c7df46..6ffe47bd 100644 --- a/webapp/src/app/modules/patents/patents.component.html +++ b/webapp/src/app/modules/patents/patents.component.html @@ -26,13 +26,52 @@ USPTO -
- +
+
+ Zeitraum + +
+ +
+ {{ selectedStartYear }} + bis + {{ selectedEndYear }} +
+ +
+
+ + +
+ +
+ {{ minYear }} + {{ maxYear }} +
@@ -60,7 +99,12 @@
{{ row.label }}
@if (row.variant === 'source') { - {{ row.value }} + {{ row.value }} } @else { {{ row.value }} } @@ -97,10 +141,17 @@ } @if (selectedPatent.ipc_descriptions.length > 0) { -
+

Klassifikation (IPC)

- @for (card of getClassificationCards(selectedPatent.ipc_descriptions, 'IPC'); track card.key) { + @for ( + card of getClassificationCards( + selectedPatent.ipc_descriptions, + 'IPC' + ); + track card.key + ) {
@@ -109,17 +160,34 @@ }
- {{ card.system }} - {{ card.levelLabel }} + {{ card.system }} + {{ card.levelLabel }}
@if (card.primaryDescription) {

- {{ isClassificationExpanded(card.key) ? card.primaryDescription : getDescriptionPreview(card.primaryDescription) }} + {{ + isClassificationExpanded(card.key) + ? card.primaryDescription + : getDescriptionPreview(card.primaryDescription) + }}

@if (isLongDescription(card.primaryDescription)) { - } } @@ -149,10 +217,17 @@ } @if (selectedPatent.cpc_descriptions.length > 0) { -
+

Klassifikation (CPC)

- @for (card of getClassificationCards(selectedPatent.cpc_descriptions, 'CPC'); track card.key) { + @for ( + card of getClassificationCards( + selectedPatent.cpc_descriptions, + 'CPC' + ); + track card.key + ) {
@@ -161,17 +236,34 @@ }
- {{ card.system }} - {{ card.levelLabel }} + {{ card.system }} + {{ card.levelLabel }}
@if (card.primaryDescription) {

- {{ isClassificationExpanded(card.key) ? card.primaryDescription : getDescriptionPreview(card.primaryDescription) }} + {{ + isClassificationExpanded(card.key) + ? card.primaryDescription + : getDescriptionPreview(card.primaryDescription) + }}

@if (isLongDescription(card.primaryDescription)) { - } } @@ -206,12 +298,25 @@
} @else {
- @for (patent of patents; track patent.patent_id + (patent.publication_date ?? '')) { - + @for ( + patent of patents; + track patent.patent_id + (patent.publication_date ?? '') + ) { + - {{ patent.title ?? patent.patent_id }} + {{ + patent.title ?? patent.patent_id + }} - {{ patent.source }} + {{ patent.source }} @@ -224,7 +329,9 @@ - diff --git a/webapp/src/app/modules/patents/patents.component.scss b/webapp/src/app/modules/patents/patents.component.scss index e19ca6e1..9c96ca64 100644 --- a/webapp/src/app/modules/patents/patents.component.scss +++ b/webapp/src/app/modules/patents/patents.component.scss @@ -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 { diff --git a/webapp/src/app/modules/patents/patents.component.ts b/webapp/src/app/modules/patents/patents.component.ts index d946a0e5..c0d056f0 100644 --- a/webapp/src/app/modules/patents/patents.component.ts +++ b/webapp/src/app/modules/patents/patents.component.ts @@ -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(); - private searchSubject = new Subject(); 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(); for (const entry of entries) {