Skip to content

Commit 0444537

Browse files
Show message when article not yet indexed for similarity
When an article is too new to have a topic vector, show 'Svipaðar greinar verða tiltækar þegar greinin hefur verið flokkuð' instead of an empty list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a82e04f commit 0444537

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

routes/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ def similar() -> Response:
116116
return better_jsonify(**resp)
117117

118118
with SessionContext(commit=True) as session:
119-
similar = Search.list_similar_to_article(session, uuid, n=MAX_SIM_ARTICLES)
119+
similar, not_indexed = Search.list_similar_to_article(
120+
session, uuid, n=MAX_SIM_ARTICLES
121+
)
120122

121-
resp["payload"] = render_template("similar.html", similar=similar)
123+
resp["payload"] = render_template(
124+
"similar.html", similar=similar, not_indexed=not_indexed
125+
)
122126
resp["err"] = False
123127

124128
return better_jsonify(**resp)

search.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ def _new_client(cls) -> SimilarityClient:
7373
@classmethod
7474
def list_similar_to_article(
7575
cls, session: Session, uuid: str, n: int
76-
) -> List[SimilarDict]:
77-
"""List n articles that are similar to the article with the given id"""
76+
) -> Tuple[List[SimilarDict], bool]:
77+
"""List n articles that are similar to the article with the given id.
78+
Returns a tuple of (similar_articles, not_indexed) where not_indexed
79+
is True if the article has not yet been indexed for similarity."""
7880
client = cls._new_client()
7981
try:
8082
result = client.list_similar_to_article(uuid, n=n + 5)
83+
not_indexed: bool = result.get("not_indexed", False)
8184
articles: List[Tuple[str, float]] = result.get("articles", [])
82-
return cls.list_articles(session, articles, n)
85+
return cls.list_articles(session, articles, n), not_indexed
8386
finally:
8487
client.close()
8588

templates/similar.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{% if not_indexed %}
2+
<p class="similar-pending">Svipaðar greinar verða tiltækar þegar greinin hefur verið flokkuð.</p>
3+
{% elif similar %}
14
<ul id="similarlist">
25
{% for sa in similar %}
36
<li>
@@ -8,3 +11,4 @@
811
</li>
912
{% endfor %}
1013
</ul>
14+
{% endif %}

vectors/simserver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ def __init__(self, request: object) -> None:
369369
# Compare similarity to an article identified by UUID
370370
uuid = request["id"].strip().lower()
371371
topic = self.article_topic(uuid)
372+
if topic is None:
373+
result["not_indexed"] = True
372374
except:
373375
raise ClientError(request)
374376
elif "terms" in request:

0 commit comments

Comments
 (0)