removed old code and truncated cards in person search to keep layout static
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Kazgatari
2026-06-17 11:46:16 +02:00
parent bb066117bc
commit b496cfd52c
4 changed files with 86 additions and 111 deletions
@@ -35,15 +35,6 @@ headers = {
"Content-Type": "application/json"
}
def float_array_to_base64(vector):
"""
Convert a float vector into a Base64 string representing 32-bit big-endian float bytes.
Elasticsearch expects big-endian floats for binary/Base64 dense_vector encoding.
"""
arr = np.asarray(vector, dtype=np.float32)
big_endian_bytes = arr.astype('>f4').tobytes()
return base64.b64encode(big_endian_bytes).decode('utf-8')
def split_into_sentences(text):
if not text:
return []
@@ -52,77 +43,6 @@ def split_into_sentences(text):
# Filter out empty or extremely short sentences
return [s for s in sentences if len(s.strip()) > 3]
def check_and_update_mapping():
print("Checking 'topicvectors' index...")
with httpx.Client(timeout=30.0) as client:
exists_resp = client.head(f"{ELASTIC_URL}topicvectors", headers=headers)
if exists_resp.status_code == 404:
print("Index 'topicvectors' does not exist. Creating index with mapping...")
create_payload = {
"mappings": {
"properties": {
"id": {"type": "keyword"},
"display_name": {
"type": "text",
"fields": {
"keyword": {"type": "keyword", "ignore_above": 256}
}
},
"display_name_vector": {
"type": "dense_vector",
"dims": 768,
"index": True,
"similarity": "cosine",
"index_options": {
"type": "int8_hnsw",
"m": 16,
"ef_construction": 100
}
},
"description": {"type": "text"},
"description_vectors": {
"type": "nested",
"properties": {
"vector": {
"type": "dense_vector",
"dims": 768,
"index": True,
"similarity": "cosine",
"index_options": {
"type": "int8_hnsw",
"m": 16,
"ef_construction": 100
}
}
}
},
"keywords": {
"type": "text",
"fields": {
"keyword": {"type": "keyword"}
}
},
"cited_by_count": {"type": "long"},
"works_count": {"type": "long"},
"updated_date": {"type": "date"},
"created_date": {"type": "date"}
}
}
}
resp = client.put(
f"{ELASTIC_URL}topicvectors",
json=create_payload,
headers=headers
)
if resp.status_code == 200:
print("Successfully created 'topicvectors' index.")
else:
print(f"Failed to create index: {resp.status_code} - {resp.text}")
resp.raise_for_status()
else:
print("Index 'topicvectors' already exists.")
def fetch_all_topics():
print("Fetching topics from 'openalex-topics'...")
topics = []
@@ -204,8 +124,6 @@ def bulk_index_topics(topics, display_name_vectors, nested_description_vectors):
print(f"Indexed batch {i} to {i + len(batch_topics)}")
def main():
check_and_update_mapping()
topics = fetch_all_topics()
if not topics:
print("No topics found. Exiting.")
@@ -5,15 +5,7 @@
{{ getInitials(person.display_name) }}
</div>
<div class="header-main">
<div class="rating-and-bookmark">
@if (person.relevance_rating) {
<span
[skText]="loading"
class="suitability-badge"
[ngClass]="getRatingClass(person.relevance_rating)">
{{ person.relevance_rating }}
</span>
}
<div class="bookmark">
<button
class="bookmark-btn"
(click)="
@@ -26,16 +18,20 @@
}}</mat-icon>
</button>
</div>
<h2 [skText]="loading" class="person-name">{{ person.display_name }}</h2>
<h2
[skText]="loading"
class="person-name"
[title]="person.display_name ?? ''">
{{ person.display_name ?? '' }}
</h2>
<p [skText]="loading" class="person-id">
{{ getDistinguishingId(person) }}
{{ getDistinguishingId(person) ?? '' }}
</p>
<p [skText]="loading" class="stats">
Publikationen: {{ person.works_count }} · Zitationen:
{{ person.cited_by_count }}
{{ getStatsString() }}
</p>
<p [skText]="loading" class="stats">
h_index: {{person.summary_stats?.h_index }}
<p [skText]="loading" class="stats">
{{ getHIndexString() }}
</p>
</div>
</a>
@@ -60,9 +56,12 @@
"
>apartment</mat-icon
>
<span [skText]="loading" style="vertical-align: middle">{{
inst.display_name ?? '' | truncate: 30
}}</span>
<span
[skText]="loading"
class="institution-name"
style="vertical-align: middle"
>{{ inst.display_name ?? '' }}</span
>
@if (inst.country_code && !loading) {
<img
alt=""
@@ -71,6 +70,7 @@
height="10"
style="margin-left: 6px; vertical-align: middle" />
<span
class="country-code"
style="font-size: 9px; margin-left: 2px; vertical-align: middle"
>{{ inst.country_code.toUpperCase() }}</span
>
@@ -108,6 +108,11 @@
font-size: 16px;
font-weight: 600;
color: var(--sg-text);
min-height: 24px;
line-height: 24px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.institution {
display: flex;
@@ -133,6 +138,26 @@
display: inline-flex;
align-items: center;
transition: all 0.2s ease;
max-width: 100%;
box-sizing: border-box;
.institution-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
min-width: 0;
flex: 1;
}
.flag-img {
flex-shrink: 0;
}
.country-code {
display: inline-block;
flex-shrink: 0;
white-space: nowrap;
}
&:hover {
background: var(--sg-primary);
@@ -143,13 +168,15 @@
.flag-img {
border: 1px solid;
vertical-align: -10px;
vertical-align: middle;
}
.person-id {
margin: 2px 0 0;
font-size: 10px;
color: var(--sg-text-soft);
min-height: 15px;
line-height: 15px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -159,6 +186,11 @@
margin: 4px 0 0;
font-size: 10px;
color: var(--sg-text-muted);
min-height: 15px;
line-height: 15px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.card-body {
@@ -186,6 +218,11 @@
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
box-sizing: border-box;
&:hover {
background: var(--sg-primary-soft);
@@ -3,18 +3,11 @@ import { CommonModule } from '@angular/common';
import { RouterLink } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { CustomAuthor, DehydratedInstitution, WorkTopic } from '../../api';
import { TruncatePipe } from '../../shared/pipes/truncate.pipe';
import { SkTextDirective } from '../../custom-directives/sk-text.directive';
@Component({
selector: 'app-person-card',
standalone: true,
imports: [
CommonModule,
RouterLink,
MatIconModule,
TruncatePipe,
SkTextDirective,
],
imports: [CommonModule, RouterLink, MatIconModule, SkTextDirective],
templateUrl: './person-card.component.html',
styleUrl: './person-card.component.scss',
})
@@ -62,8 +55,11 @@ export class PersonCardComponent {
if (topic.field?.display_name) parts.push(topic.field.display_name);
if (topic.subfield?.display_name) parts.push(topic.subfield.display_name);
if (parts.length === 0) return topic.display_name || '';
return parts.join(' - ');
const path = parts.join(' - ');
if (topic.display_name) {
return path ? `${topic.display_name}\n(${path})` : topic.display_name;
}
return path;
}
getDistinguishingId(person: CustomAuthor): string {
@@ -74,6 +70,30 @@ export class PersonCardComponent {
return '';
}
getStatsString(): string {
const works = this.person.works_count;
const citations = this.person.cited_by_count;
const hasWorks = works !== undefined && works !== null;
const hasCitations = citations !== undefined && citations !== null;
if (hasWorks && hasCitations) {
return `Publikationen: ${works} · Zitationen: ${citations}`;
} else if (hasWorks) {
return `Publikationen: ${works}`;
} else if (hasCitations) {
return `Zitationen: ${citations}`;
}
return '';
}
getHIndexString(): string {
const hIndex = this.person.summary_stats?.h_index;
if (hIndex !== undefined && hIndex !== null) {
return `h_index: ${hIndex}`;
}
return '';
}
toggleBookmark(): void {
this.bookmarkToggle.emit(this.person);
}