Displaying user data in query results

How to display a message along with the query result. In algolia docs, there is a consequence named Display Info. The link is provided below-

https://www.algolia.com/doc/tutorials/query-rules/query-rules-how-to-implement-segmentation/#use-case---age-groups

But I don’t have an option of display info in the consequences. So how can i display message along with the query results by using return Custom Data option in the consequence.

Hi @Rochelle, doing so depends on what kind of integration, language or framework you are using with Algolia.

Return custom data is here to transform a regular list of results received from Algolia:

{
  hits: [{
    objectID: '...',
    name: 'hello'
  }]
}

into:

{
  userData: {
    bannerImage: 'http://...'
  },
  hits: [{
    objectID: '...',
    name: 'hello'
  }]
}

So that then on your frontend search website, you can interpret the results in a way that will display specific information defined in your query rules consequences.

Let us know how it goes and if you have further questions please give us the tools you are using along with Algolia, for example if you are using shopify, wordpress, magento etc…

Thankyou so much for your instant response. But I don’t know how to display banners along with the search results for a particular query alone. In the following link banner is being attached to the query results using Display Info consequence.

https://www.algolia.com/doc/tutorials/query-rules/query-rules-how-to-implement-segmentation/#use-case—age-groups.

But in my algolia dashboard there is no such consequence named Display Info. I have attached screenshot of this, please find that.!

algoliaConfluenceIssue |690x387 So now how should i display banner… Can you suggest me with a solution.

Hi @vvo, i am able to see the userdata value in the network tab when i create a query rule and it is in this format -
{“message”:“Diwali sale is on”,“blink”:“true”,“url”:“https://www.google.com/”}.
So could you tell me how i can fetch this message value in magento 2 enterprise edition. If possible can you please provide me with some useful links where this kind of issue is addressed

Hi @Rochelle, you can customize magento 2 instantsearch experience like this https://community.algolia.com/magento/doc/m2/customize-instantsearch/.

And add a custom widget that will read this userData property like this Using "Display Specific Info" Query Rules with InstantSearch.js. How do you display?.

Let us know how it goes.

Hey @vvo , I have added a custom widget in the instantsearch.js and made use of the render function to display the userData. But The problem I am facing now is that, for that particular message which i have entered in the custom data, I should return an associated Static block in magento2.
But the problem is i have the userData in frontend(which is the js file) but after fetching this value I have to fetch the associated Static Block from Magento Backend(i.e a block class).Could you please let me know how to render the associated static block for the userData which is fetched in js.