Updated search with additional filtering and paging options.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 7 Jul 2016 13:43:44 +0000 (09:43 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 7 Jul 2016 13:43:44 +0000 (09:43 -0400)
12 files changed:
classes/data/dataManagement.php
classes/glmSearch.php
index.php
models/front/search/index.php
setup/databaseScripts/create_database_V0.0.1.sql [deleted file]
setup/databaseScripts/create_database_V0.0.3.sql [new file with mode: 0644]
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.2.sql [new file with mode: 0644]
setup/databaseScripts/update_database_V0.0.3.sql [new file with mode: 0644]
views/admin/management/search.html
views/front/search/header.html
views/front/search/index.html

index 654c72f..682c99a 100644 (file)
@@ -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'
             )
 
 
+
         );
 
     }
index e609c69..2af2878 100644 (file)
@@ -151,6 +151,13 @@ class GLMSearch
      * @access public\r
      */\r
     public $filter = true;\r
+    /**\r
+     * Show home page content flag\r
+     *\r
+     * @var    $exclude_home_page\r
+     * @access public\r
+     */\r
+    public $exclude_home_page = true;\r
     /**\r
      * Host Filter Type\r
      *\r
@@ -182,7 +189,7 @@ class GLMSearch
      * @return void\r
      * @access public\r
      */\r
-    public function __construct($index, $website, $login, $key, $filterType = false, $filterValue = false)\r
+    public function __construct($index, $website, $login, $key, $exclude_home_page, $filterType = false, $filterValue = false)\r
     {\r
 \r
         // If there's a problem with Filter and validate supplied parameters\r
@@ -197,6 +204,7 @@ class GLMSearch
         // Store supplied parameters\r
         $this->index = $index;\r
         $this->website = $website;\r
+        $this->exclude_home_page = $exclude_home_page;\r
 \r
         // Build authentication parameters for submissions\r
         $this->auth = "login=$login&key=$key";\r
@@ -288,6 +296,15 @@ class GLMSearch
                )\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 e953ab3..d517751 100644 (file)
--- 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');
index d27edd5..259dab0 100644 (file)
@@ -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.1.sql
deleted file mode 100644 (file)
index 958f06a..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
--- Gaslight Media Members Database - Search 
--- File Created: 12/02/15 15:27:15
--- Database Version: 0.0.1
--- Database Creation Script
--- 
--- To permit each query below to be executed separately,
--- all queries must be separated by a line with four dashes
-
--- Search Management Settings
-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
-  login TINYTEXT NULL,                  -- OSS API Login 
-  login_key TINYTEXT NULL,              -- OSS API Login Key
-  PRIMARY KEY (id)
-);
-
-----
-
--- Set default package management entry
-INSERT INTO {prefix}management
-    ( id, search_index, website, login, login_key )
-   VALUES
-    ( 1, 'Index_1', 'www.gaslightmedia.com', 'WebsiteServices', '829800701e8440b67a78e3afbefa1049' )
-;
-
diff --git a/setup/databaseScripts/create_database_V0.0.3.sql b/setup/databaseScripts/create_database_V0.0.3.sql
new file mode 100644 (file)
index 0000000..f1063cd
--- /dev/null
@@ -0,0 +1,29 @@
+-- Gaslight Media Members Database - Search 
+-- File Created: 12/02/15 15:27:15
+-- Database Version: 0.0.1
+-- Database Creation Script
+-- 
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashes
+
+-- Search Management Settings
+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)
+);
+
+----
+
+-- Set default package management entry
+INSERT INTO {prefix}management
+    ( id, search_index, website, exclude_home_page, numb_rows, login, login_key )
+   VALUES
+    ( 1, 'Index_1', 'www.gaslightmedia.com', true, 20, 'WebsiteServices', '829800701e8440b67a78e3afbefa1049' )
+;
+
index 1419080..d466cda 100644 (file)
@@ -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 (file)
index 0000000..d0d8678
--- /dev/null
@@ -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 (file)
index 0000000..b717cc1
--- /dev/null
@@ -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;
index 79a5a46..ef784ee 100644 (file)
                     {if $searchSettings.fieldFail.login_key}<p>{$searchSettings.fieldFail.login_key}</p>{/if}
                 </td>
             </tr>
+            <tr>
+                <th>Exclude Home Page Content<br>From Search Results:</th>
+                <td>
+                    <input type="checkbox" name="exclude_home_page"{if $searchSettings.fieldData.exclude_home_page.value} checked="checked"{/if}>
+                </td>
+            </tr>
+            <tr>
+                <th>Default number of rows per result page:</th>
+                <td>
+                    <input type="text" name="numb_rows" value="{$searchSettings.fieldData.numb_rows}" class="glm-form-text-input-veryshort">
+                </td>
+            </tr>
         </table>
         <input type="submit" value="Update Settings" class="button-primary">
     </form>
index 5e9f93d..e6bf437 100644 (file)
@@ -1,3 +1,3 @@
-<div class="wrap">
+<div class="wrap opensearchserver.ignore">
     <div id="glm-member-search-front-container" class="glm-member-front-container">
     
\ No newline at end of file
index 47d8063..bcd70cb 100644 (file)
@@ -2,16 +2,14 @@
  
     <form action="{$thisUrl}?glm_action=index" method="post" enctype="multipart/form-data">
         Search for: <input type="hidden" name="GLMSearch" value="true">
-        <input type="hidden" name="start" value="0">
-        <input type="hidden" name="rows" value="10">
         <input type="text" name="query" value="{$query}">
         <input type="checkbox" name="matchAll" {if $searchResult.operator == 'AND'}checked{/if} value="on"> Match all words
         <input type="submit" id="submit" value="Search">
     </form>
     
-{if $haveSearchResult}
+{if $haveSearchRequest}
   
-  {if $searchResult.totalResults > 0}
+  {if $haveSearchResult}
   
             <!-- Results Header - Top -->
             
@@ -92,7 +90,7 @@
                         
                 
   {else}
-            <h3>No results matching your search.</h3>
+            <h4>No results matching your search.</h4>
   {/if}
   
 {else}