Performance $pages->find vs $pages->findBy vs $pages->findByURI


I’m building a very large Kirby site 50 000+ pages and I wonder if there is any performance diff when finding a page by $pages->find vs $pages->findBy vs $pages->findByURI.

Would it for example be faster to use $pages->find so the server only need to read the folder names and not open every txt-file to look for a specific field value?

This is a really good question! I was not that “lucky” to test it out with 50k pages on Kirby – but I think that you can get the best performance by filtering your pages by specific blueprint fields before you hit a search. I’ve made the experience with this site and a few hundred articles, that it is way better for good performance and result quality to limit the fields that should be searched for.

So I do not recommend to search for flowing text elements like a text area or similar. You get much better results if you just search for the title, subtitle or tag fields.

This is how I did it on this page for the search results (and it’s working pretty fast).

$query = 'monkey';
$results = $site->search($query, 'title|subtitle|tags')
		->filterBy('template', 'in', ['default_article', 'blog_article'])
		->sortBy('modified', 'desc')->visible();

If you don’t want to manually add specific tags for every page, you could alternatively look for a good text analyzer service. There are many good ones (like TextRazor). We connected Kirby with the TextRazor API just by using Kirby Hooks on page update or save. After that you can perform a text post that should be analyzed and TextRazor will give you the most important and even additional keywords (based on an AI) that you can automatically save in a tags field.

Hope this solution is quite helpful for you :wink:

1 Like

Thank you for that info. We use Algolia for searches on the front and that is really really super fast! TextRazor or similar tools can be useful in the future.

I will try to run some test and post the results.

Just wanted to update this post and say that I never did run som test. We switched to ElasticSerch to store all the products and skipped to also have them saved as pages. The reason to switch from Algolia to Elasticsearch was just about the money. Algolia is really really great but also a bit expensive in the end…