From 1e04f9f2ecb5a326ded1422cd03ee1f37198e571 Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph.amissah@gmail.com>
Date: Thu, 27 Jan 2022 12:57:13 -0500
Subject: cgi sqlite_search, heading matches fix, cleanup

---
 sundry/spine_search_cgi/src/spine_search.d         | 44 +++++++++++-----------
 sundry/spine_search_cgi/src/spine_search.d_        | 39 ++++++++++---------
 sundry/spine_search_cgi/views/configuration.txt    |  6 +--
 .../views/configuration_example.txt                |  6 +--
 4 files changed, 44 insertions(+), 51 deletions(-)

(limited to 'sundry')

diff --git a/sundry/spine_search_cgi/src/spine_search.d b/sundry/spine_search_cgi/src/spine_search.d
index 2f9de26..e1e0c93 100644
--- a/sundry/spine_search_cgi/src/spine_search.d
+++ b/sundry/spine_search_cgi/src/spine_search.d
@@ -7,7 +7,7 @@
   - Author: Ralph Amissah
     [ralph.amissah@gmail.com]
 
-  - Copyright: (C) 2015 - 2021 Ralph Amissah, All Rights
+  - Copyright: (C) 2015 - 2022 Ralph Amissah, All Rights
     Reserved.
 
   - License: AGPL 3 or later:
@@ -41,7 +41,7 @@
     - docReform object numbering
       - standard SiSU object citation numbering & system
 
-  - Hompages:
+  - Homepages:
     [https://www.doc_reform.org]
     [https://www.sisudoc.org]
 
@@ -68,9 +68,7 @@ void cgi_function_intro(Cgi cgi) {
     string http_request_type;
     string http_host;
     // string server_name;
-    string web_doc_root_path;
-    string doc_collection_sub_root;
-    string cgi_root;
+    string doc_collection_subroot;
     string cgi_script_name;
     string cgi_search_form_title;
     string cgi_search_form_html_title;
@@ -84,9 +82,7 @@ void cgi_function_intro(Cgi cgi) {
   auto conf = Config();
   conf.http_request_type          = environment.get("REQUEST_SCHEME",        _cfg.http_request_type);
   conf.http_host                  = environment.get("SERVER_NAME",           _cfg.http_host);
-  conf.web_doc_root_path          = environment.get("DOCUMENT_ROOT",         _cfg.www_doc_root);
-  conf.doc_collection_sub_root    = "/spine/static"; // (output_path - web_doc_root_path)
-  conf.cgi_root                   = environment.get("CONTEXT_DOCUMENT_ROOT", _cfg.cgi_bin_subpath);
+  conf.doc_collection_subroot     = _cfg.www_doc_subroot;
   conf.cgi_script_name            = environment.get("SCRIPT_NAME",           _cfg.cgi_filename);
   conf.cgi_search_form_title      = _cfg.cgi_search_form_title; // ≅ SiSU spine search form
   conf.cgi_search_form_html_title = "<a href=\""
@@ -95,7 +91,7 @@ void cgi_function_intro(Cgi cgi) {
     ~ "\">"
     ~ _cfg.cgi_search_form_title
     ~ "</a>";
-  conf.query_base_url          = conf.http_request_type ~ "://" ~ conf.http_host ~ "/" ~ conf.cgi_script_name ~ "?";
+  conf.query_base_url          = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script_name ~ "?";
   conf.query_string            = environment.get("QUERY_STRING",          "");
   conf.http_url                = environment.get("HTTP_REFERER",          conf.query_base_url ~ conf.query_string);
   conf.request_method          = environment.get("REQUEST_METHOD",        "POST");
@@ -1684,6 +1680,7 @@ SELECT
   doc_objects.body,
   doc_objects.seg_name,
   doc_objects.ocn,
+  doc_objects.lev,
   metadata_and_text.uid
 FROM
   doc_objects,
@@ -1734,7 +1731,7 @@ LIMIT %s OFFSET %s
               ~ "<hr><div class=\"publication\">"
                 ~ "<p class=\"publication\"><a href=\""
                   ~ conf.http_request_type ~ "://"
-                  ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                  ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                   ~ row["language_document_char"].as!string ~ "/html/"
                   ~ row["src_filename_base"].as!string ~ "/"
                   ~ "toc.html"
@@ -1751,16 +1748,16 @@ LIMIT %s OFFSET %s
             );
           }
           if (cv.results_type == "txt") {
-            if (row["ocn"].as!string != "0") {
+            if ((row["lev"].as!int < 4)
+            || (row["ocn"].as!string == "0")) {
               cgi.write(
                 "<div class=\"flex-container\">"
                 ~ "<div class=\"textview_ocn\" style=\"flex: 0 0 1.2em\">"
                   ~ "<p class=\"ocn_is\"><a href=\""
                     ~ conf.http_request_type ~ "://"
-                    ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                    ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                     ~ row["language_document_char"].as!string ~ "/html/"
-                    ~ row["src_filename_base"].as!string ~ "/"
-                    ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+                    ~ row["src_filename_base"].as!string ~ "/toc.html"
                   ~ "\">"
                     ~ row["ocn"].as!string
                   ~ "</a>:</p>"
@@ -1776,9 +1773,10 @@ LIMIT %s OFFSET %s
                 ~ "<div class=\"textview_ocn\" style=\"flex: 0 0 1.2em\">"
                   ~ "<p class=\"ocn_is\"><a href=\""
                     ~ conf.http_request_type ~ "://"
-                    ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                    ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                     ~ row["language_document_char"].as!string ~ "/html/"
-                    ~ row["src_filename_base"].as!string ~ "/toc.html"
+                    ~ row["src_filename_base"].as!string ~ "/"
+                    ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
                   ~ "\">"
                     ~ row["ocn"].as!string
                   ~ "</a>:</p>"
@@ -1790,15 +1788,15 @@ LIMIT %s OFFSET %s
               );
             }
           } else {
-            if (row["ocn"].as!string != "0") {
+            if ((row["lev"].as!int < 4)
+            || (row["ocn"].as!string == "0")) {
               cgi.write(
                 _matched_ocn_open
                 ~ "<a href=\""
                   ~ conf.http_request_type ~ "://"
-                  ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                  ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                   ~ row["language_document_char"].as!string ~ "/html/"
-                  ~ row["src_filename_base"].as!string ~ "/"
-                  ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+                  ~ row["src_filename_base"].as!string ~ "/toc.html"
                 ~ "\">"
                   ~ row["ocn"].as!string
                 ~ "</a>, "
@@ -1808,9 +1806,10 @@ LIMIT %s OFFSET %s
                 _matched_ocn_open
                 ~ "<a href=\""
                   ~ conf.http_request_type ~ "://"
-                  ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                  ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                   ~ row["language_document_char"].as!string ~ "/html/"
-                  ~ row["src_filename_base"].as!string ~ "/toc.html"
+                  ~ row["src_filename_base"].as!string ~ "/"
+                  ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
                 ~ "\">"
                   ~ row["ocn"].as!string
                 ~ "</a>, "
@@ -1820,7 +1819,6 @@ LIMIT %s OFFSET %s
           }
         }
         cgi.write( previous_next);
-
       } else { // offset_not_beyond_limit = false;
         cgi.write("select_query_results empty<p>\n");
       }
diff --git a/sundry/spine_search_cgi/src/spine_search.d_ b/sundry/spine_search_cgi/src/spine_search.d_
index 10dc9c3..3703659 100755
--- a/sundry/spine_search_cgi/src/spine_search.d_
+++ b/sundry/spine_search_cgi/src/spine_search.d_
@@ -69,9 +69,7 @@ void cgi_function_intro(Cgi cgi) {
     string http_request_type;
     string http_host;
     // string server_name;
-    string web_doc_root_path;
-    string doc_collection_sub_root;
-    string cgi_root;
+    string doc_collection_subroot;
     string cgi_script_name;
     string cgi_search_form_title;
     string cgi_search_form_html_title;
@@ -86,9 +84,7 @@ void cgi_function_intro(Cgi cgi) {
   conf.http_request_type          = environment.get("REQUEST_SCHEME",        _cfg.http_request_type);
   conf.http_host                  = environment.get("SERVER_NAME",           _cfg.http_host);
   // conf.http_host                  = environment.get("HTTP_HOST",             _cfg.http_host);
-  conf.web_doc_root_path          = environment.get("DOCUMENT_ROOT",         _cfg.www_doc_root);
-  conf.doc_collection_sub_root    = "/spine/static"; // (output_path - web_doc_root_path)
-  conf.cgi_root                   = environment.get("CONTEXT_DOCUMENT_ROOT", _cfg.cgi_bin_subpath);
+  conf.doc_collection_subroot     = _cfg.www_doc_subroot;
   conf.cgi_script_name            = environment.get("SCRIPT_NAME",           _cfg.cgi_filename);
   conf.cgi_search_form_title      = _cfg.cgi_search_form_title; // ≅ SiSU spine search form
   conf.cgi_search_form_html_title = "<a href=\""
@@ -97,7 +93,7 @@ void cgi_function_intro(Cgi cgi) {
     ~ "\">"
     ~ _cfg.cgi_search_form_title
     ~ "</a>";
-  conf.query_base_url          = conf.http_request_type ~ "://" ~ conf.http_host ~ "/" ~ conf.cgi_script_name ~ "?";
+  conf.query_base_url          = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script_name ~ "?";
   conf.query_string            = environment.get("QUERY_STRING",          "");
   conf.http_url                = environment.get("HTTP_REFERER",          conf.query_base_url ~ conf.query_string);
   conf.request_method          = environment.get("REQUEST_METHOD",        "POST");
@@ -1686,6 +1682,7 @@ SELECT
   doc_objects.body,
   doc_objects.seg_name,
   doc_objects.ocn,
+  doc_objects.lev,
   metadata_and_text.uid
 FROM
   doc_objects,
@@ -1736,7 +1733,7 @@ LIMIT %s OFFSET %s
               ~ "<hr><div class=\"publication\">"
                 ~ "<p class=\"publication\"><a href=\""
                   ~ conf.http_request_type ~ "://"
-                  ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                  ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                   ~ row["language_document_char"].as!string ~ "/html/"
                   ~ row["src_filename_base"].as!string ~ "/"
                   ~ "toc.html"
@@ -1753,16 +1750,16 @@ LIMIT %s OFFSET %s
             );
           }
           if (cv.results_type == "txt") {
-            if (row["ocn"].as!string != "0") {
+            if ((row["lev"].as!int < 4)
+            || (row["ocn"].as!string == "0")) {
               cgi.write(
                 "<div class=\"flex-container\">"
                 ~ "<div class=\"textview_ocn\" style=\"flex: 0 0 1.2em\">"
                   ~ "<p class=\"ocn_is\"><a href=\""
                     ~ conf.http_request_type ~ "://"
-                    ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                    ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                     ~ row["language_document_char"].as!string ~ "/html/"
-                    ~ row["src_filename_base"].as!string ~ "/"
-                    ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+                    ~ row["src_filename_base"].as!string ~ "/toc.html"
                   ~ "\">"
                     ~ row["ocn"].as!string
                   ~ "</a>:</p>"
@@ -1778,9 +1775,10 @@ LIMIT %s OFFSET %s
                 ~ "<div class=\"textview_ocn\" style=\"flex: 0 0 1.2em\">"
                   ~ "<p class=\"ocn_is\"><a href=\""
                     ~ conf.http_request_type ~ "://"
-                    ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                    ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                     ~ row["language_document_char"].as!string ~ "/html/"
-                    ~ row["src_filename_base"].as!string ~ "/toc.html"
+                    ~ row["src_filename_base"].as!string ~ "/"
+                    ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
                   ~ "\">"
                     ~ row["ocn"].as!string
                   ~ "</a>:</p>"
@@ -1792,15 +1790,15 @@ LIMIT %s OFFSET %s
               );
             }
           } else {
-            if (row["ocn"].as!string != "0") {
+            if ((row["lev"].as!int < 4)
+            || (row["ocn"].as!string == "0")) {
               cgi.write(
                 _matched_ocn_open
                 ~ "<a href=\""
                   ~ conf.http_request_type ~ "://"
-                  ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                  ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                   ~ row["language_document_char"].as!string ~ "/html/"
-                  ~ row["src_filename_base"].as!string ~ "/"
-                  ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+                  ~ row["src_filename_base"].as!string ~ "/toc.html"
                 ~ "\">"
                   ~ row["ocn"].as!string
                 ~ "</a>, "
@@ -1810,9 +1808,10 @@ LIMIT %s OFFSET %s
                 _matched_ocn_open
                 ~ "<a href=\""
                   ~ conf.http_request_type ~ "://"
-                  ~ conf.http_host ~ conf.doc_collection_sub_root ~ "/"
+                  ~ conf.http_host ~ conf.doc_collection_subroot ~ "/"
                   ~ row["language_document_char"].as!string ~ "/html/"
-                  ~ row["src_filename_base"].as!string ~ "/toc.html"
+                  ~ row["src_filename_base"].as!string ~ "/"
+                  ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
                 ~ "\">"
                   ~ row["ocn"].as!string
                 ~ "</a>, "
diff --git a/sundry/spine_search_cgi/views/configuration.txt b/sundry/spine_search_cgi/views/configuration.txt
index e810d68..51a8963 100644
--- a/sundry/spine_search_cgi/views/configuration.txt
+++ b/sundry/spine_search_cgi/views/configuration.txt
@@ -1,10 +1,8 @@
 struct Cfg {
   string http_request_type     = "http";
   string http_host             = "localhost";
-  string www_url_doc_root      = "http://localhost";
-  string www_doc_root          = "/srv/www/spine/static";
-  string cgi_bin_subpath       = "";
-  string cgi_filename          = "spine_search";                          // "spine-search"
+  string www_doc_subroot       = "/spine";
+  string cgi_filename          = "spine_search";
   string cgi_search_form_title = "≅ SiSU Spine search";
   string db_sqlite_path        = "/var/www/sqlite";
   string db_sqlite_filename    = "spine.search.db";
diff --git a/sundry/spine_search_cgi/views/configuration_example.txt b/sundry/spine_search_cgi/views/configuration_example.txt
index 3552861..ea43fde 100644
--- a/sundry/spine_search_cgi/views/configuration_example.txt
+++ b/sundry/spine_search_cgi/views/configuration_example.txt
@@ -2,10 +2,8 @@
 struct Cfg {
   string http_request_type     = "http";
   string http_host             = "localhost";
-  string www_url_doc_root      = "http://localhost";
-  string www_doc_root          = "/srv/www/spine";
-  string cgi_bin_subpath       = "/cgi-bin";
-  string cgi_filename          = "spine_search";                          // "spine-search"
+  string www_doc_subroot       = "/spine";
+  string cgi_filename          = "spine_search";
   string cgi_search_form_title = "≅ SiSU Spine search";
   string db_sqlite_path        = "/var/www/sqlite";
   string db_sqlite_filename    = "spine.search.db";
-- 
cgit v1.2.3