From 8404b0cec67b395759d617663cceb938c5a59408 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Mon, 20 Mar 2017 20:08:56 +0000
Subject: [PATCH] Default to snippet from the page source in search result
 context generation - some pages may appear when the search terms appear only
 in the title or tags, and not the page source.

---
 Changelog.md                         |  1 +
 build/index.php                      |  8 +++++---
 module_index.json                    | 12 ++++++------
 modules/feature-guiconfig.php        |  2 +-
 modules/feature-search.php           |  4 +++-
 modules/feature-user-preferences.php |  2 +-
 6 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 9bcd29a..94cc707 100755
--- a/Changelog.md
+++ b/Changelog.md
@@ -43,6 +43,7 @@
  - Correct error message when attempting to move a page
  - Improved security of PHP session cookie by setting HttpOnly flag.
  - Linked pages with single quotes (`'`) in their names corectly in page lists.
+ - Fixed blank descriptions in search results by defaulting to a snippet from the beginning of the page.
 
 ## v0.12.1
 
diff --git a/build/index.php b/build/index.php
index b9cd80d..40f003b 100644
--- a/build/index.php
+++ b/build/index.php
@@ -1977,7 +1977,7 @@ function render_sidebar($pageindex, $root_pagename = "")
 
 register_module([
 	"name" => "Settings GUI",
-	"version" => "0.1",
+	"version" => "0.1.1",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.",
 	"id" => "feature-guiconfig",
@@ -2532,7 +2532,7 @@ register_module([
 
 register_module([
 	"name" => "Search",
-	"version" => "0.4",
+	"version" => "0.5",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
 	"id" => "feature-search",
@@ -2690,6 +2690,8 @@ register_module([
 				
 				//echo("Extracting context for result " . $result["pagename"] . ".\n");
 				$context = search::extract_context($_GET["query"], $pagesource);
+				if(strlen($context) === 0)
+					$context = substr($pagesource, 0, $settings->search_characters_context * 2);
 				//echo("'Generated search context for " . $result["pagename"] . ": $context'\n");
 				$context = search::highlight_context($_GET["query"], $context);
 				/*if(strlen($context) == 0)
@@ -3822,7 +3824,7 @@ function errorimage($text, $target_size)
 
 register_module([
 	"name" => "User Preferences",
-	"version" => "0.2",
+	"version" => "0.2.1",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Adds a user preferences page, letting pople do things like change their email address and password.",
 	"id" => "feature-user-preferences",
diff --git a/module_index.json b/module_index.json
index 5889df4..cd49949 100755
--- a/module_index.json
+++ b/module_index.json
@@ -46,11 +46,11 @@
     },
     {
         "name": "Settings GUI",
-        "version": "0.1",
+        "version": "0.1.1",
         "author": "Starbeamrainbowlabs",
         "description": "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.",
         "id": "feature-guiconfig",
-        "lastupdate": 1490039426,
+        "lastupdate": 1490040335,
         "optional": false
     },
     {
@@ -82,11 +82,11 @@
     },
     {
         "name": "Search",
-        "version": "0.4",
+        "version": "0.5",
         "author": "Starbeamrainbowlabs",
         "description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
         "id": "feature-search",
-        "lastupdate": 1485464071,
+        "lastupdate": 1490040313,
         "optional": false
     },
     {
@@ -100,11 +100,11 @@
     },
     {
         "name": "User Preferences",
-        "version": "0.2",
+        "version": "0.2.1",
         "author": "Starbeamrainbowlabs",
         "description": "Adds a user preferences page, letting pople do things like change their email address and password.",
         "id": "feature-user-preferences",
-        "lastupdate": 1490039844,
+        "lastupdate": 1490040319,
         "optional": false
     },
     {
diff --git a/modules/feature-guiconfig.php b/modules/feature-guiconfig.php
index 5ffc37a..d0f1b61 100644
--- a/modules/feature-guiconfig.php
+++ b/modules/feature-guiconfig.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "Settings GUI",
-	"version" => "0.1",
+	"version" => "0.1.1",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "The module everyone has been waiting for! Adds a web based gui that lets mods change the wiki settings.",
 	"id" => "feature-guiconfig",
diff --git a/modules/feature-search.php b/modules/feature-search.php
index ca7802b..ada6c2b 100755
--- a/modules/feature-search.php
+++ b/modules/feature-search.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "Search",
-	"version" => "0.4",
+	"version" => "0.5",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
 	"id" => "feature-search",
@@ -159,6 +159,8 @@ register_module([
 				
 				//echo("Extracting context for result " . $result["pagename"] . ".\n");
 				$context = search::extract_context($_GET["query"], $pagesource);
+				if(strlen($context) === 0)
+					$context = substr($pagesource, 0, $settings->search_characters_context * 2);
 				//echo("'Generated search context for " . $result["pagename"] . ": $context'\n");
 				$context = search::highlight_context($_GET["query"], $context);
 				/*if(strlen($context) == 0)
diff --git a/modules/feature-user-preferences.php b/modules/feature-user-preferences.php
index 3477da9..2676eaa 100644
--- a/modules/feature-user-preferences.php
+++ b/modules/feature-user-preferences.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "User Preferences",
-	"version" => "0.2",
+	"version" => "0.2.1",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Adds a user preferences page, letting pople do things like change their email address and password.",
 	"id" => "feature-user-preferences",
