0

My content node includes a verified checkbox that's marked by a human reviewer who then also enters a date. The node is verified only when the box is checked and the date is entered. A content node may be published before it is verified.

How can I keep an unverified content node from appearing in search API results?

One solution is to add a search API exclude entity field to the content node and to set the value of the exclude field in a presave hook based on the verified checkbox and date. This isn't difficult, but it seems there should be a more straightforward way of accomplishing what's needed.

I've looked at modules, but those I've seen don't seem to fit the need. I imagine I'm just missing something obvious, but what is it?

I don't think it's relevant, but I'll mention that I'm using Solr search.

0

Given no alternative answers, I solved this problem by

  • installing the Search API Exclude Entity module
  • adding a field of type Search API Exclude Entity named search_exclude to the content node
  • adding the following to my custom rsc module

    function rsc_node_presave(EntityInterface $node) {
      switch ($node->getType()) {
        case 'content':
          $node->field_search_exclude->value = <conditions to exclude node>;
          break;
      }
    }
    
  • going to /admin/config/search/search-api/index/default_solr_index/processors

  • checking the Search API Exclude Entity box
  • selecting the Search API Exclude Entity tab at the bottom of the page
  • checking the field_search_exclude (content) box
  • reindexing the content

Seems to be working well. When unverified nodes are saved, the search_exclude field is set and that keeps the nodes out of the search results.

| improve this answer | |

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.