2

With the Search Plus plugin, it's possible to define a custom mapping of your Entries for your Algolia index. This is basically a two-part process:

  1. Call the searchPlus_addAlgoliaMapping to declare which function controls the mapping.
  2. Write the function which controls the mapping.

I've done both of these, and it's working very well. Here's an example of my mapping function...

return [
    'objectID' => $entry->id,
    'uri'      => $entry->uri,
    'title'    => $entry->title,
];

However, there are certain entries which should be excluded from the search index. My instinct tells me to simply wrap a conditional around that mapping, and return false (or null) for entries which should be excluded...

if ($entry->includeInSearch) {
    return [
        'objectID' => $entry->id,
        'uri'      => $entry->uri,
        'title'    => $entry->title,
    ];
} else {
    return false;
}

The problem is, this seems to cause an error when Search Plus tries to export to Algolia...

craft_searchplus_indexitem

Which leads to the question: What is the proper way to omit an entry from an Algolia index?

4

I've done this, and I believe the trick was to return true.

UPDATE: Looks like this was fixed in version 1.5.2, returning false will skip the entry as expected.

| improve this answer | |
  • Interesting... so you're saying I should return true instead of false? Seems counter-intuitive, but I'll give it a shot! – Lindsey D Jul 19 '17 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.