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> 
Command icon 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

jastraat created an issue. See original summary.

jastraat’s picture

Status: Active » Needs review

timozura made their first commit to this issue’s fork.

timozura’s picture

Version: 1.0.x-dev » 1.10.0
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.