Skip to content

Apply the avoid filters to saved searches and topic browsing - #754

Open
mircealungu wants to merge 1 commit into
masterfrom
fix/708-avoid-filters-on-saved-searches
Open

mircealungu wants to merge 1 commit into
masterfrom
fix/708-avoid-filters-on-saved-searches

Conversation

@mircealungu

Copy link
Copy Markdown
Member

Fixes #708.

Symptom

An article reached a learner's home feed through a saved-search subscription even when it matched their "Topics to Avoid" list, was classified as disturbing, or both. The organic half of the feed honors both settings; the search-injection half did not, so this only affected learners with a subscription.

Fix

build_elastic_search_query now takes the avoid-keyword list and the disturbing flag and applies the same must_not clauses build_elastic_recommender_query already does. article_and_video_search_for_user was already computing both and then dropping them — it now passes them through, which covers the feed injection, the subscription preview and the subscription emails in one go. topic_filter_for_user applies them too.

The two settings differ in what a learner can override:

  • Avoid-keywords yield in exactly one place: a term typed into the search box. That is an explicit instruction now, and it outranks a preference set earlier. Everywhere we search on the learner's behalf, the block wins — someone who avoids trump and subscribes to iran did not ask for the intersection.
  • Disturbing content yields nowhere. It is a setting a teacher or a parent may have made on a school account, and a setting a learner can switch off by searching is not a setting.

Also fixes a TypeError in topic_filter_for_user, which called Language.code as a method although it is a column — the function raised before reaching any of its query.

Tests

zeeguu/core/test/test_avoid_filters_on_searches.py. The ones that matter go through the real article_and_video_search_for_user and topic_filter_for_user with a real user and read the query that actually reached Elasticsearch, since the gap was never in the builder but in the caller dropping what it had computed. All seven fail against the code before this change.

Full suite green before and after (597 → 605 passed, 1 skipped).

🤖 Generated with Claude Code

A saved-search subscription injected articles into the home feed through a
query that applied neither the learner's "Topics to Avoid" keyword list nor
their "Avoid disturbing news" setting, so an article matching a subscription
appeared however it was classified and whatever it mentioned. Browsing a
single topic had the same gap. Both filters are honored on the organic half
of the feed, which is why this only showed up for subscribers.

build_elastic_search_query now takes the two exclusions and applies the same
must_not clauses build_elastic_recommender_query does.
article_and_video_search_for_user had already computed both and was dropping
them; it now passes them on, so the feed injection, the subscription preview
and the subscription emails are all filtered. topic_filter_for_user applies
them too.

Where the two settings differ is what a learner can override. The keyword
list yields to a term typed into the search box, which is an explicit
instruction outranking a standing preference -- the one caller passing
honor_avoid_keywords=False. The disturbing-content filter yields to nothing:
it is a setting a teacher or a parent may have made, and one a learner can
switch off by searching is not a setting.

Also fixes a TypeError in topic_filter_for_user, which called Language.code
as a method although it is a column -- the whole function raised before
reaching any of its query.

Closes #708

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

ArchLens - No architecturally relevant changes to the existing views

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saved-search subscriptions bypass "Topics to Avoid" and "Avoid disturbing news" filters

1 participant