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 --- src/doc_reform/io_out/cgi_sqlite_search_form.d | 145 +++++++++++++++++-------- 1 file changed, 102 insertions(+), 43 deletions(-) (limited to '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