Value from extended pageModel in search?

Hi,

i have a pageModel where i define a new value. is it possible to be able to search for this new value inside $site->search() ?

class PartyPage extends Page {
  public function partyname() {
	$partyName = 'foo';
	return $partyName;
  }
}

i am able to output this new value but i can’t search for it.
Kirby Version is 3.6

In K4, the core search only searches the content, not calling methods on the item. I would say it was the same in K3. You could try creating your own search component based on the core one and change that behaviour.

Using an external service like Algolia and GitHub - johannschopplich/kirby-algolia-docsearch: 🔦 Index and search your Kirby site with Algolia DocSearch you could define the content on the fly.

site/config/config.php

return [
    'johannschopplich.algolia-docsearch' => [
        // Return any string which should be indexed
        'content' => [
            'default' => fn (\Kirby\Cms\Page $page, string|null $languageCode) => strip_tags($page->text()->toBlocks()->toHtml())
            'home' => fn (\Kirby\Cms\Page $page, string|null $languageCode) => $page->description()->value()
        ]
        // other options …
    ]
];

Thanks @bnomei , this looks like a little bit to much for my skills.

Maybe i can update all pages to get my value directly in the content. :frowning:

Or you could overwrite the content method in your page model, and add a new field with this value to the content

hey, could you point me in a general direaction on how to do that?


class PartyPage extends Page {
    public function partyname() {
	$partyName = 'foo';
	return $partyName;
    }
  
    public function content(string|null $languageCode = null): Content
    {
		// single language support
		if ($this->kirby()->multilang() === false) {
			if ($this->content instanceof Content) {
				return $this->content;
			}

			// don't normalize field keys (already handled by the `Data` class)
			return $this->content = new Content(array_merge($this->readContent(), ['newField' => 'newValue']) , $this, false);
		}
    }

}

Something like this, merging the content from the content file with an array of extra values (I left out the multi-lang part of the original method)

Thank you, i will try this way first.