Can one increase the numer of search results from 10 to 25

Core Version - 8.5.9
PHP Version - 7.0.33

Dear Community,
I have used Google what feels like 100 times, but have not found a solution. How can I increase the number of search results from 10 to (for example) 25, if I use the normal search block? This must be specified somewhere. I even have already searched for the number “10” in the core data - without success.
I would be very happy to receive an expert tip.
Best
Mathias

You could override the search block controller and modify it according to your needs. Copy the following code and put it in a file application\blocks\search\controller.php on your server

<?php

namespace Application\Block\Search;

use Concrete\Block\Search\Controller as CoreSearchController;

use CollectionAttributeKey;
use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Page\PageList;
use Core;

class Controller extends CoreSearchController
{
    /**
     * Perform the search.
     *
     * @return null|false
     */
    public function do_search()
    {
        $query = (string) $this->request->request('query');

        $ipl = new PageList();
        $ipl->setItemsPerPage(25);

        $options = $this->request->request('options');
        if ($options) {
            //Overrides search all settings with user submitted option
            if ($options === 'ALL') {
                $ipl->setSiteTreeToAll();
            }
        } else {
            //If options are not send by user then use default options from the block settings.
            //If Search All is enabled set search site tree to all.
            if ((int) $this->search_all === 1) {
                $ipl->setSiteTreeToAll();
            }
        }

        $aksearch = false;
        $akIDs = $this->request->request('akID');
        if (is_array($akIDs)) {
            foreach ($akIDs as $akID => $req) {
                $fak = CollectionAttributeKey::getByID($akID);
                if (is_object($fak)) {
                    $type = $fak->getAttributeType();
                    $cnt = $type->getController();
                    $cnt->setAttributeKey($fak);
                    $cnt->searchForm($ipl);
                    $aksearch = true;
                }
            }
        }

        if ($this->request->request('month') !== null && $this->request->request('year') !== null) {
            $year = @(int) ($this->request->request('year'));
            $month = abs(@(int) ($this->request->request('month')));
            if (strlen(abs($year)) < 4) {
                $year = (($year < 0) ? '-' : '') . str_pad(abs($year), 4, '0', STR_PAD_LEFT);
            }
            if ($month < 12) {
                $month = str_pad($month, 2, '0', STR_PAD_LEFT);
            }
            $daysInMonth = date('t', strtotime("$year-$month-01"));
            $dh = Core::make('helper/date');
            /* @var $dh \Concrete\Core\Localization\Service\Date */
            $start = $dh->toDB("$year-$month-01 00:00:00", 'user');
            $end = $dh->toDB("$year-$month-$daysInMonth 23:59:59", 'user');
            $ipl->filterByPublicDate($start, '>=');
            $ipl->filterByPublicDate($end, '<=');
            $aksearch = true;
        }

        if ($query === '' && $aksearch === false) {
            return false;
        }

        if ($query !== '') {
            $ipl->filterByKeywords($query);
        }

        $search_paths = $this->request->request('search_paths');
        if (is_array($search_paths)) {
            foreach ($search_paths as $path) {
                if ($path === '') {
                    continue;
                }
                $ipl->filterByPath($path);
            }
        } elseif ($this->baseSearchPath != '') {
            $ipl->filterByPath($this->baseSearchPath);
        }

        $cak = CollectionKey::getByHandle('exclude_search_index');
        if (is_object($cak)) {
            $ipl->filterByExcludeSearchIndex(false);
        }

        $pagination = $ipl->getPagination();
        $results = $pagination->getCurrentPageResults();

        $this->set('query', $query);
        $this->set('results', $results);
        $this->set('do_search', true);
        $this->set('searchList', $ipl);
        $this->set('pagination', $pagination);
    }
}

The line $ipl->setItemsPerPage(25); lets you set the number of results per page. The pagination will appear as needed.

1 Like

@mnakalay Strange. i was trying to modify by adding that line as well and couldn’t seem to get results. I’ll have to take a closer look at what you did here…

Edit: I was inserting it just before $pagination = $ipl->getPagination();…

@enlil it works the way you did it. Did you remember to modify the namespace at the top to be Application instead of Concrete and extend the original core controller?

No I was just messing in the core block files. Probably a cache issue at the time. Figured that HAD to be the answer!

Where’s the “I’m amused” emoji when you need it :yum:

Cool. It works great.
Finally I am even able to sort and filter the results by using this modified file.
Thank you so much!!!

Best
Mathias