From: Chuck Scott Date: Fri, 5 Aug 2016 18:45:30 +0000 (-0400) Subject: Restructured the glmSearch.php class to be able to search multiple specific sites... X-Git-Tag: v1.1.0^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=5fbd9feb64c56412f7275f77f50deef5061bb92a;p=WP-Plugins%2Fglm-member-db-search.git Restructured the glmSearch.php class to be able to search multiple specific sites or all sites at one time. Updated the management search setup form to inform the user how to enter the websites to do this. --- diff --git a/classes/glmSearch.php b/classes/glmSearch.php index deda4f0..ee79ecc 100644 --- a/classes/glmSearch.php +++ b/classes/glmSearch.php @@ -194,7 +194,7 @@ class GLMSearch // If there's a problem with Filter and validate supplied parameters if ( - ($website = filter_var($website, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false || + (trim($website) != '' && ($website = filter_var($website, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) || ($login = filter_var($login, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false || ($key = filter_var($key, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false ) { @@ -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 if ($this->filter) { - // Determine if there's a specific filter type and value - Default to host: - $query = ''; - if (trim($this->website) != '') { - $query = 'host:"'.$this->website.'"'; + $this->request['filters'] = array(); + + // Build a list of Websites provided in the management Website field (comma separated) + $sites = array_filter(explode(',', $this->website )); + + // Add each Website to the positive query filter + if (count($sites) > 0) { + + $addHosts = ''; + $blockHomepages = ''; + $customFilter = ''; + $sep = ''; + foreach ($sites as $site) { + + $site = trim($site); + + // Build string to include sites + $addHosts .= $sep.'host:"'.$site.'"'; + + // Build string to block homepages + $blockHomepages .= $sep.'url:"http://'.$site.'/"'; + + if ($this->filterType && !$this->filterValue) { + $customFilter .= $this->filterType.':"'.$site.'"'; + } + + $sep = ' '; + + } + + $this->request['filters'][] = array( + "type" => "QueryFilter", + "negative" => false, + "query" => $addHosts + ); + + + // If excluding the home page contents, add a negative filter for that for this site + if ($this->exclude_home_page) { + $this->request['filters'][] = array( + "type" => "QueryFilter", + "negative" => true, + "query" => $blockHomepages + ); + } + } + + // If there's a supplied filterType, use that also if ($this->filterType) { if ($this->filterValue) { $query = $this->filterType.':"'.$this->filterValue.'"'; - } else { + } elseif ($customFilter != '') { $query = $this->filterType.':"'.$this->website.'"'; } } - // Set filter - $this->request['filters'] = array( - array( - "type" => "QueryFilter", - "negative" => false, - "query" => $query - ) - ); - - // Check if we're supposed to exclude the home page contents - if ($this->exclude_home_page) { - $this->request['filters'][] = array( - "type" => "QueryFilter", - "negative" => true, - "query" => 'url:"http://'.$this->website.'/"' - ); - } - } else { unset($this->request['filters']); } diff --git a/views/admin/management/search.html b/views/admin/management/search.html index 2518214..fcc97c4 100644 --- a/views/admin/management/search.html +++ b/views/admin/management/search.html @@ -25,8 +25,9 @@ Website: - - + +
Leave blank to search all sites in the selected Index. +
Include a comma separated list of sites to search multiple specific sites. {if $searchSettings.fieldFail.website}

{$searchSettings.fieldFail.website}

{/if}