Search results duplicate entries when using the editor plugin

Hi!

Is there a possibility to prevent duplicate entries in search results when using the editor plugin?

I think it’s the editor plugin which is causing the duplicate entries because of its block structure – like if a keyword is found in multiple <p> blocks for example (?).

The search controller is:

<?php
return function ($site) {
  $query   = get('q');
  $results = $site->search($query)->listed();
  $results = $results->not("home");

  return [
    'query'   => $query,
    'results' => $results,
  ];
};

And the output code is:

<a href="<?= $result->url() ?>">
    <?= Strip_tags($result->text()->blocks(), 0, 350) ?>
</a>

Thanks for any tips!

It would be more useful to see what is around that code block.

Ah ok, sorry

<ul>
  <?php foreach ($results as $result): ?>
    <li>
      <a href="<?= $result->url() ?>">
        <?php if($result->parents()->count() > 0): ?>
          <?php if($result->template() == "projekt"): ?>
            <?= t('project') ?>:&nbsp;
          <?php else: ?>
            <?= $result->parent()->title() ?>:&nbsp;
          <?php endif ?>
        <?php endif ?>
        <em>
          <?= Strip_tags(substr($result->text()->blocks(), 0, 350)); ?>
        </em>
      </a>
    </li>
  <?php endforeach ?>
</ul>

Some results have a template a parent page and some don’t. The duplicate entries have a parent page “projekte” and a template “projekt”. If I change the language (multi-setup) than the duplicates don’t occur, since the keyword doesn’t occur multiple times in the other language’s text.

That’s weird. What do you mean with duplicate entries, what is the actual result rendered in source from your original code?

The search results contain duplicates – like if a search query keyword submitted by a search input field is found multiple times in Page A, that Page A occurs multiple times in a search result list. The ul list containing the title and link to Page A is generated with the code above.

what is the actual result rendered in source from your original code?

Sorry, what do you mean by that?

But never mind, I will figure something out by changing the foreach loop and the if statements.