Displaying "direct content" from ChatBar AI-Search
If your AI-Search instance has Direct Content enabled, then queries that match that content result in it being sent directly to the user without further processing or interpretation by the AI mode.
As an example, say you have a YouTube video of your latest book review, you can load that embedded video as direct content. Should the visitor ask "What was your latest book review?", then that direct content, ie. the embedded YouTube video will be returned with the search results.
It is then up to the website to describe how, or even if at all, the direct content is shown. This is easily handle within the searchResultsCallback as shown in the example below. This callback checks the search results for any search result with the property direct_content set, and if that search result is the best match it displays that content directly as a answer to the users query.
searchResultsCallback = function(sr) { if (!showSearchLinks || !sr.length) return; // Sort search results by score sr.sort((a, b) => a.score - b.score); // Check if the last, ie. best, result has direct content let last = sr[sr.length - 1]; if (last.hasOwnProperty("direct_content")) { const el = _bl_ai_search.appendChatResponse(last.direct_content, false); // Remove previous "thinking" message let prev = el.previousElementSibling; if (prev && prev.classList.contains("_bl_ai-response")) prev.remove(); // Filter out results with direct content sr = sr.filter(x => !x.hasOwnProperty("direct_content")); } };