Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Integrate a Hook to customize searched Pages in \ModuleSearch #5223

Closed
JohannesFerner opened this issue Jan 8, 2013 · 15 comments
Closed

Integrate a Hook to customize searched Pages in \ModuleSearch #5223

JohannesFerner opened this issue Jan 8, 2013 · 15 comments

Comments

@JohannesFerner
Copy link

Hello,

Problem:
you can not modify the searched Pages from \ModuleSearch

Solution:
as you can see in https://gist.github.com/4482409/5e7273acc3fdec713cd256797075a82987776b94#file-gistfile1-php-L125 i have added a Hook in the /system/modules/core/modules/ModuleSearch.php in order to customize the pages searched in the module.

Maybe a Hook-Name like 'getSearchedPages' or something like that would be better.

Zusätzlich:

// unterhalb des Hooks
// oder in  /system/modules/core/library/Contao/Search.php#487
array_unique($arrPages);

Why?
I have a multidomain project, where i want to enable the search over all of my root-pages.
If this Hook is integrated I'm able to develop a CrossSiteSearchModule.

@leofeyer
Copy link
Member

@contao/workgroup-core

@aschempp
Copy link
Member

Sorry, but that does not make sense. That is a custom extension case.

Check out https://github.com/aschempp/contao-rootsearch for a hint. The module might be outdated, not sure if it works in your installation.

@JohannesFerner
Copy link
Author

@aschempp Yes it is a case for an extension, but i need the hook, otherwhise i can't manipulate the data
Edit: this way i can inherit from \ModuleSearch otherwhise than to C&P the search Extension and add the sites i want to be searched.

@aschempp
Copy link
Member

Well you need to add the sites anyway, not? The search module is only a front end to the search engine library class, every custom frontend module can use the search engine class.

@JohannesFerner
Copy link
Author

The Sites are in the Index, but they are from another Page-Root, so the \ModuleSearch would automatically only include all the Sites of the currently visited Root-Page.

To make it search across all my Root-Pages i have to add the Sites here.

@aschempp
Copy link
Member

Have you checked out my extension? It does exactly what you need (search over multiple root sites)...

@JohannesFerner
Copy link
Author

** I've to correct my statement from above, that it should be in an own extension, i mean only "mini-extension" giving the Sites I wan't to be searched to the \ModuleSearch, so I dont't have to rewrite the whole module (as you did in Root-Search). i only add my Sites in a Hook and the Module takes all the Sites I want to have searched into account

So my "Root-Search" would only add all Site-ID's in the \ModuleSearch

I'll upload my code later, I have already integrated this in a project

@aschempp
Copy link
Member

Ok. So if we are going to do something, we should change the module so that the individual functionalities are in separate methods, and your new extension can simply override them.

@leofeyer what do you think? Want a pull request?

@JohannesFerner
Copy link
Author

That would be best case, so I've got a method to override, which only populates the sites-id data.
The Rest of module is inherited from the core-module and I'm upgrade-safe.

@aschempp
Copy link
Member

@leofeyer what is your opinion?

@JohannesFerner
Copy link
Author

In my locally integrated HOOK i just use the following code to implement a Search-Module, which is taking all Sites into account.

<?php

class EnhancedSearch extends \Controller
{
    public function customizeSearch($arrPages)
    {
        // Modify the Pages
        $allPages = \Database::getInstance()->prepare('SELECT `id` from tl_page where pid != 0')->execute();

        while($allPages->next())
            $arrPages[] = $allPages->id;

        array_unique($arrPages);

        return $arrPages;
    }

}

@leofeyer
Copy link
Member

Would #6792 also solve this issue?

@leofeyer
Copy link
Member

Implemented in e77d3fa.

@katrinhaertl
Copy link

shouldnt there be a return value?
$arrPages = $this->$callback[0]->$callback[1]($arrPages, $strKeywords, $strQueryType, $blnFuzzy);
Otherwise I dont know how to use that hook.

@Toflar
Copy link
Member

Toflar commented Dec 4, 2014

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants