cms icon indicating copy to clipboard operation
cms copied to clipboard

Search indexes unpublished items (Algolia)

Open fitzage opened this issue 3 years ago • 1 comments

Bug description

I'm building out indexing for a client who currently has a lot of unpublished items in one collection. Due to the large discrepancy in number of entries vs the records that showed up in Algolia, I realized that when I submit my search index to Algolia it's indexing all the unpublished entries.

This will certainly create an issue when content that shouldn't yet be public starts showing up in the search index.

How to reproduce

  1. Set up Algolia indexing following the Statamic guide.
  2. Index collection with unpublished items.
  3. Unpublished items get sent to Algolia.

Logs

No response

Versions

Statamic 3.2.32 Pro Laravel 8.83.0 PHP 8.0.14 aryehraber/statamic-font-awesome 2.2.0 optimoapps/statamic-bard-text-align 1.0.2 statamic/seo-pro 2.3.2 statamic/ssg 0.9.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

fitzage avatar Feb 09 '22 04:02 fitzage

Hey @fitzage,

I had the same issue. What I ended up doing is the following:

  1. Add the "status" field to your index. You can do that in /config/statamic/search.php under indexes->default->fields. Add "status" to that array.

  2. Add status to the "attributes for faceting" in the Algolia search ui:

image
  1. Configure your javascript algolia driver (in my case vue instant search) to only show "published" entries:

image

It's basically what @riasvdv suggested here: https://github.com/statamic/cms/discussions/5200

Hope this helps!

markussorg avatar Jul 11 '22 16:07 markussorg

In 3.4, draft entries will not be indexed. Additionally, you can filter out entries however you want. #6318

jasonvarga avatar Jan 24 '23 20:01 jasonvarga