Restructured the glmSearch.php class to be able to search multiple specific sites...
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 5 Aug 2016 18:45:30 +0000 (14:45 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 5 Aug 2016 18:45:30 +0000 (14:45 -0400)
Updated the management search setup form to inform the user how to enter the websites to do this.

classes/glmSearch.php
views/admin/management/search.html

index deda4f0..ee79ecc 100644 (file)
@@ -194,7 +194,7 @@ class GLMSearch
 \r
         // If there's a problem with Filter and validate supplied parameters\r
         if (\r
-            ($website = filter_var($website, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false ||\r
+            (trim($website) != '' && ($website = filter_var($website, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) ||\r
             ($login = filter_var($login, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false ||\r
             ($key = filter_var($key, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false\r
         ) {\r
@@ -277,37 +277,63 @@ class GLMSearch
         // If host filter has not been turned off, set filter to only search the specified Website in the index\r
         if ($this->filter) {\r
 \r
-            // Determine if there's a specific filter type and value - Default to host:\r
-            $query = '';\r
-            if (trim($this->website) != '') {\r
-                $query = 'host:"'.$this->website.'"';\r
+            $this->request['filters'] = array();\r
+\r
+            // Build a list of Websites provided in the management Website field (comma separated)\r
+            $sites = array_filter(explode(',', $this->website ));\r
+\r
+            // Add each Website to the positive query filter\r
+            if (count($sites) > 0) {\r
+\r
+                $addHosts = '';\r
+                $blockHomepages = '';\r
+                $customFilter = '';\r
+                $sep = '';\r
+                foreach ($sites as $site) {\r
+\r
+                    $site = trim($site);\r
+\r
+                    // Build string to include sites\r
+                    $addHosts .= $sep.'host:"'.$site.'"';\r
+\r
+                    // Build string to block homepages\r
+                    $blockHomepages .= $sep.'url:"http://'.$site.'/"';\r
+\r
+                    if ($this->filterType && !$this->filterValue) {\r
+                        $customFilter .= $this->filterType.':"'.$site.'"';\r
+                    }\r
+\r
+                    $sep = ' ';\r
+\r
+                }\r
+\r
+                $this->request['filters'][] = array(\r
+                    "type" => "QueryFilter",\r
+                    "negative" => false,\r
+                    "query" => $addHosts\r
+                );\r
+\r
+\r
+                // If excluding the home page contents, add a negative filter for that for this site\r
+                if ($this->exclude_home_page) {\r
+                       $this->request['filters'][] = array(\r
+                        "type" => "QueryFilter",\r
+                        "negative" => true,\r
+                        "query" => $blockHomepages\r
+                       );\r
+                }\r
+\r
             }\r
+\r
+            // If there's a supplied filterType, use that also\r
             if ($this->filterType) {\r
                 if ($this->filterValue) {\r
                     $query = $this->filterType.':"'.$this->filterValue.'"';\r
-                } else {\r
+                } elseif ($customFilter != '') {\r
                     $query = $this->filterType.':"'.$this->website.'"';\r
                 }\r
             }\r
 \r
-            // Set filter\r
-            $this->request['filters'] = array(\r
-               array(\r
-                    "type" => "QueryFilter",\r
-                    "negative" => false,\r
-                    "query" => $query\r
-               )\r
-            );\r
-\r
-            // Check if we're supposed to exclude the home page contents\r
-            if ($this->exclude_home_page) {\r
-               $this->request['filters'][] = array(\r
-                    "type" => "QueryFilter",\r
-                    "negative" => true,\r
-                    "query" => 'url:"http://'.$this->website.'/"'\r
-               );\r
-            }\r
-\r
         } else {\r
             unset($this->request['filters']);\r
         }\r
index 2518214..fcc97c4 100644 (file)
@@ -25,8 +25,9 @@
             <tr>
                 <th {if $searchSettings.fieldRequired.website}class="glm-required"{/if}>Website:</th>
                 <td {if $searchSettings.fieldFail.website}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
-                    <input type="text" name="website" value="{$searchSettings.fieldData.website}" class="glm-form-text-input-medium">
-                    <!-- Leave blank to search all sites in the selected Index.  -->
+                    <input type="text" name="website" value="{$searchSettings.fieldData.website}" class="glm-form-text-input" placeholder="i.e.: www.upnorth.net or www.upnorth.net,www.gaslightmedia.com,... for multiple sites">
+                    <br>Leave blank to search all sites in the selected Index.
+                    <br>Include a comma separated list of sites to search multiple specific sites.
                     {if $searchSettings.fieldFail.website}<p>{$searchSettings.fieldFail.website}</p>{/if}
                 </td>
             </tr>