Overriding default search with Advanced Search and SearchSolr

We’d like to make solr search the default for the searchbar within pages.

by overriding the view/common/search-form.phtml file in the default theme we’re able to change the query from ?fulltext_search to ?q and then if I manually override the action of the form to point to a pre-defined solr-search page that I created in the search manager then I can get it pulling results from solr, but I can’t work out how to override that action.

switch ($searchType) {
    case 'cross-site':
        $searchAction = $this->url('site/cross-site-search', ['action' => 'results'], true);
        break;
    case 'sitewide':
    default:
        $searchAction = $this->url('site/resource', ['controller' => 'index', 'action' => 'search'], true);
}

If, in the search manager, I set the slug for my solr search to index/search to override the default search, any calls to it fail with the logs stating:

2024-12-19T15:00:38+00:00 ERR (3): Laminas\Router\Exception\RuntimeException: Route with name "search-page-index" not found in /home/sunny/Documents/omeka/omeka_dev/omeka-s/vendor/laminas/laminas-router/src/Http/TreeRouteStack.php:364

but I also can’t work out how I need to edit the $this->url() call in search-form.phtml in order for my default search bar to render with the form action “/s//solr-search”.

Any help would be greatly appreciated.

@sunny.moon-schott ,

There might be a better way to do this, but you don’t really need to use the $this->url() helper. You could just set the action for the default case and change the input name to q in the form.

default:
        $searchAction = $this->site->url().'/solr-search';

Using this approach, I did have to add the search page to my navigation on every site.

Interesting, I’ll give that a go, thanks!

Worked perfectly, thanks! You’re a star!

1 Like