Skip to content

Conversation

@flavorjones
Copy link
Member

@flavorjones flavorjones commented Jan 22, 2026

Summary

Prevents draft cards from appearing in search results by guarding the search indexing callbacks. This is an alternative approach to #2408 — instead of filtering drafts at query time, this prevents them from being indexed in the first place.

Details

  • Adds searchable? to Card (returns published?) and Comment (returns true)
  • Guards create_in_search_index and update_in_search_index with searchable?
  • Publishing a draft indexes it; unpublishing removes the search record

The first commit is simply updating the existing search tests to use published cards. The second commit 17e47e2 represents the behavior change and includes new tests.

ref: https://app.fizzy.do/5986089/cards/3829

@flavorjones flavorjones force-pushed the filter-drafts-in-search branch 3 times, most recently from 2e04432 to 17e47e2 Compare January 22, 2026 21:39
@northeastprince
Copy link
Contributor

Would a script to remove any already-indexed ones be pertinent?

Copy link
Collaborator

@kevinmcconnell kevinmcconnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, @flavorjones!

I initially thought we should just filter the query on the card status, since we end up needing to fetch the cards to show the results anyway. I can't tell off-hand whether there's any practical difference in performance between the two approaches because of that.

But, the more I thought about it, I think what you're doing here is a more elegant approach in any case. There's no point in indexing something you aren't going to return! Neat idea.

if searchable?
search_record_class.upsert!(search_record_attributes)
else
remove_from_search_index
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way for a card to get "unpublished" back to draft, right? Because if we ever did that, I think any comments on the card would remain in the search index, is that right?

I think this doesn't matter in practice because we can't create comments until a card is published, and we can't un-publish a card. But I'm just checking :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinmcconnell You're correct, the UI does not allow setting cards back to draft once they're published. It doesn't look like it's possible via the API, either, since status is not a permitted parameter for the CardsController.

A related interesting edge case is that it's currently possible to add comments to a draft card via the API -- but I've got a separate branch that will address that gap shortly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to prevent comments on draft cards: #2423

@flavorjones flavorjones force-pushed the filter-drafts-in-search branch from 17e47e2 to bbce3ee Compare January 23, 2026 16:13
@flavorjones
Copy link
Member Author

@northeastprince Good idea, I've pushed an additional commit with a script to clean that up.

flavorjones and others added 2 commits January 23, 2026 12:13
Only index cards and comments if their card is `published?`, using a
new method `searchable?` that is implemented on both Card and Comment.
This prevents draft cards and their comments from being indexed.

When drafts are published, the existing `update_in_search_index`
callback creates the record via `upsert!`, or else ensures unpublished
records are removed from the index.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
One-time script to clean up any search records that were indexed
before the searchable? guard was added.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@flavorjones flavorjones force-pushed the filter-drafts-in-search branch from bbce3ee to a9c6bc2 Compare January 23, 2026 17:14
@flavorjones flavorjones merged commit dfa4875 into main Jan 23, 2026
12 checks passed
@flavorjones flavorjones deleted the filter-drafts-in-search branch January 23, 2026 17:17
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.

4 participants