Conditional attributes in hits?

Is it possible for the attributes displayed in search results/hits to differ based on the search query?

For example if I was replicating an Amazon-style search, could the hits show a ‘runtime’ attribute if the search was for DVDs but a ‘pagecount’ attribute if the search was for Books?

Very basic example but hopefully illustrates what I’m getting at.

Yes you can achieve that, just store all your products in the same index, have a product_type field in them and then on your frontend, based on product_type, change the displaying.

That sounds like displaying different products.

Let’s say I have a running shoe: “Nike AirZoom Pegasus”

Among it’s attributes, it has:
{activity} = “Running”
{colour} = “Green”

If someone has filtered a search with the “Sportswear” category, I’d like the {activity} attribute to be displayed. But if the search is filtered with “Fashion”, I’d like the {colour} attribute to be displayed.

Is that clearer?

My point being that individual records can have lots of information, but it doesn’t always make sense to display them - depending on the searcher’s intent.

Yes this is clearer, to do so you will have to conditionally check in your hits rendering method (depends on what you’re using to display your search UI: InstantSearch?) what’s the activated filter.

The way to do so depends on what you’re using to build your search UI. If you’re using InstantSearch.js for example this would be done by using the hits widget here: https://www.algolia.com/doc/api-reference/widgets/hits/js/ with a function as for the template.

And in the function, you would use the helper state (var search = instantsearch…; helper is search.helper) to check for the current applied filters (helper.state).