0

I have Search API installed, and have indexed all of my nodes.

The nodes all have a different Author, and the Authors have roles "Free user", and "Business User".

I only want the nodes belonging to Business Users showing up in search.

I created a view, the search works perfectly on indexed fields, but I cannot filter by Author:Role

I have added a relationship of Indexed Node: Author, but still no filter available.

Anyone know how I can achieve this?

1

You need to index the author's roles so that Search API can query that field.

Visit the fields configuration page for your node index (probably admin/config/search/search_api/index/default_node_index/fields if you're using the default node index). At the bottom of the list of fields you'll see a fieldgroup called "add related fields". Expand that, choose author, click "add fields".

When the page reloads your big list of fields will now contain a bunch of new Author-related fields including Author » User roles. Check the box next to that one, choose how you want it indexed (integer or string are probably the only ones you'd care to use for this purpose), save your changes, and re-index your content.

I've found that with these sorts of changes I need to clear my cache twice in order for the proper data to be registered with Views and for the appropriate filters to appear in my Views.

  • Ah! Awesome. Thank you so much. I knew it needed to be indexed for it to be used in views, but I couldn't figure where to grab the user role. – Collins Sep 18 '15 at 9:26

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.