Problem/Motivation
Currently parsed search results only include htmlTitle, link, and snippet. Even basic website indexing can include additional data however. For example, if the sitemap for the site includes pagemap data, that data may be contained in the derived structured data.
[
'name' => 'projects/....,
'id' => '0',
'derivedStructData' => [
'pagemap' => [ pagemap data here ],
'link' => '/',
'htmlTitle' => 'Title',
'formattedUrl' => '/',
'title' => 'Title',
'snippets' => []
]
In addition, advanced website indexing allows for structured data, and if present, it would be great to be able to include this in the result templates.
Proposed resolution
This could be accomplished by adding something like the following to the buildResults() function in VertexAISearch.php:
if (isset($result['document']['structData']) && is_array($result['document']['structData'])) {
foreach ($result['document']['structData'] as $key => $value) {
$parsedResult[$key] = $value;
}
}
This should have no impact on sites without structured data and would allow sites with structured data to override the theme template for results and include structured data. Here's an example with a structured data array called 'articleSection'.
{% set title_markup = [{'#markup': result.htmlTitle|render}] %}
{% set snippet_markup = [{'#markup': result.snippet|render}] %}
{% set article_type = [{'#markup': result.articleSection[0]|render}] %}
<div class="result">
<div class="type">{{ article_type }}</div>
<div class="title"><a href="{{ result.link }}">{{ title_markup }}</a></div>
<div class="snippet">{{ snippet_markup }}</div>
</div>
Issue fork vertex_ai_search-3588686
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jastraat commentedComment #6
timozura commented