Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rely on searchcontext scaffolding instead of creating search query by hand #7

Open
micschk opened this issue Dec 10, 2024 · 0 comments

Comments

@micschk
Copy link

micschk commented Dec 10, 2024

The current construction of the searchquery assumes a 1:1 field mapping and fails in case of 'match_any' search (across fields). Instead of trying to construct a full searchquery by hand it would be better to simply rely on searchcontext to resolve this.

OP\SearchController:

    [...]
    public function buildsearchquery(HTTPRequest $request)
    {
        $SearchedDataObject = Injector::inst()->create($request->getVar('ClassName'));

        // check for a first-name last-name pattern with people's names
        [...] (think this members-search could/will also be covered by scaffolded searchcontext)

        // Search using searchcontext scaffolding...
        /** @var SearchContext $searchContext */
        if ($searchContext = $SearchedDataObject->getDefaultSearchContext()) {
            $searchParams = [ $SearchedDataObject->getGeneralSearchFieldName() => $request->getVar('query') ];
            return $searchContext->getResults($searchParams);
        }
        
        [...] (DONE - remaining code can probably be removed...)

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

No branches or pull requests

1 participant