nexuspolaris Posted December 29, 2023 Share Posted December 29, 2023 Hello! I build a multisite website with same database based on this module : https://github.com/somatonic/Multisite/ and the skyscraper profile. On the main page I can search for local companies by regions. The search results are listed on the Search page. This is my page structure: - Web -- Regions --- Region-1 ---- Company-1 ---- Company-2 ---- Company-3 --- Region-2 ---- Company-4 ---- Company-5 ---- Company-6 -- Search -- Site-1 --- Search -- Site-2 --- Search The search form template is pointed to the root's Search page: <form method='get' action='<?php echo $config->urls->root?>search/'> In the config.php multisite settings: $config->MultisiteDomains = array( "site-1" => array( "root" => "Site-1", "http404" => 27 ), "site-2" => array( "root" => "Site-2", "http404" => 5332 ) ); $config->httpHosts = array('site-1', 'site-2'); I copied the same search form from the root's page (Web) to the Site-1 or Site-2 page and the search results are listed in the root's search page: http://root-domain/search instead of http://site-1/search or http://root-domain/site-1/search What is the best method to point the search result page to the Site-1 or Site-2 children 'Search' page? Link to comment Share on other sites More sharing options...
gornycreative Posted December 30, 2023 Share Posted December 30, 2023 Not sure I fully understand your question, but the search results page is simply a page with a template that sanitizes your search form and runs a find on it (or if you use the SearchEngine module you have additional options). Take a look at templates/search.php and you will see a basic model. <?php namespace ProcessWire; // look for a GET variable named 'q' and sanitize it $q = input()->get('q'); // sanitize to text, which removes markup, newlines, too long, etc. $q = sanitizer()->text($q); // did $q have anything in it after sanitizing to text? if($q) { // Make the search query appear in the top-right search box. // Always entity encode any user input that also gets output echo '<input id="search-query" value="' . sanitizer()->entities($q) . '">'; // Sanitize for placement within a selector string. This is important for any // values that you plan to bundle in a selector string like we are doing here. // It quotes them when necessary, and removes characters that might cause issues. $q = sanitizer()->selectorValue($q); // Search the title and body fields for our query text. // Limit the results to 50 pages. The has_parent!=2 excludes irrelevant admin // pages from the search, for when an admin user performs a search. $selector = "title|body~=$q, limit=50, has_parent!=2"; // Find pages that match the selector $matches = pages()->find($selector); } else { $matches = array(); } In the end you have a $matches array returned by the find() method. But you could create different search pages to represent different form actions and filter the results to be what you wish on the respective processing template. So for example you might modify your $selector to only include descendents of a certain branch, or certain templates unique to a single site, etc. If you are not familiar with the power of selectors, this is a key place where you will want to dig deep: https://processwire.com/docs/selectors/ Does that make sense? There isn't anything really special about the search page aside from the sanitizing and find() functions found in the template file. By setting your own search form action pages (multiples if you wish) with different page templates you can create topical search engines or whatnot. I guess my point is that you aren't limited to just one search template, or one search action URL. If it was me, I'd probably create separate search templates for each site, dedicate a page under each site tree for each, and point the forms on the respective sites to the respective search pages. Both forms will process find against the same page tree, but you can filter the find selector in advance, adding whatever query post gets sent from the form. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now