diff options
author | Ralph Amissah <ralph.amissah@gmail.com> | 2020-04-01 17:04:38 -0400 |
---|---|---|
committer | Ralph Amissah <ralph.amissah@gmail.com> | 2020-05-20 11:27:25 -0400 |
commit | 4d0bbc984c29420ef2ac61592c9b69483d817d59 (patch) | |
tree | f159a3b4c5ed44ad079787010b26a05d97b6a721 /src/doc_reform | |
parent | search, simplify & remove un-implemented features (diff) |
cgi search form, toggle a documents matched index & text
Diffstat (limited to 'src/doc_reform')
-rw-r--r-- | src/doc_reform/io_out/cgi_sqlite_search_form.d | 145 |
1 files changed, 102 insertions, 43 deletions
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); |