From 5e4cfff864085bf23b38ed82a4e1350c7800df76 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Thu, 7 Jul 2016 09:43:44 -0400 Subject: [PATCH] Updated search with additional filtering and paging options. --- classes/data/dataManagement.php | 17 +++++++++++++++ classes/glmSearch.php | 19 ++++++++++++++++- index.php | 2 +- models/front/search/index.php | 21 +++++++++++++++---- ..._V0.0.1.sql => create_database_V0.0.3.sql} | 6 ++++-- setup/databaseScripts/dbVersions.php | 4 +++- .../update_database_V0.0.2.sql | 12 +++++++++++ .../update_database_V0.0.3.sql | 13 ++++++++++++ views/admin/management/search.html | 12 +++++++++++ views/front/search/header.html | 2 +- views/front/search/index.html | 8 +++---- 11 files changed, 101 insertions(+), 15 deletions(-) rename setup/databaseScripts/{create_database_V0.0.1.sql => create_database_V0.0.3.sql} (65%) create mode 100644 setup/databaseScripts/update_database_V0.0.2.sql create mode 100644 setup/databaseScripts/update_database_V0.0.3.sql diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php index 654c72f..682c99a 100644 --- a/classes/data/dataManagement.php +++ b/classes/data/dataManagement.php @@ -145,9 +145,26 @@ class GlmDataSearchManagement extends GlmDataAbstract 'type' => 'text', 'required' => true, 'use' => 'a' + ), + + // Flag to show/exclude home page from search results + 'exclude_home_page' => array( + 'field' => 'exclude_home_page', + 'type' => 'checkbox', + 'default' => false, + 'use' => 'a' + ), + + // Number of rows per result page (default) + 'numb_rows' => array ( + 'field' => 'numb_rows', + 'type' => 'integer', + 'required' => true, + 'use' => 'a' ) + ); } diff --git a/classes/glmSearch.php b/classes/glmSearch.php index e609c69..2af2878 100644 --- a/classes/glmSearch.php +++ b/classes/glmSearch.php @@ -151,6 +151,13 @@ class GLMSearch * @access public */ public $filter = true; + /** + * Show home page content flag + * + * @var $exclude_home_page + * @access public + */ + public $exclude_home_page = true; /** * Host Filter Type * @@ -182,7 +189,7 @@ class GLMSearch * @return void * @access public */ - public function __construct($index, $website, $login, $key, $filterType = false, $filterValue = false) + public function __construct($index, $website, $login, $key, $exclude_home_page, $filterType = false, $filterValue = false) { // If there's a problem with Filter and validate supplied parameters @@ -197,6 +204,7 @@ class GLMSearch // Store supplied parameters $this->index = $index; $this->website = $website; + $this->exclude_home_page = $exclude_home_page; // Build authentication parameters for submissions $this->auth = "login=$login&key=$key"; @@ -288,6 +296,15 @@ class GLMSearch ) ); + // 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/index.php b/index.php index e953ab3..d517751 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_SEARCH_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_SEARCH_PLUGIN_DB_VERSION', '0.0.1'); +define('GLM_MEMBERS_SEARCH_PLUGIN_DB_VERSION', '0.0.3'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_SEARCH_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.1.9'); diff --git a/models/front/search/index.php b/models/front/search/index.php index d27edd5..259dab0 100644 --- a/models/front/search/index.php +++ b/models/front/search/index.php @@ -60,9 +60,10 @@ class GlmMembersFront_search_index extends GLMSearch $website = $this->config['settings']['website']; $login = $this->config['settings']['login']; $key = $this->config['settings']['login_key']; + $exclude_home_page = $this->config['settings']['exclude_home_page']; // Run constructor for members data class - parent::__construct($index, $website, $login, $key); + parent::__construct($index, $website, $login, $key, $exclude_home_page); } @@ -103,28 +104,39 @@ class GlmMembersFront_search_index extends GLMSearch public function modelAction ($actionData = false) { + $haveSearchRequest = false; $haveSearchResult = false; $status = true; $query = false; + $start = 0; + $rows = $this->config['settings']['numb_rows']; $searchResult = array( 'operator' => 'AND' ); - /* * Get input from form */ if (isset($_REQUEST['query'])) { + $haveSearchRequest = true; + + // Assemble requested query $query = $_REQUEST['query']; $operator = 'OR'; if (isset($_REQUEST['matchAll']) && $_REQUEST['matchAll'] == 'on') { $operator = 'AND'; } - $start = $_REQUEST['start']; - $rows = $_REQUEST['rows']; + // Set pagination - Note that form may override the number of rows. + if (isset($_REQUEST['start'])) { + $start = $_REQUEST['start']; + } + if (isset($_REQUEST['rows'])) { + $rows = $_REQUEST['rows']; + } + // Send request to OpenSearchServer and get results if (trim($query) != '') { $searchResult = $this->glmSearch($query, $operator, $start, $rows); if (is_array($searchResult) && isset($searchResult['totalResults']) && $searchResult['totalResults'] > 0 ) { @@ -136,6 +148,7 @@ class GlmMembersFront_search_index extends GLMSearch // Compile template data $templateData = array( + 'haveSearchRequest' => $haveSearchRequest, 'haveSearchResult' => $haveSearchResult, 'searchResult' => $searchResult, 'query' => $query diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.3.sql similarity index 65% rename from setup/databaseScripts/create_database_V0.0.1.sql rename to setup/databaseScripts/create_database_V0.0.3.sql index 958f06a..f1063cd 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.3.sql @@ -11,6 +11,8 @@ CREATE TABLE {prefix}management ( id INT NOT NULL AUTO_INCREMENT, search_index TINYTEXT NULL, -- OSS Search Index to use (normally "Index_1") website TINYTEXT NULL, -- Hostname for the Website + exclude_home_page BOOLEAN NULL, -- Flag to say whether to exclude home page from search results + numb_rows SMALLINT NULL, -- Number of rows to show per page in results login TINYTEXT NULL, -- OSS API Login login_key TINYTEXT NULL, -- OSS API Login Key PRIMARY KEY (id) @@ -20,8 +22,8 @@ CREATE TABLE {prefix}management ( -- Set default package management entry INSERT INTO {prefix}management - ( id, search_index, website, login, login_key ) + ( id, search_index, website, exclude_home_page, numb_rows, login, login_key ) VALUES - ( 1, 'Index_1', 'www.gaslightmedia.com', 'WebsiteServices', '829800701e8440b67a78e3afbefa1049' ) + ( 1, 'Index_1', 'www.gaslightmedia.com', true, 20, 'WebsiteServices', '829800701e8440b67a78e3afbefa1049' ) ; diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 1419080..d466cda 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -14,6 +14,8 @@ */ $glmMembersSearchDbVersions = array( - '0.0.1' => array('version' => '0.0.1', 'tables' => 1) + '0.0.1' => array('version' => '0.0.1', 'tables' => 1, 'date' => '6/20/16'), + '0.0.2' => array('version' => '0.0.2', 'tables' => 1, 'date' => '7/5/16'), + '0.0.3' => array('version' => '0.0.3', 'tables' => 1, 'date' => '7/7/16') ); diff --git a/setup/databaseScripts/update_database_V0.0.2.sql b/setup/databaseScripts/update_database_V0.0.2.sql new file mode 100644 index 0000000..d0d8678 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.2.sql @@ -0,0 +1,12 @@ +-- Gaslight Media Members Database +-- File Created: 7/5/16 15:27:15 +-- Database Version: 0.0.2 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + +ALTER TABLE {prefix}management ADD COLUMN exclude_home_page BOOLEAN; + + + diff --git a/setup/databaseScripts/update_database_V0.0.3.sql b/setup/databaseScripts/update_database_V0.0.3.sql new file mode 100644 index 0000000..b717cc1 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.3.sql @@ -0,0 +1,13 @@ +-- Gaslight Media Members Database +-- File Created: 7/5/16 15:27:15 +-- Database Version: 0.0.2 +-- Database Update From Previous Version Script +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashses + +ALTER TABLE {prefix}management ADD COLUMN numb_rows SMALLINT; + +---- + +UPDATE {prefix}management SET numb_rows = 20; diff --git a/views/admin/management/search.html b/views/admin/management/search.html index 79a5a46..ef784ee 100644 --- a/views/admin/management/search.html +++ b/views/admin/management/search.html @@ -43,6 +43,18 @@ {if $searchSettings.fieldFail.login_key}

{$searchSettings.fieldFail.login_key}

{/if} + + Exclude Home Page Content
From Search Results: + + + + + + Default number of rows per result page: + + + + diff --git a/views/front/search/header.html b/views/front/search/header.html index 5e9f93d..e6bf437 100644 --- a/views/front/search/header.html +++ b/views/front/search/header.html @@ -1,3 +1,3 @@ -
+
\ No newline at end of file diff --git a/views/front/search/index.html b/views/front/search/index.html index 47d8063..bcd70cb 100644 --- a/views/front/search/index.html +++ b/views/front/search/index.html @@ -2,16 +2,14 @@
Search for: - - Match all words
-{if $haveSearchResult} +{if $haveSearchRequest} - {if $searchResult.totalResults > 0} + {if $haveSearchResult} @@ -92,7 +90,7 @@ {else} -

No results matching your search.

+

No results matching your search.

{/if} {else} -- 2.17.1