Full cross site search with rest api


I’m having trouble understanding the Rest API search.

The view/common/search-form.phtml returns the results of all the sites’ items and html blocks containing the search text.

How do I do the same with domain.com/api/... ?

Help is warmly welcome :slight_smile:

The search page simply searches on the items, item sets, and site page resources separately and returns those results together. Without specifying a specific site ID to filter by, searches on those resources will always return items across all sites by default.

Thanks for getting back :slight_smile:

Yes, I’ve read that piece of code.

I suppose my question really is, Does a full-cross-site-search rest api endpoint already exist as part of Omeka? And if so, What does it look like? I can’t find examples.


My comment was meant to say, the search form you referred to does multiple requests because that’s the only way to do it. There is no single endpoint for searching of “everything,” though most resource searches are inherently “cross-site” through the API unless otherwise specified (except of course the ones dealing with sites specifically).

Thanks for the pointers. I managed to build a custom endpoint. Works fine!


Well I thought it worked fine until I tried it without logging into the application.

Omeka\Mvc\Exception\PermissionDeniedException: Permission denied for the current user to access the index action of the MyModule\Controller\MyModuleController

I’ve been reading Laminas docs all day and am confused.

Maybe someone here could help me?

Thank you!

Hi @buttle, I think what you might need to specify that login isn’t required using something similar to the code snippet below in the onBootstrap method of your Module.php file:

     * Code to run when first using the module.
     * @param MvcEvent $event
    public function onBootstrap(MvcEvent $event): void

        $acl = $this->getServiceLocator()->get('Omeka\Acl');
        $acl->allow(null, ['MyModule\Controller\MyModuleController']);

Thanks for the help.

I added the resource. Otherwise it threw this error

Resource 'MyModule\Controller\MyModuleController' not found
use Laminas\Permissions\Acl\Resource\GenericResource as Resource;
$acl = $this->getServiceLocator()->get('Omeka\Acl');
$acl->addResource(new Resource('MyModule\Controller\MyModuleController'));
$acl->allow(null, 'MyModule\Controller\MyModuleController');

But I still get the same Permission denied error :frowning:

Could that be because MyModuleController class does not inherit GenericResource ?

I read here that a resource requires the function getResourceId()

I’d test that idea, but I’m not sure how to do multiple inheritance in php AbstractActionController + GenericResource


The two lines I shared work for me. I’m not sure why you would need to include the addResource method.

I think the one thing you’ll want to check is that you change ‘MyModule\Controller\MyModuleController’ to match what you have in your module.config.php for that module. It should be the key of the array and not necessarily the Controller class, which could be different. I was just trying to make my best guess from what you had shared.

'controllers' => [
        'invokables' => [
            'Omeka\Controller\Site\CrossSiteSearchController' => Controller\Site\CrossSiteSearchController::class,
$acl = $this->getServiceLocator()->get('Omeka\Acl');
$acl->allow(null, ['Omeka\Controller\Site\CrossSiteSearchController']);
1 Like

Yeah, it’s not uncommon for the keys to not match the class names in this case, and it is the key that’s used for the ACL lookup, not the class name.

My problem was I didn’t have the left side of the invokable declaration quoted to become a string.


Thank you very much.

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.