Search returns results twice

Hi! I’m prototyping search for a small site. Nothing fancy, just following the recipe from the cookbook. Currently only searching through page titles.

The weird thing is however, that in some instances I get results back twice (Even when only searching the title field); and in other cases I just get the expected single result…

here’s a var_dump of the $results:

object(Kirby\Cms\Pages)#428 (2) { [0]=> string(22) "content/works/4-d-news" [1]=> string(14) "works/4-d-news" }

so the first item in the collection includes the content/ and the second one doesn’t. Any thoughts on what might be going on here?

That’s a weird result, a collection of pages usually doesn’t have the content part in the id.

What is your Kirby version and what plugins do you have installed? If not plugins, other custom code?

Hey @texnixe! Currently running Kirby 3.4.4, installed through Composer. editor and kirby-color are installed as plugins…

Just tried with both plugins removed, same behaviour.

Here’s my search controller:

<?php

return function ($site) {

  $query   = get('q');
  $results = $site->search($query, 'title')->listed()->filterBy('template', 'work');

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

};

Hmm… :thinking: If use page('works')->search(...) (the parent of the work pages) I have the intended behaviour (each page being returned only once). Doesn’t change the output of $site->search(...), but now the search behaves as expected. So I guess that’s my solution for now…

Hm, it’s still weird and I can’t reproduce this in my test project.

@texnixe I found the source of the confusion. Turns out that there was a copy of the content folder inside the content folder. Probably something that went wrong while configuring rsync for deployment. So, problem solved :slight_smile:

Thanks for reporting back. That explains it.