Blog Sections Open

Restricting AjaxSearch Results to Selected Parent Sections

A practical pattern for tying AjaxSearch to a category selector so search results stay inside the intended section of the site.

AjaxSearch becomes much more useful on large sites when it can search within a chosen section instead of across the entire content tree. the underlying example used a category selector to pass a parent resource into the search configuration and limit results accordingly.

Core idea

Instead of hard-coding one parent list, pass the selected parent ID from a form and feed it into the AjaxSearch configuration.

$dcfg['parents'] = $_POST['categoryList'];

Example form pattern

<select name="categoryList" id="categoryList">
    <option value="">All sections</option>
    <option value="11">Section 11</option>
    <option value="16">Section 16</option>
</select>

The practical challenge is preserving the selected value and keeping the form state consistent between requests. Once that is handled, AjaxSearch can behave like a scoped section search rather than a global lookup.

If the implementation starts becoming too heavy, that is also the point where it is worth reconsidering whether evoSearch or another search tool is a better match for the scale of the project.

Newer post

Using DLRequest to Drive DocLister Sorting and Display from GET and POST

How to build request-driven sorting, direction, and display controls for DocLister with DLRequest.

Older post

Installing Twig in Evolution CMS with Composer and EvoTwig

How to add Twig templating to Evolution CMS using Composer, EvoTwig, and a predictable file-based template workflow.