Well that didn't really pane out how I thought. Seems like querying different records in that handlebars doesn't work, or at least I have not found a way to do it. Doing entities lookup on each item with the AJAX seems to be fail, if you hard code the liquid it does work though so its something with the handlebars that is stopping this. I tried moving the liquid logic to another web template and still had the same issue.
Here is another trick which should allow you to do it though, its not the greatest probably for performance as it is resulting in a lot of requests, an extra for each result. So since this is handlebars we can register a helper that will then make an jquery ajax call which will call a web template with your liquid logic to get the data you want. There might be a better way to this, everyone feel free to improve.
Let's start with creating a new web template that has the logic of what you want to add to each result. My template is fairly simple, you could add additional parameters like logical name as well. You could put whatever logic you wanted in here, have like a switch case for the different result types, etc.
{% assign eid = request.params['entityid'] %}
{% assign wpage = entities.adx_webpage[eid] %}
<p><strong>Name:</strong> {{wpage.adx_name}}</p>
Once created, now create a page template that uses this web template, ensure that you untick the "Use Website Header and Footer" as all we want out of this is the HTML you want to add to each result. Now add a web page that uses this page template. You can test it by hitting the URL manually, ie. /search-details/?entityid=94216ad7-7864-e611-80d7-00155db4fa48, I just pulled some random page ID.
Now we need to register our handlebars helper. Go to the search page in the site (run a search), make sure you are logged in with an account that as front-side editor (or you can add this via CRM). On the search page select the Edit from the editor control, go to the Options tab and add the following to the custom JavaScript.
Handlebars.registerHelper("search_details", function (obj) {
return $.ajax({
url: "/search-details/?entityid=" + obj.fn(this),
type: "GET",
async: false
}).responseText;
});
You will need to modify the URL for your web page that you setup.
Now head over to the web template for the results rendering - "Faceted Search - Results Template". Within the {{#each items}} where you want the details located add
{{#search_details}}{{entityID}}{{/search_details}}
Here is what my complete each looked like:
{{#each items}}
<li>
<h3><a title="{{title}}" href="{{url}}">{{title}}</a></h3>
<p class="fragment">{{{fragment}}}</p>
{{#search_details}}{{entityID}}{{/search_details}}
<div>
{{#each tags}}
<span class="{{cssClass}}">{{./label}}</span>
{{/each}}
</div>
</li>
{{/each}}
Save, refresh search result and there should be your extra data as part of each result!
Remember to give entity permissions on the entities you query with liquid.
The thing that is really not great about this is the fact that an extra request will be made for each result. You can debug this and see the extra requests in the browser tools network tab. I will still look for a better way to do this but this is currently what I have working.