From 4d0bbc984c29420ef2ac61592c9b69483d817d59 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 1 Apr 2020 17:04:38 -0400 Subject: cgi search form, toggle a documents matched index & text --- org/out_cgi_search_sqlite.org | 168 ++++++++++++++++++------- src/doc_reform/io_out/cgi_sqlite_search_form.d | 145 ++++++++++++++------- 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) { <> <> <> + <> + <> + <> <> <> <> @@ -303,7 +306,6 @@ auto text_fields() { static date = ctRegex!(`(?:^|\s~\s*)date:\s+(?P.+)$`, "m"); static results_type = ctRegex!(`(?:^|\s~\s*)type:\s+(?P.+)$`, "m"); static format = ctRegex!(`(?:^|\s~\s*)format:\s+(?P.+)$`, "m"); - static identifier = ctRegex!(`(?:^|\s~\s*)identifier:\s+(?P.+)$`, "m"); static source = ctRegex!(`(?:^|\s~\s*)source:\s+(?P.+)$`, "m"); static language = ctRegex!(`(?:^|\s~\s*)language:\s+(?P.+)$`, "m"); static relation = ctRegex!(`(?:^|\s~\s*)relation:\s+(?P.+)$`, "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[&]smo=)(?P[0-9]+)`); + static results_type = ctRegex!(`[&]rt=(?Pidx|txt)`); + static results_type_index = ctRegex!(`[&]rt=idx`); + static results_type_text = ctRegex!(`[&]rt=txt`); + static fn = ctRegex!(`[&]fn=(?P[^&]+)`); + } + 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[&]smo=)(?P[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 = + "" + ~ "" + ~ "※" + ~ ""; + 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 - ~ "
\n" + ~ " " + ~ show_matched_objects(row["src_filename_base"].as!string) + ~ "
\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( - "
" - ~ row["ocn"].as!string - ~ "" - ~ "
" - ~ row["body"].as!string - ); + if (row["ocn"].as!string != "0") { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } else { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ 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( - "" - ~ row["ocn"].as!string - ~ ", " - ); + if (row["ocn"].as!string != "0") { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } else { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } } #+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.+)$`, "m"); static results_type = ctRegex!(`(?:^|\s~\s*)type:\s+(?P.+)$`, "m"); static format = ctRegex!(`(?:^|\s~\s*)format:\s+(?P.+)$`, "m"); - static identifier = ctRegex!(`(?:^|\s~\s*)identifier:\s+(?P.+)$`, "m"); static source = ctRegex!(`(?:^|\s~\s*)source:\s+(?P.+)$`, "m"); static language = ctRegex!(`(?:^|\s~\s*)language:\s+(?P.+)$`, "m"); static relation = ctRegex!(`(?:^|\s~\s*)relation:\s+(?P.+)$`, "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[&]smo=)(?P[0-9]+)`); + static results_type = ctRegex!(`[&]rt=(?Pidx|txt)`); + static results_type_index = ctRegex!(`[&]rt=idx`); + static results_type_text = ctRegex!(`[&]rt=txt`); + static fn = ctRegex!(`[&]fn=(?P[^&]+)`); + } + 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 = + "" + ~ "" + ~ "※" + ~ ""; + 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[&]smo=)(?P[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 - ~ "
\n" + ~ " " + ~ show_matched_objects(row["src_filename_base"].as!string) + ~ "
\n" ); } if (cv.results_type == "txt") { - cgi.write( - "
" - ~ row["ocn"].as!string - ~ "" - ~ "
" - ~ row["body"].as!string - ); + if (row["ocn"].as!string != "0") { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } else { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } } else { - cgi.write( - "" - ~ row["ocn"].as!string - ~ ", " - ); + if (row["ocn"].as!string != "0") { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } else { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } } } cgi.write( previous_next); -- cgit v1.2.3