aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2020-04-01 17:04:38 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2020-05-20 11:27:25 -0400
commit4d0bbc984c29420ef2ac61592c9b69483d817d59 (patch)
treef159a3b4c5ed44ad079787010b26a05d97b6a721
parentsearch, simplify & remove un-implemented features (diff)
cgi search form, toggle a documents matched index & text
-rw-r--r--org/out_cgi_search_sqlite.org168
-rw-r--r--src/doc_reform/io_out/cgi_sqlite_search_form.d145
2 files changed, 227 insertions, 86 deletions
diff --git a/org/out_cgi_search_sqlite.org b/org/out_cgi_search_sqlite.org
index be963cb..04d0c47 100644
--- a/org/out_cgi_search_sqlite.org
+++ b/org/out_cgi_search_sqlite.org
@@ -97,6 +97,9 @@ void cgi_function_intro(Cgi cgi) {
<<cgi_sqlite_initialize_env>>
<<cgi_sqlite_initialize_tail>>
<<cgi_sqlite_initialize_sql_select>>
+ <<cgi_sqlite_initialize_canned_url>>
+ <<cgi_sqlite_initialize_regex_for_canned_search>>
+ <<cgi_sqlite_initialize_show_matched_objects>>
<<cgi_sqlite_initialize_previous_next>>
<<cgi_sqlite_header>>
<<cgi_sqlite_table>>
@@ -303,7 +306,6 @@ auto text_fields() {
static date = ctRegex!(`(?:^|\s~\s*)date:\s+(?P<matched>.+)$`, "m");
static results_type = ctRegex!(`(?:^|\s~\s*)type:\s+(?P<matched>.+)$`, "m");
static format = ctRegex!(`(?:^|\s~\s*)format:\s+(?P<matched>.+)$`, "m");
- static identifier = ctRegex!(`(?:^|\s~\s*)identifier:\s+(?P<matched>.+)$`, "m");
static source = ctRegex!(`(?:^|\s~\s*)source:\s+(?P<matched>.+)$`, "m");
static language = ctRegex!(`(?:^|\s~\s*)language:\s+(?P<matched>.+)$`, "m");
static relation = ctRegex!(`(?:^|\s~\s*)relation:\s+(?P<matched>.+)$`, "m");
@@ -336,7 +338,6 @@ auto text_fields() {
string contributor = ""; // contributor == ct
string date = ""; // date == dt
string format = ""; // format == fmt
- string identifier = ""; // identifier == id
string source = ""; // source == src sfn
string language = ""; // language == lng
string relation = ""; // relation == rl
@@ -436,10 +437,6 @@ auto text_fields() {
got.format = m["matched"];
got.canned_query ~= "&fmt=" ~ m["matched"];
}
- if (auto m = got.search_text_area.matchFirst(rgx.identifier)) {
- got.identifier = m["matched"];
- got.canned_query ~= "&id=" ~ m["matched"];
- }
if (auto m = got.search_text_area.matchFirst(rgx.source)) {
got.source = m["matched"];
got.canned_query ~= "&src=" ~ m["matched"];
@@ -581,10 +578,6 @@ auto text_fields() {
got.format = canned_query["fmt"].split("%%20").join(" ");
got.search_text_area ~= "format: " ~ got.format ~ "\n";
}
- if ("id" in canned_query && !(canned_query["id"]).empty) {
- got.identifier = canned_query["id"].split("%%20").join(" ");
- got.search_text_area ~= "identifier: " ~ got.identifier ~ "\n";
- }
if ("src" in canned_query && !(canned_query["src"]).empty) {
got.source = canned_query["src"].split("%%20").join(" ");
got.search_text_area ~= "source: " ~ got.source ~ "\n";
@@ -646,6 +639,39 @@ auto sql_select = SQL_select();
**** misc
+***** canned url
+
+#+NAME: cgi_sqlite_initialize_canned_url
+#+BEGIN_SRC d
+string canned_url () {
+ string _url = "";
+ if (environment.get("REQUEST_METHOD", "POST") == "POST") {
+ _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query;
+ } else if (environment.get("REQUEST_METHOD", "POST") == "GET") {
+ _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", "");
+ }
+ return _url;
+}
+#+END_SRC
+
+***** canned url regex
+
+#+NAME: cgi_sqlite_initialize_regex_for_canned_search
+#+BEGIN_SRC d
+auto regex_canned_search () {
+ static struct RgxCS {
+ static track_offset = ctRegex!(`(?P<offset_key>[&]smo=)(?P<offset_val>[0-9]+)`);
+ static results_type = ctRegex!(`[&]rt=(?P<results_type>idx|txt)`);
+ static results_type_index = ctRegex!(`[&]rt=idx`);
+ static results_type_text = ctRegex!(`[&]rt=txt`);
+ static fn = ctRegex!(`[&]fn=(?P<fn>[^&]+)`);
+ }
+ return RgxCS();
+}
+#+END_SRC
+
+***** previous & next actions
+
#+NAME: cgi_sqlite_initialize_previous_next
#+BEGIN_SRC d
string base ; // = "";
@@ -653,24 +679,16 @@ string tip ; // = "";
string search_note ; // = "";
uint sql_match_offset_count = 0;
string previous_next () {
- static struct Rgx {
- static track_offset = ctRegex!(`(?P<offset_key>[&]smo=)(?P<offset_val>[0-9]+)`, "m");
- }
- auto rgx = Rgx();
+ auto rgx = regex_canned_search;
string _previous_next = "";
int _current_offset_value = 0;
string _set_offset_next = "";
string _set_offset_previous = "";
- string _url = "";
+ string _url = canned_url;
string _url_previous = "";
string _url_next = "";
string arrow_previous = "";
string arrow_next = "";
- if (environment.get("REQUEST_METHOD", "POST") == "POST") {
- _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query;
- } else if (environment.get("REQUEST_METHOD", "POST") == "GET") {
- _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", "");
- }
if (auto m = _url.matchFirst(rgx.track_offset)) {
_current_offset_value = m.captures["offset_val"].to!int;
_set_offset_next = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int + cv.sql_match_limit.to!int).to!string;
@@ -708,6 +726,42 @@ string previous_next () {
}
#+END_SRC
+***** show matched objects text | index toggle
+
+#+NAME: cgi_sqlite_initialize_show_matched_objects
+#+BEGIN_SRC d
+string show_matched_objects (string fn) {
+ auto rgx = regex_canned_search;
+ string _matched_objects_text = "";
+ string _url = canned_url;
+ string _url_new = "";
+ string _matches_show_text = "&rt=txt";
+ string _matches_show_index = "&rt=idx";
+ string _fn = "&fn=" ~ fn;
+ _url_new = _url;
+ if (_url_new.match(rgx.results_type_index)) {
+ _url_new = _url_new.replace(rgx.results_type_index, _matches_show_text);
+ } else if (_url.match(rgx.results_type_text)) {
+ _url_new = _url_new.replace(rgx.results_type_text, _matches_show_index);
+ } else {
+ if (!(_url.match(rgx.results_type))) {
+ _url_new = _url ~ _matches_show_text;
+ }
+ }
+ if (!(_url_new.match(rgx.fn))) {
+ _url_new = _url_new ~ _fn;
+ }
+ _matched_objects_text =
+ "<font size=\"2\" color=\"#666666\">"
+ ~ "<a href=\""
+ ~ _url_new
+ ~ "\">"
+ ~ "※"
+ ~ "</a></font>";
+ return _matched_objects_text;
+}
+#+END_SRC
+
** cgi
*** cgi html header
@@ -1602,7 +1656,9 @@ LIMIT %%s OFFSET %%s
~ row["language_document_char"].as!string
~ "] "
~ row["creator_author_last_first"].as!string
- ~ "<br>\n"
+ ~ " "
+ ~ show_matched_objects(row["src_filename_base"].as!string)
+ ~ "<br> \n"
);
}
#+END_SRC
@@ -1612,18 +1668,32 @@ LIMIT %%s OFFSET %%s
#+NAME: cgi_sqlite_select_statement_0
#+BEGIN_SRC d
if (cv.results_type == "txt") {
- cgi.write(
- "<hr><a href=\""
- ~ "http://" ~ conf.http_host ~ "/"
- ~ row["language_document_char"].as!string ~ "/html/"
- ~ row["src_filename_base"].as!string ~ "/"
- ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
- ~ "\">"
- ~ row["ocn"].as!string
- ~ "</a>"
- ~ "<br>"
- ~ row["body"].as!string
- );
+ if (row["ocn"].as!string != "0") {
+ cgi.write(
+ "<hr><a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/"
+ ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>"
+ ~ "<br>"
+ ~ row["body"].as!string
+ );
+ } else {
+ cgi.write(
+ "<hr><a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/toc.html"
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>"
+ ~ "<br>"
+ ~ row["body"].as!string
+ );
+ }
#+END_SRC
****** ocn index
@@ -1631,16 +1701,28 @@ LIMIT %%s OFFSET %%s
#+NAME: cgi_sqlite_select_statement_0
#+BEGIN_SRC d
} else {
- cgi.write(
- "<a href=\""
- ~ "http://" ~ conf.http_host ~ "/"
- ~ row["language_document_char"].as!string ~ "/html/"
- ~ row["src_filename_base"].as!string ~ "/"
- ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
- ~ "\">"
- ~ row["ocn"].as!string
- ~ "</a>, "
- );
+ if (row["ocn"].as!string != "0") {
+ cgi.write(
+ "<a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/"
+ ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>, "
+ );
+ } else {
+ cgi.write(
+ "<a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/toc.html"
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>, "
+ );
+ }
}
#+END_SRC
diff --git a/src/doc_reform/io_out/cgi_sqlite_search_form.d b/src/doc_reform/io_out/cgi_sqlite_search_form.d
index 155a544..31cab66 100644
--- a/src/doc_reform/io_out/cgi_sqlite_search_form.d
+++ b/src/doc_reform/io_out/cgi_sqlite_search_form.d
@@ -105,7 +105,6 @@ void cgi_function_intro(Cgi cgi) {
static date = ctRegex!(`(?:^|\s~\s*)date:\s+(?P<matched>.+)$`, "m");
static results_type = ctRegex!(`(?:^|\s~\s*)type:\s+(?P<matched>.+)$`, "m");
static format = ctRegex!(`(?:^|\s~\s*)format:\s+(?P<matched>.+)$`, "m");
- static identifier = ctRegex!(`(?:^|\s~\s*)identifier:\s+(?P<matched>.+)$`, "m");
static source = ctRegex!(`(?:^|\s~\s*)source:\s+(?P<matched>.+)$`, "m");
static language = ctRegex!(`(?:^|\s~\s*)language:\s+(?P<matched>.+)$`, "m");
static relation = ctRegex!(`(?:^|\s~\s*)relation:\s+(?P<matched>.+)$`, "m");
@@ -132,7 +131,6 @@ void cgi_function_intro(Cgi cgi) {
string contributor = ""; // contributor == ct
string date = ""; // date == dt
string format = ""; // format == fmt
- string identifier = ""; // identifier == id
string source = ""; // source == src sfn
string language = ""; // language == lng
string relation = ""; // relation == rl
@@ -225,10 +223,6 @@ void cgi_function_intro(Cgi cgi) {
got.format = m["matched"];
got.canned_query ~= "&fmt=" ~ m["matched"];
}
- if (auto m = got.search_text_area.matchFirst(rgx.identifier)) {
- got.identifier = m["matched"];
- got.canned_query ~= "&id=" ~ m["matched"];
- }
if (auto m = got.search_text_area.matchFirst(rgx.source)) {
got.source = m["matched"];
got.canned_query ~= "&src=" ~ m["matched"];
@@ -364,10 +358,6 @@ void cgi_function_intro(Cgi cgi) {
got.format = canned_query["fmt"].split("%%20").join(" ");
got.search_text_area ~= "format: " ~ got.format ~ "\n";
}
- if ("id" in canned_query && !(canned_query["id"]).empty) {
- got.identifier = canned_query["id"].split("%%20").join(" ");
- got.search_text_area ~= "identifier: " ~ got.identifier ~ "\n";
- }
if ("src" in canned_query && !(canned_query["src"]).empty) {
got.source = canned_query["src"].split("%%20").join(" ");
got.search_text_area ~= "source: " ~ got.source ~ "\n";
@@ -413,29 +403,70 @@ void cgi_function_intro(Cgi cgi) {
string the_range = "";
}
auto sql_select = SQL_select();
+ string canned_url () {
+ string _url = "";
+ if (environment.get("REQUEST_METHOD", "POST") == "POST") {
+ _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query;
+ } else if (environment.get("REQUEST_METHOD", "POST") == "GET") {
+ _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", "");
+ }
+ return _url;
+ }
+ auto regex_canned_search () {
+ static struct RgxCS {
+ static track_offset = ctRegex!(`(?P<offset_key>[&]smo=)(?P<offset_val>[0-9]+)`);
+ static results_type = ctRegex!(`[&]rt=(?P<results_type>idx|txt)`);
+ static results_type_index = ctRegex!(`[&]rt=idx`);
+ static results_type_text = ctRegex!(`[&]rt=txt`);
+ static fn = ctRegex!(`[&]fn=(?P<fn>[^&]+)`);
+ }
+ return RgxCS();
+ }
+ string show_matched_objects (string fn) {
+ auto rgx = regex_canned_search;
+ string _matched_objects_text = "";
+ string _url = canned_url;
+ string _url_new = "";
+ string _matches_show_text = "&rt=txt";
+ string _matches_show_index = "&rt=idx";
+ string _fn = "&fn=" ~ fn;
+ _url_new = _url;
+ if (_url_new.match(rgx.results_type_index)) {
+ _url_new = _url_new.replace(rgx.results_type_index, _matches_show_text);
+ } else if (_url.match(rgx.results_type_text)) {
+ _url_new = _url_new.replace(rgx.results_type_text, _matches_show_index);
+ } else {
+ if (!(_url.match(rgx.results_type))) {
+ _url_new = _url ~ _matches_show_text;
+ }
+ }
+ if (!(_url_new.match(rgx.fn))) {
+ _url_new = _url_new ~ _fn;
+ }
+ _matched_objects_text =
+ "<font size=\"2\" color=\"#666666\">"
+ ~ "<a href=\""
+ ~ _url_new
+ ~ "\">"
+ ~ "※"
+ ~ "</a></font>";
+ return _matched_objects_text;
+ }
string base ; // = "";
string tip ; // = "";
string search_note ; // = "";
uint sql_match_offset_count = 0;
string previous_next () {
- static struct Rgx {
- static track_offset = ctRegex!(`(?P<offset_key>[&]smo=)(?P<offset_val>[0-9]+)`, "m");
- }
- auto rgx = Rgx();
+ auto rgx = regex_canned_search;
string _previous_next = "";
int _current_offset_value = 0;
string _set_offset_next = "";
string _set_offset_previous = "";
- string _url = "";
+ string _url = canned_url;
string _url_previous = "";
string _url_next = "";
string arrow_previous = "";
string arrow_next = "";
- if (environment.get("REQUEST_METHOD", "POST") == "POST") {
- _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query;
- } else if (environment.get("REQUEST_METHOD", "POST") == "GET") {
- _url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", "");
- }
if (auto m = _url.matchFirst(rgx.track_offset)) {
_current_offset_value = m.captures["offset_val"].to!int;
_set_offset_next = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int + cv.sql_match_limit.to!int).to!string;
@@ -1284,33 +1315,61 @@ LIMIT %%s OFFSET %%s
~ row["language_document_char"].as!string
~ "] "
~ row["creator_author_last_first"].as!string
- ~ "<br>\n"
+ ~ " "
+ ~ show_matched_objects(row["src_filename_base"].as!string)
+ ~ "<br> \n"
);
}
if (cv.results_type == "txt") {
- cgi.write(
- "<hr><a href=\""
- ~ "http://" ~ conf.http_host ~ "/"
- ~ row["language_document_char"].as!string ~ "/html/"
- ~ row["src_filename_base"].as!string ~ "/"
- ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
- ~ "\">"
- ~ row["ocn"].as!string
- ~ "</a>"
- ~ "<br>"
- ~ row["body"].as!string
- );
+ if (row["ocn"].as!string != "0") {
+ cgi.write(
+ "<hr><a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/"
+ ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>"
+ ~ "<br>"
+ ~ row["body"].as!string
+ );
+ } else {
+ cgi.write(
+ "<hr><a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/toc.html"
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>"
+ ~ "<br>"
+ ~ row["body"].as!string
+ );
+ }
} else {
- cgi.write(
- "<a href=\""
- ~ "http://" ~ conf.http_host ~ "/"
- ~ row["language_document_char"].as!string ~ "/html/"
- ~ row["src_filename_base"].as!string ~ "/"
- ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
- ~ "\">"
- ~ row["ocn"].as!string
- ~ "</a>, "
- );
+ if (row["ocn"].as!string != "0") {
+ cgi.write(
+ "<a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/"
+ ~ row["seg_name"].as!string ~ ".html#" ~ row["ocn"].as!string
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>, "
+ );
+ } else {
+ cgi.write(
+ "<a href=\""
+ ~ "http://" ~ conf.http_host ~ "/"
+ ~ row["language_document_char"].as!string ~ "/html/"
+ ~ row["src_filename_base"].as!string ~ "/toc.html"
+ ~ "\">"
+ ~ row["ocn"].as!string
+ ~ "</a>, "
+ );
+ }
}
}
cgi.write( previous_next);