remove_person_search_metric #314

Merged
tischer merged 2 commits from remove_person_search_metric into dev 2026-09-06 16:56:45 +02:00
7 changed files with 18 additions and 152 deletions
+6 -37
View File
@@ -410,31 +410,16 @@ async def topic_stats_for_authors(
return results
def _primary_topic_match(keywords: list[str], fuzzy: bool) -> dict:
"""Matches works whose primary topic is one of the searched topics/keywords."""
if fuzzy:
return {"terms": {"primary_topic.id": keywords}}
return {
"bool": {
"should": [
{"match_phrase": {"primary_topic.display_name": keyword}}
for keyword in keywords
],
"minimum_should_match": 1,
},
}
def _topic_profile_query(
author_ids: list[str],
keywords: list[str],
operator: KeywordOperator,
publication_types: list[PublicationType],
timespan: Timespan | None,
fuzzy: bool = False,
) -> dict:
"""Builds the Section 3 query"""
"""Builds the Section 3 query.
Unfiltered by keywords on purpose: the topic profile always describes each
author's complete body of work in the timespan.
"""
filters = [_author_filter(author_ids)]
@@ -475,14 +460,6 @@ def _topic_profile_query(
"to_work": {
"reverse_nested": {},
"aggs": {
"matched": {
"filter": _build_keyword_query(keywords, operator, fuzzy),
"aggs": {
"primary_match": {
"filter": _primary_topic_match(keywords, fuzzy),
},
},
},
"by_subfield": {
"terms": {
"field": "primary_topic.subfield.display_name.keyword",
@@ -555,11 +532,8 @@ def _topic_profile_query(
async def topic_profile_for_authors(
author_ids: list[str],
keywords: list[str],
operator: KeywordOperator,
publication_types: list[PublicationType],
timespan: Timespan | None,
fuzzy: bool = False,
) -> list[AuthorTopicProfile]:
if not author_ids:
@@ -567,9 +541,7 @@ async def topic_profile_for_authors(
response: dict[str, Any] = await elasticsearch.search(
index=config.settings.openalex_works_search_index,
body=_topic_profile_query(
author_ids, keywords, operator, publication_types, timespan, fuzzy
),
body=_topic_profile_query(author_ids, publication_types, timespan),
cluster=ESCluster.NES,
)
@@ -585,7 +557,6 @@ async def topic_profile_for_authors(
for author_bucket in author_buckets:
to_work = author_bucket.get("to_work", {})
matched = to_work.get("matched", {})
subfields = [
SubfieldShare(
name=bucket.get("key", ""),
@@ -622,8 +593,6 @@ async def topic_profile_for_authors(
author_id=author_bucket.get("key", ""),
display_name=_display_name_from_bucket(author_bucket),
works_total=to_work.get("doc_count", 0),
matched_works=matched.get("doc_count", 0),
primary_topic_matches=matched.get("primary_match", {}).get("doc_count", 0),
distinct_topics=to_work.get("distinct_topics", {}).get("value", 0),
distinct_subfields=to_work.get("distinct_subfields", {}).get("value", 0),
distinct_fields=to_work.get("distinct_fields", {}).get("value", 0),
+1 -8
View File
@@ -333,14 +333,7 @@ class AuthorTopicProfile(BaseModel):
author_id: str = Field(description="The OpenAlex ID of the author.")
display_name: str = Field(description="The name of the author.")
works_total: int = Field(
description="All works of the author in the timespan, regardless of the topic filter.",
)
matched_works: int = Field(
description="Works matching the topic filter (same subset as Section 1).",
)
primary_topic_matches: int = Field(
description="Matched works where one of the searched topics is the work's "
"primary topic.",
description="All works of the author in the timespan.",
)
distinct_topics: int = Field(
description="Number of distinct primary topics across all works.",
+1 -8
View File
@@ -129,22 +129,15 @@ async def topic_stats(request: SelectedAuthorsRequest):
@router.post("/topic-profile", response_model=list[AuthorTopicProfile])
async def topic_profile(request: SelectedAuthorsRequest):
logger.info(
"topic-profile author_ids=%s keywords=%s operator=%s fuzzy=%s "
"publication_types=%s timespan=%s",
"topic-profile author_ids=%s publication_types=%s timespan=%s",
request.author_ids,
request.keywords,
request.operator,
request.fuzzy,
request.publication_types,
request.timespan,
)
return await logic.topic_profile_for_authors(
request.author_ids,
request.keywords,
request.operator,
request.publication_types,
request.timespan,
request.fuzzy,
)
# Compare authors table 2 (author-level stats, keyword/time-independent)
@@ -20,17 +20,9 @@ export interface AuthorTopicProfile {
*/
display_name: string;
/**
* All works of the author in the timespan, regardless of the topic filter.
* All works of the author in the timespan.
*/
works_total: number;
/**
* Works matching the topic filter (same subset as Section 1).
*/
matched_works: number;
/**
* Matched works where one of the searched topics is the work\'s primary topic.
*/
primary_topic_matches: number;
/**
* Number of distinct primary topics across all works.
*/
@@ -87,7 +87,8 @@
<section class="card">
<h2 class="card-title">Themenprofil</h2>
<p class="card-sub">
Verteilung und Breite der Themen über alle Publikationen
Verteilung und Breite der Themen
<strong>über alle Publikationen</strong>
</p>
@if (profileLoading()) {
@@ -103,24 +104,12 @@
[options]="subfieldChart()"
class="profile-chart profile-chart-wide"></div>
<div class="chart-grid">
<div class="chart-box">
<h3 class="chart-title">Themen-Fokus</h3>
<p class="chart-hint">
Publikationen zum Suchthema im Verhältnis zu allen Publikationen –
und wie viele es als Primärthema tragen
</p>
<div echarts [options]="focusChart()" class="profile-chart"></div>
</div>
<div class="chart-box">
<h3 class="chart-title">Themenbreite</h3>
<p class="chart-hint">
Einzigartige Primärthemen, Subfields und Fields über alle
Publikationen (Primärthema)
</p>
<div echarts [options]="breadthChart()" class="profile-chart"></div>
</div>
</div>
<h3 class="chart-title">Themenbreite</h3>
<p class="chart-hint">
Einzigartige Primärthemen, Subfields und Fields über alle
Publikationen (Primärthema)
</p>
<div echarts [options]="breadthChart()" class="profile-chart"></div>
<h3 class="chart-title">Themenlandschaft</h3>
<p class="chart-hint">Field → Subfield → Thema</p>
@@ -311,18 +311,8 @@ app-chip mat-icon {
}
}
.chart-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 24px;
}
@media (max-width: 900px) {
.compare-layout {
padding: 20px 16px 32px;
}
.chart-grid {
grid-template-columns: 1fr;
}
}
@@ -585,67 +585,7 @@ export class CompareAuthorsComponent implements OnInit {
} as EChartsOption;
});
// chart 2: topic focus — how much of the complete body of work is on the searched topic
readonly focusChart = computed<EChartsOption>(() => {
const profiles = this.orderedProfiles();
if (profiles.length === 0) return {};
const pct = (part: number, whole: number) =>
whole > 0 ? Math.round((part / whole) * 1000) / 10 : 0;
return {
tooltip: {
trigger: 'axis',
axisPointer: { type: 'shadow' },
formatter: (params: any) => {
const lines = params.map(
(p: any) =>
`${p.marker} ${p.seriesName}: <b>${p.data.value} %</b> (${p.data.part} von ${p.data.whole} Werken)`,
);
return `<b>${params[0]?.name ?? ''}</b><br/>${lines.join('<br/>')}`;
},
},
legend: { top: 0, textStyle: { color: this.chartTheme.colors().text } },
grid: { left: 16, right: 40, top: 32, bottom: 8, containLabel: true },
xAxis: {
type: 'value',
max: 100,
axisLabel: { formatter: '{value} %' },
},
yAxis: {
type: 'category',
inverse: true,
data: profiles.map((p) => p.display_name),
axisLabel: this.authorAxisLabel(profiles),
},
series: [
{
name: 'Anteil am Gesamtwerk',
type: 'bar',
itemStyle: { color: '#2563eb' },
label: { show: true, position: 'right', formatter: '{c} %' },
data: profiles.map((p) => ({
value: pct(p.matched_works, p.works_total),
part: p.matched_works,
whole: p.works_total,
})),
},
{
name: 'davon Primärthema',
type: 'bar',
itemStyle: { color: '#7c3aed' },
label: { show: true, position: 'right', formatter: '{c} %' },
data: profiles.map((p) => ({
value: pct(p.primary_topic_matches, p.matched_works),
part: p.primary_topic_matches,
whole: p.matched_works,
})),
},
],
} as EChartsOption;
});
// chart 3: topic breadth — how many distinct (sub)fields the author publishes in
// chart 2: topic breadth — how many distinct (sub)fields the author publishes in
readonly breadthChart = computed<EChartsOption>(() => {
const profiles = this.orderedProfiles();
if (profiles.length === 0) return {};