From eed0938b23d13ec4f2ef4588ccdb2e7abc0c1552 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 29 Mar 2020 18:29:44 -0400 Subject: 0.10.0 search sqlite & cgi --- .gitignore | 11 +- meson.build | 1 + org/default_misc.org | 2 +- org/default_paths.org | 66 +- org/in_source_files.org | 59 +- org/meta_conf_make_meta.org | 263 +++- org/out_cgi_search_sqlite.org | 1284 ++++++++++++++++++++ org/out_harvest_metadata.org | 5 + org/out_latex.org | 2 +- org/out_metadata.org | 16 +- org/out_odt.org | 1 - org/out_sqlite.org | 119 +- org/out_xmls.org | 49 +- org/output_hub.org | 31 +- org/output_show.org | 44 +- org/spine.org | 274 +++-- org/spine_build_scaffold.org | 12 +- org/util_cgi_d_sqlite_search.org | 1179 ++++++++++++++++++ org/util_cgi_rb_fcgi_sqlite_search.org | 1071 ++++++++++++++++ src/doc_reform/io_in/read_config_files.d | 51 +- src/doc_reform/io_in/read_source_files.d | 8 +- src/doc_reform/io_out/cgi_sqlite_search_form.d | 988 +++++++++++++++ src/doc_reform/io_out/defaults.d | 2 +- src/doc_reform/io_out/hub.d | 26 +- src/doc_reform/io_out/metadata.d | 16 +- src/doc_reform/io_out/odt.d | 1 - src/doc_reform/io_out/paths_output.d | 60 +- src/doc_reform/io_out/sqlite.d | 56 +- src/doc_reform/io_out/xmls.d | 49 +- src/doc_reform/meta/conf_make_meta_json.d | 26 +- src/doc_reform/meta/conf_make_meta_structs.d | 35 +- src/doc_reform/meta/conf_make_meta_yaml.d | 166 ++- src/doc_reform/meta/defaults.d | 2 +- src/doc_reform/meta/metadoc.d | 6 + src/doc_reform/meta/metadoc_show_config.d | 44 +- src/doc_reform/spine.d | 266 ++-- util/d/cgi/search/README | 11 + util/d/cgi/search/dub.sdl | 14 + util/d/cgi/search/dub.selections.json | 7 + .../cgi/search/localhostsqlitespine.search.sql.db | 0 util/d/cgi/search/src/spine_cgi_sqlite_search.d | 913 ++++++++++++++ util/dr_tex.rb | 70 -- util/rb/cgi/search.cgi | 937 ++++++++++++++ util/rb/cgi/search_ref.cgi | 937 ++++++++++++++ util/rb/cgi/sisu_7a_sqlite.cgi | 937 ++++++++++++++ util/rb/cgi/sisu_lng.cgi | 935 ++++++++++++++ util/rb/cgi/sisu_search_pg.cgi | 935 ++++++++++++++ util/rb/cgi/sisu_search_sqlite.cgi | 937 ++++++++++++++ util/rb/cgi/spine.search.cgi | 958 +++++++++++++++ util/rb/tex/dr_tex.rb | 70 ++ views/version.txt | 2 +- 51 files changed, 13295 insertions(+), 659 deletions(-) create mode 100644 org/out_cgi_search_sqlite.org create mode 100644 org/util_cgi_d_sqlite_search.org create mode 100644 org/util_cgi_rb_fcgi_sqlite_search.org create mode 100644 src/doc_reform/io_out/cgi_sqlite_search_form.d create mode 100644 util/d/cgi/search/README create mode 100644 util/d/cgi/search/dub.sdl create mode 100644 util/d/cgi/search/dub.selections.json create mode 100644 util/d/cgi/search/localhostsqlitespine.search.sql.db create mode 100644 util/d/cgi/search/src/spine_cgi_sqlite_search.d delete mode 100755 util/dr_tex.rb create mode 100755 util/rb/cgi/search.cgi create mode 100755 util/rb/cgi/search_ref.cgi create mode 100755 util/rb/cgi/sisu_7a_sqlite.cgi create mode 100755 util/rb/cgi/sisu_lng.cgi create mode 100755 util/rb/cgi/sisu_search_pg.cgi create mode 100755 util/rb/cgi/sisu_search_sqlite.cgi create mode 100755 util/rb/cgi/spine.search.cgi create mode 100755 util/rb/tex/dr_tex.rb diff --git a/.gitignore b/.gitignore index 65910b7..39e781a 100644 --- a/.gitignore +++ b/.gitignore @@ -16,12 +16,11 @@ !conf.sdl !org !util +!util/** +!ext_lib +!ext_lib/** !src -!src/doc_reform -!src/doc_reform/* -!src_yaml -!src_yaml/doc_reform -!src_yaml/doc_reform/* +!src/** !data !data/* !data/src/** @@ -45,6 +44,8 @@ notes/** !notes/reminders !notes/reminders/** .dub/** +**/.dub/** +**/cgi-bin/** tmp/** *_.org *_.d diff --git a/meson.build b/meson.build index c8300ff..d6bb5de 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ spine_sources = [ 'src/doc_reform/io_in/paths_source.d', 'src/doc_reform/io_in/read_config_files.d', 'src/doc_reform/io_in/read_source_files.d', + 'src/doc_reform/io_out/cgi_sqlite_search_form.d', 'src/doc_reform/io_out/create_zip_file.d', 'src/doc_reform/io_out/defaults.d', 'src/doc_reform/io_out/epub3.d', diff --git a/org/default_misc.org b/org/default_misc.org index 88e724d..d96e2bb 100644 --- a/org/default_misc.org +++ b/org/default_misc.org @@ -291,7 +291,7 @@ template InternalMarkup() { string tc_c = "┚"; string tc_p = "┆"; string img = "☼"; - string sep = "␣"; + string sep = "␣"; // "~"; string on_o = "「"; string on_c = "」"; string mk_bullet = "● "; static string indent_by_spaces_provided(int indent, string _indent_spaces ="░░") { diff --git a/org/default_paths.org b/org/default_paths.org index 0e80bb2..789d94e 100644 --- a/org/default_paths.org +++ b/org/default_paths.org @@ -1029,6 +1029,22 @@ template spineOutPathSQLite() { return _PathsStruct(); } } +template spineOutPathSQLiteCGI() { + auto spineOutPathSQLiteCGI(Po)( + Po output_pth_root, + ) { + struct _PathsStruct { + string output_root() { + return (output_pth_root.length > 0) + ? output_pth_root : ""; + } + string output_base() { + return ((output_root).asNormalizedPath).array; + } + } + return _PathsStruct(); + } +} #+END_SRC ** set @@ -1575,9 +1591,9 @@ template spinePathsSQLiteDiscrete() { template spinePathsSQLite() { mixin spineRgxIn; static auto rgx = RgxI(); - auto spinePathsSQLite(DbN, Po)( - DbN db_name, - Po output_pth_root, + auto spinePathsSQLite()( + string db_name, + string output_pth_root, ) { struct _PathsStruct { string base_filename(string fn_src) { @@ -1589,7 +1605,49 @@ template spinePathsSQLite() { return (((out_pth.output_root).chainPath(base_dir)).asNormalizedPath).array; } string sqlite_file() { - return ((base.chainPath(base_filename(db_name) ~ ".sql.db")).asNormalizedPath).array; + return (base.chainPath(db_name).asNormalizedPath).array; + } + } + return _PathsStruct(); + } +} +#+END_SRC + +*** TODO cgi search form + +#+NAME: template_paths_sqlite +#+BEGIN_SRC d +template spinePathsSQLiteCGI() { + mixin spineRgxIn; + static auto rgx = RgxI(); + auto spinePathsSQLiteCGI()( + string cgi_search_form_d, + string cgi_search_form, + string output_pth_root, + ) { + struct _PathsStruct { + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string base() { + auto out_pth = spineOutPathSQLiteCGI!()(output_pth_root); + string base_dir = "cgi"; + return (((out_pth.output_root).chainPath(base_dir)).asNormalizedPath).array; + } + string src() { + return ((base.chainPath("src")).asNormalizedPath).array; + } + string cgi_bin() { + return ((base.chainPath("cgi-bin")).asNormalizedPath).array; + } + string dub_sdl_path_out() { + return ((base.chainPath("dub.sdl")).asNormalizedPath).array; + } + string search_form_dub_path() { + return ("src/".chainPath(base_filename(cgi_search_form_d)).asNormalizedPath).array; + } + string search_form_path_out() { + return (src.chainPath((cgi_search_form_d)).asNormalizedPath).array; } } return _PathsStruct(); diff --git a/org/in_source_files.org b/org/in_source_files.org index 5db71b3..eb813db 100644 --- a/org/in_source_files.org +++ b/org/in_source_files.org @@ -63,30 +63,37 @@ template readConfigSite() { string config_file_str; string default_config_file_str = format(q"┃ flag: - act0: --html - act1: --html --epub -#output: -# path: "" + act0: "--html" + act1: "--html --epub" +output: + path: "/var/www/html" default: - language: "en" - papersize: "a4" - text_wrap: "80" - digest: "sha256" -search: - title: "" - flag: "" - action: "" - db: "" + language: "en" + papersize: "a4" + text_wrap: "80" + digest: "sha256" webserv: - url_domain: "not-configured" - url_root: "doc" - doc_path: "doc" - images: "" - cgi: "" - cgi_host: "" - cgi_host_path: "" - cgi_port: "" - cgi_user: "" + http: "http" + domain: "localhost" + data_http: "http" + data_domain: "localhost" + data_root_url: "http://localhost" + data_root_path: "/var/www/html" + data_root_part: "" + images_root_part: "image" + cgi_title: "≅ SiSU Spine search" + cgi_http: "http" + cgi_domain: "localhost" + cgi_bin_url: "http://localhost/cgi-bin" + cgi_bin_part: "cgi-bin" + cgi_bin_path: "/usr/lib/cgi-bin" + cgi_search_script: "spine-search" + cgi_port: "" + cgi_user: "" + cgi_action: "http://localhost/cgi-bin/spine-search" + db_sqlite: "spine.search.db" + db_pg_table: "" + db_pg_user: "" ┃"); foreach(conf_fn; [_conf_file_details.config_filename_site]) { foreach(pth; _conf_file_details.possible_config_path_locations.config_local_site) { @@ -523,7 +530,7 @@ if (type1["curly_code"] == 1) { } contents_insert ~= line; } else if (line.matchFirst(rgx.block_curly_code_open)) { - type1["curly_code"] = 1; + type1["curly_code"] = 1; type1["header_make"] = 0; type1["header_meta"] = 0; contents_insert ~= line; @@ -535,7 +542,7 @@ if (type1["curly_code"] == 1) { } contents_insert ~= line; } else if (line.matchFirst(rgx.block_tic_code_open)) { - type1["tic_code"] = 1; + type1["tic_code"] = 1; type1["header_make"] = 0; type1["header_meta"] = 0; contents_insert ~= line; @@ -605,7 +612,7 @@ int[string] type = flags_type_init; auto fn_pth_full = fn_src.match(rgx.src_pth_sst_or_ssm); auto markup_src_file_path = fn_pth_full.captures[1]; char[][] contents_insert; -string[] _images =[]; +string[] _images =[]; string[] insert_file_list =[]; #+END_SRC @@ -630,7 +637,7 @@ if (type["curly_code"] == 1) { type["tic_code"] = 1; contents ~= line; } else if (auto m = line.match(rgx.insert_src_fn_ssi_or_sst)) { - auto insert_fn = m.captures[2]; + auto insert_fn = m.captures[2]; auto insert_sub_pth = m.captures[1]; auto fn_src_insert = chainPath(markup_src_file_path, insert_sub_pth ~ insert_fn).array; diff --git a/org/meta_conf_make_meta.org b/org/meta_conf_make_meta.org index ce43d84..8777fde 100644 --- a/org/meta_conf_make_meta.org +++ b/org/meta_conf_make_meta.org @@ -16,6 +16,44 @@ [[./spine.org][spine]] [[./][org/]] * 0. generic +** conf yaml ref + +#+BEGIN_SRC yaml +flag: + act0: "--html" + act1: "--html --epub" +output: + path: "/var/www/html" +default: + language: "en" + papersize: "a4" + text_wrap: "80" + digest: "sha256" +webserv: + http: "http" + domain: "localhost" + data_http: "http" + data_domain: "localhost" + data_root_url: "http://localhost" + data_root_path: "/var/www/html" + data_root_part: "" + images_root_part: "image" + cgi_title: "≅ SiSU Spine search" + cgi_http: "http" + cgi_domain: "localhost" + cgi_bin_url: "http://localhost/cgi-bin" + cgi_bin_part: "cgi-bin" + cgi_bin_path: "/usr/lib/cgi-bin" + cgi_search_script: "spine-search" + cgi_search_script_raw_fn_d: "spine_search.d" + cgi_port: "" + cgi_user: "" + cgi_action: "http://localhost/cgi-bin/spine-search" + db_sqlite: "spine.search.db" + db_pg_table: "" + db_pg_user: "" +#+END_SRC + ** imports #+NAME: meta_defaults_imports @@ -213,16 +251,31 @@ struct ConfCompositeMakeInit { #+NAME: meta_defaults_template_structs #+BEGIN_SRC d struct ConfCompositeSiteLocal { - string webserv_url_doc_root; - string webserv_url_domain; - string webserv_url_doc_path; - string webserv_images; - string webserv_cgi; - string webserv_cgi_host; - string webserv_cgi_host_path; - string webserv_cgi_port; - string webserv_cgi_user; - string webserv_cgi_file_links; + string w_srv_http; + string w_srv_domain; + string w_srv_data_http; // if not set same as webserv_http + string w_srv_data_domain; // if not set same as webserv_domain + string w_srv_data_root_part; + string w_srv_data_root_url; + string w_srv_data_root_path; + string w_srv_images_root_part; + // string w_srv_url_doc_path; + string w_srv_cgi_title; + string w_srv_cgi_http; // if not set same as webserv_http + string w_srv_cgi_domain; // if not set same as webserv_domain + string w_srv_cgi_bin_part; + string w_srv_cgi_bin_path; + string w_srv_cgi_search_script; + string w_srv_cgi_search_script_raw_fn_d; + string w_srv_cgi_port; + string w_srv_cgi_user; + string w_srv_cgi_action; + string w_srv_cgi_bin_url; + string w_srv_db_sqlite; + // string w_srv_db_pg; + string w_srv_db_pg_table; + string w_srv_db_pg_user; + // string webserv_cgi_file_links; string output_path; string processing_path; string processing_dir; @@ -541,57 +594,161 @@ if ("webserv" in _yaml if (_yaml["webserv"].type.mapping && _yaml["webserv"].tag.match(rgx.yaml_tag_is_map) ) { - if ("url_root" in _yaml["webserv"] - && _yaml["webserv"]["url_root"].type.string - && _yaml["webserv"]["url_root"].tag.match(rgx.yaml_tag_is_str) + if ("http" in _yaml["webserv"] + && _yaml["webserv"]["http"].type.string + && _yaml["webserv"]["http"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_url_doc_root = _yaml["webserv"]["url_root"].get!string; - if (auto m = _struct_composite.conf.webserv_url_doc_root.match(rgx.webserv_url_doc_root)) { - _struct_composite.conf.webserv_url_domain = m.captures[2].to!string; - _struct_composite.conf.webserv_url_doc_path = m.captures[3].to!string; - } + _struct_composite.conf.w_srv_http = _yaml["webserv"]["http"].get!string; + } // else { set default? } + if ("data_http" in _yaml["webserv"] + && _yaml["webserv"]["data_http"].type.string + && _yaml["webserv"]["data_http"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_http = _yaml["webserv"]["data_http"].get!string; + } + if ("cgi_http" in _yaml["webserv"] + && _yaml["webserv"]["cgi_http"].type.string + && _yaml["webserv"]["cgi_http"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_http = _yaml["webserv"]["cgi_http"].get!string; + } + if ("domain" in _yaml["webserv"] + && _yaml["webserv"]["domain"].type.string + && _yaml["webserv"]["domain"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_domain = _yaml["webserv"]["domain"].get!string; + } + // if ("data_root_url" in _yaml["webserv"] + // && _yaml["webserv"]["data_root_url"].type.string + // && _yaml["webserv"]["data_root_url"].tag.match(rgx.yaml_tag_is_str) + // ) { + // _struct_composite.conf.w_srv_data_root_url = _yaml["webserv"]["data_root_url"].get!string; + // if (auto m = _struct_composite.conf.w_srv_data_root_url.match(rgx.webserv_url_doc_root)) { + // _struct_composite.conf.w_srv_url_domain = m.captures[2].to!string; + // _struct_composite.conf.w_srv_url_doc_path = m.captures[3].to!string; + // } + // } + if ("data_root_path" in _yaml["webserv"] + && _yaml["webserv"]["data_root_path"].type.string + && _yaml["webserv"]["data_root_path"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_root_path = _yaml["webserv"]["data_root_path"].get!string; + } + if ("data_root_part" in _yaml["webserv"] + && _yaml["webserv"]["data_root_part"].type.string + && _yaml["webserv"]["data_root_part"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_root_part = _yaml["webserv"]["data_root_part"].get!string; + } + if ("images_root_part" in _yaml["webserv"] + && _yaml["webserv"]["images_root_part"].type.string + && _yaml["webserv"]["images_root_part"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_images_root_part = _yaml["webserv"]["images_root_part"].get!string; + } + if ("data_root_url" in _yaml["webserv"] + && _yaml["webserv"]["data_root_url"].type.string + && _yaml["webserv"]["data_root_url"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_root_url = _yaml["webserv"]["data_root_url"].get!string; + } else { + _struct_composite.conf.w_srv_data_root_url = _struct_composite.conf.w_srv_data_root_part; + } + if ("cgi_domain" in _yaml["webserv"] + && _yaml["webserv"]["cgi_domain"].type.string + && _yaml["webserv"]["cgi_domain"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_domain = _yaml["webserv"]["cgi_domain"].get!string; + } else { // composite construct + _struct_composite.conf.w_srv_cgi_domain = _struct_composite.conf.w_srv_domain; + } + if ("cgi_title" in _yaml["webserv"] + && _yaml["webserv"]["cgi_title"].type.string + && _yaml["webserv"]["cgi_title"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_title = _yaml["webserv"]["cgi_title"].get!string; } - if ("images" in _yaml["webserv"] - && _yaml["webserv"]["images"].type.string - && _yaml["webserv"]["images"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_bin_part" in _yaml["webserv"] + && _yaml["webserv"]["cgi_bin_part"].type.string + && _yaml["webserv"]["cgi_bin_part"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_images = _yaml["webserv"]["images"].get!string; + _struct_composite.conf.w_srv_cgi_bin_part = _yaml["webserv"]["cgi_bin_part"].get!string; } - if ("cgi" in _yaml["webserv"] - && _yaml["webserv"]["cgi"].type.string - && _yaml["webserv"]["cgi"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_bin_path" in _yaml["webserv"] + && _yaml["webserv"]["cgi_bin_path"].type.string + && _yaml["webserv"]["cgi_bin_path"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi = _yaml["webserv"]["cgi"].get!string; + _struct_composite.conf.w_srv_cgi_bin_path = _yaml["webserv"]["cgi_bin_path"].get!string; } - if ("cgi_host" in _yaml["webserv"] - && _yaml["webserv"]["cgi_host"].type.string - && _yaml["webserv"]["cgi_host"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_search_script" in _yaml["webserv"] + && _yaml["webserv"]["cgi_search_script"].type.string + && _yaml["webserv"]["cgi_search_script"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_host = _yaml["webserv"]["cgi_host"].get!string; + _struct_composite.conf.w_srv_cgi_search_script = _yaml["webserv"]["cgi_search_script"].get!string; + } else { + _struct_composite.conf.w_srv_cgi_search_script = "spine-search"; } - if ("cgi_host_path" in _yaml["webserv"] - && _yaml["webserv"]["cgi_host_path"].type.string - && _yaml["webserv"]["cgi_host_path"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_search_script_raw_fn_d" in _yaml["webserv"] + && _yaml["webserv"]["cgi_search_script_raw_fn_d"].type.string + && _yaml["webserv"]["cgi_search_script_raw_fn_d"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_host_path = _yaml["webserv"]["cgi_host_path"].get!string; + _struct_composite.conf.w_srv_cgi_search_script_raw_fn_d = _yaml["webserv"]["cgi_search_script_raw_fn_d"].get!string; + } else if ("cgi_search_script" in _yaml["webserv"] + && _yaml["webserv"]["cgi_search_script"].type.string + && _yaml["webserv"]["cgi_search_script"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_search_script_raw_fn_d = (_yaml["webserv"]["cgi_search_script"].get!string).translate(['-' : "_"]) ~ ".d"; + } else { + _struct_composite.conf.w_srv_cgi_search_script_raw_fn_d = "spine_search.d"; } if ("cgi_port" in _yaml["webserv"] && _yaml["webserv"]["cgi_port"].type.string && _yaml["webserv"]["cgi_port"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_port = _yaml["webserv"]["cgi_port"].get!string; + _struct_composite.conf.w_srv_cgi_port = _yaml["webserv"]["cgi_port"].get!string; } if ("cgi_user" in _yaml["webserv"] && _yaml["webserv"]["cgi_user"].type.string && _yaml["webserv"]["cgi_user"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_user = _yaml["webserv"]["cgi_user"].get!string; + _struct_composite.conf.w_srv_cgi_user = _yaml["webserv"]["cgi_user"].get!string; } - if ("cgi_file_links" in _yaml["webserv"] - && _yaml["webserv"]["cgi_file_links"].type.string - && _yaml["webserv"]["cgi_file_links"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_action" in _yaml["webserv"] + && _yaml["webserv"]["cgi_action"].type.string + && _yaml["webserv"]["cgi_action"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_file_links = _yaml["webserv"]["cgi_file_links"].get!string; + _struct_composite.conf.w_srv_cgi_action = _yaml["webserv"]["cgi_action"].get!string; + } else { // action is composite, build + } + if ("cgi_bin_url" in _yaml["webserv"] + && _yaml["webserv"]["cgi_bin_url"].type.string + && _yaml["webserv"]["cgi_bin_url"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_bin_url = _yaml["webserv"]["cgi_bin_url"].get!string; + } else { + _struct_composite.conf.w_srv_cgi_bin_url = + (_struct_composite.conf.w_srv_cgi_http.empty) + ? _struct_composite.conf.w_srv_http + :_struct_composite.conf.w_srv_cgi_http + ~ "://" + ~ (_struct_composite.conf.w_srv_cgi_domain.empty) + ? _struct_composite.conf.w_srv_cgi_domain + : _struct_composite.conf.w_srv_domain + ~ "/" + ~ _struct_composite.conf.w_srv_cgi_bin_part; + } + // if ("cgi_file_links" in _yaml["webserv"] + // && _yaml["webserv"]["cgi_file_links"].type.string + // && _yaml["webserv"]["cgi_file_links"].tag.match(rgx.yaml_tag_is_str) + // ) { + // _struct_composite.conf.w_srv_cgi_file_links = _yaml["webserv"]["cgi_file_links"].get!string; + // } + if ("db_sqlite" in _yaml["webserv"] + && _yaml["webserv"]["db_sqlite"].type.string + && _yaml["webserv"]["db_sqlite"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_db_sqlite = _yaml["webserv"]["db_sqlite"].get!string; + } else { // set default ? } } } @@ -1368,49 +1525,49 @@ if ("make" in _json.object) { #+BEGIN_SRC d /+ conf ------------------------------------------------------------------- +/ if ("webserv" in _json.object) { - if ("url_root" in _json.object["webserv"] - && (_json.object["webserv"]["url_root"].type().to!string == "string") + if ("data_root_url" in _json.object["webserv"] + && (_json.object["webserv"]["data_root_url"].type().to!string == "string") ) { - _struct_composite.conf.webserv_url_doc_root = _json.object["webserv"]["url_root"].str; - if (auto m = _struct_composite.conf.webserv_url_doc_root.match(rgx.webserv_url_doc_root)) { - _struct_composite.conf.webserv_url_domain = m.captures[2].to!string; - _struct_composite.conf.webserv_url_doc_path = m.captures[3].to!string; + _struct_composite.conf.w_srv_data_root_url = _json.object["webserv"]["data_root_url"].str; + if (auto m = _struct_composite.conf.w_srv_data_root_url.match(rgx.webserv_data_root_url)) { + _struct_composite.conf.w_srv_url_domain = m.captures[2].to!string; + _struct_composite.conf.w_srv_url_doc_path = m.captures[3].to!string; } } if ("images" in _json.object["webserv"] && (_json.object["webserv"]["images"].type().to!string == "string") ) { - _struct_composite.conf.webserv_images = _json.object["webserv"]["images"].str; + _struct_composite.conf.w_srv_images = _json.object["webserv"]["images"].str; } if ("cgi" in _json.object["webserv"] && (_json.object["webserv"]["cgi"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi = _json.object["webserv"]["cgi"].str; + _struct_composite.conf.w_srv_cgi = _json.object["webserv"]["cgi"].str; } if ("cgi_host" in _json.object["webserv"] && (_json.object["webserv"]["cgi_host"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_host = _json.object["webserv"]["cgi_host"].str; + _struct_composite.conf.w_srv_cgi_host = _json.object["webserv"]["cgi_host"].str; } if ("cgi_host_path" in _json.object["webserv"] && (_json.object["webserv"]["cgi_host_path"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_host_path = _json.object["webserv"]["cgi_host_path"].str; + _struct_composite.conf.w_srv_cgi_host_path = _json.object["webserv"]["cgi_host_path"].str; } if ("cgi_port" in _json.object["webserv"] && (_json.object["webserv"]["cgi_port"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_port = _json.object["webserv"]["cgi_port"].str; + _struct_composite.conf.w_srv_cgi_port = _json.object["webserv"]["cgi_port"].str; } if ("cgi_user" in _json.object["webserv"] && (_json.object["webserv"]["cgi_user"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_user = _json.object["webserv"]["cgi_user"].str; + _struct_composite.conf.w_srv_cgi_user = _json.object["webserv"]["cgi_user"].str; } if ("cgi_file_links" in _json.object["webserv"] && (_json.object["webserv"]["cgi_file_links"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_file_links = _json.object["webserv"]["cgi_file_links"].str; + _struct_composite.conf.w_srv_cgi_file_links = _json.object["webserv"]["cgi_file_links"].str; } } if ("processing" in _json.object) { diff --git a/org/out_cgi_search_sqlite.org b/org/out_cgi_search_sqlite.org new file mode 100644 index 0000000..91171f4 --- /dev/null +++ b/org/out_cgi_search_sqlite.org @@ -0,0 +1,1284 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) hub +#+DESCRIPTION: documents - structuring, various output representations & search +#+FILETAGS: :spine:hub: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2020 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: content hideblocks hidestars noindent entitiespretty +#+PROPERTY: header-args :exports code +#+PROPERTY: header-args+ :noweb yes +#+PROPERTY: header-args+ :eval no +#+PROPERTY: header-args+ :results no +#+PROPERTY: header-args+ :cache no +#+PROPERTY: header-args+ :padline no + +[[../maker.org][maker.org makefile]] [[./][org/]] + +* cgi search + +cd util/d/cgi/search +dub --force --compiler=ldc2 && sudo cp -v cgi-bin/spine-search /usr/lib/cgi-bin/. + +** 0. set program tangle + +*** output cgi program + +- compile spine + make ldc + +- create db + ~dr/bin/spine-ldc -v \ + --sqlite-db-create --sqlite-db-filename="spine.search.db" \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +- update db + ~dr/bin/spine-ldc -v --sqlite-update --sqlite-db-filename="spine.search.db" \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +- create search form d + ~dr/bin/spine-ldc -v --cgi-search-form-codegen \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod + + ~dr/bin/spine-ldc -v --cgi-search-form-codegen \ + --sqlite-db-filename="spine.search.db" \ + --cgi-sqlite-search-filename="spine-search" \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod + +- create db & search form + ~dr/bin/spine-ldc -v \ + --sqlite-db-create --sqlite-db-filename="spine.search.db" \ + --cgi-search-form-codegen --cgi-sqlite-search-filename="spine-search" \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +- compile cgi search form + cd /var/www/html/cgi # /var/www/html (default document root) + dub --force --compiler=ldc2 && sudo cp -v cgi-bin/spine-search /usr/lib/cgi-bin/. + +- html + ~dr/bin/spine-ldc -v --html --html-link-search \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/cgi_sqlite_search_form.d" +module doc_reform.io_out.cgi_sqlite_search_form; +template CGIsearchSQLite() { + void CGIsearchSQLite(E,O,M)(E env, O opt_action, M make_and_meta_struct) { + import + std.file, + std.format; + import doc_reform.io_out; + string _sqlite_db_fn = (opt_action.sqlite_filename.empty) + ? make_and_meta_struct.conf.w_srv_db_sqlite + : opt_action.sqlite_filename; + string _cgi_search_script = (opt_action.cgi_sqlite_search_filename.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script + : opt_action.cgi_sqlite_search_filename; + string _cgi_search_script_raw_fn_d = (opt_action.cgi_sqlite_search_filename_d.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script_raw_fn_d + : opt_action.cgi_sqlite_search_filename_d; + string the_cgi_search_form = format(q"≓ +<> +<> +void cgi_function_intro(Cgi cgi) { + <> + <> + <> + cv.db_selected = "%s"; + <> + <> + <> + <> + <> + <> + <> +<> +<> +<> + "%s", +<> + <> + <> +<> + <> +<> +} +mixin GenericMain!cgi_function_intro; +≓", + _sqlite_db_fn, + _cgi_search_script, +).strip; + auto pth_sqlite_cgi = spinePathsSQLiteCGI!()(_cgi_search_script_raw_fn_d, _cgi_search_script, opt_action.output_dir_set); // TODO + { // cgi-bin search form src d + try { + if (!exists(pth_sqlite_cgi.src)) { + pth_sqlite_cgi.src.mkdirRecurse; + } + if (!exists(pth_sqlite_cgi.cgi_bin)) { + pth_sqlite_cgi.cgi_bin.mkdirRecurse; + } + auto f = File(pth_sqlite_cgi.search_form_path_out, "w"); + f.write(the_cgi_search_form); + // foreach (o; metadata_) { + // f.writeln(o); + // } + } catch (ErrnoException ex) { + // Handle error + } + // if (!(opt_action.quiet)) { + // writeln(" ", pth_sqlite_cgi.search_form); + // } + } + string the_dub_sdl = format(q"≓ +<> +≓", + "~>0.18.3", // d2sqlite3 dependency version + "src/" ~ _cgi_search_script_raw_fn_d, + _cgi_search_script +).strip; + { // dub.sdl + try { + auto f = File(pth_sqlite_cgi.dub_sdl_path_out, "w"); + f.write(the_dub_sdl); + // foreach (o; metadata_) { + // f.writeln(o); + // } + } catch (ErrnoException ex) { + // Handle error + } + } + } +} +#+END_SRC + +** header + +#+NAME: cgi_sqlite_head +#+BEGIN_SRC d +/+ dub.sdl + name "spine search" + description "spine cgi search" ++/ +#+END_SRC + +** imports + +#+NAME: cgi_sqlite_imports +#+BEGIN_SRC d +import std.format; +import std.range; +import std.regex; +import arsd.cgi; +import d2sqlite3; +import std.process : environment; +#+END_SRC + +** void main +*** initialize + +#+NAME: cgi_sqlite_initialize_head +#+BEGIN_SRC d +string header; +string table; +string form; +#+END_SRC + +**** config + +#+NAME: cgi_sqlite_initialize_config +#+BEGIN_SRC d +struct Config { + string http_request_type; + string http_host; + // string server_name; + string doc_root; + string cgi_root; + string cgi_script; + string data_path_html; + string db_path; + string query_string; + string http_url; + string request_method; +} +auto conf = Config(); +conf.http_request_type = environment.get("REQUEST_SCHEME", "http"); +conf.http_host = environment.get("HTTP_HOST", "localhost"); +// conf.server_name = environment.get("SERVER_NAME", "localhost"); +conf.doc_root = environment.get("DOCUMENT_ROOT", "/var/www/html"); +conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", "/usr/lib/cgi-bin/"); +// conf.cgi_script = environment.get("SCRIPT_NAME", "/cgi-bin/spine-search"); +conf.query_string = environment.get("QUERY_STRING", ""); +conf.http_url = environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string); +conf.db_path = "/var/www/html/sqlite/"; // conf.http_host ~ "/sqlite/"; +conf.request_method = environment.get("REQUEST_METHOD", "POST"); +#+END_SRC + +# REQUEST_URI QUERY_STRING + +**** cgi val + +#+NAME: cgi_sqlite_initialize_cgi_val +#+BEGIN_SRC d +struct CGI_val { + string db_selected = ""; + string sql_match_limit = ""; // radio: ( 1000 | 2500 ) + string sql_match_offset = ""; + string search_text = ""; + string results_type = ""; // index + bool checked_echo = false; + bool checked_stats = false; + bool checked_url = false; + bool checked_searched = false; + bool checked_tip = false; + bool checked_sql = false; +} +auto cv = CGI_val(); +#+END_SRC + +**** text fields +***** open + +#+NAME: cgi_sqlite_initialize_text +#+BEGIN_SRC d +auto text_fields() { + string canned_query_str = environment.get("QUERY_STRING", ""); + if ("query_string" in cgi.post) { + canned_query_str = environment.get("QUERY_STRING", ""); + } + string[string] canned_query; + if (conf.request_method == "POST") { + } else if (conf.request_method == "GET") { + foreach (pair_str; canned_query_str.split("&")) { + // cgi.write(pair_str ~ "
"); + string[] pair = pair_str.split("="); + canned_query[pair[0]] = pair[1]; + } + // foreach (field, content; canned_query) { + // cgi.write(field ~ ": " ~ content ~ "
"); + // } + } +#+END_SRC + +***** rgx + +#+NAME: cgi_sqlite_initialize_rgx +#+BEGIN_SRC d + static struct Rgx { + // static canned_query = ctRegex!(`\A(?P.+)\Z`, "m"); + static search_text_area = ctRegex!(`\A(?P.+)\Z`, "m"); + // static fulltext = ctRegex!(`\A(?P.+)\Z`, "m"); + static line = ctRegex!(`^(?P.+?)(?: ~|$)`, "m"); + static text = ctRegex!(`(?:^|\s~\s*)text:\s+(?P.+?)(?: ~|$)`, "m"); + static author = ctRegex!(`(?:^|\s~\s*)author:\s+(?P.+)$`, "m"); + static title = ctRegex!(`(?:^|\s~\s*)title:\s+(?P.+)$`, "m"); + static uid = ctRegex!(`(?:^|\s~\s*)uid:\s+(?P.+)$`, "m"); + static fn = ctRegex!(`(?:^|\s~\s*)fn:\s+(?P.+)$`, "m"); + static keywords = ctRegex!(`(?:^|\s~\s*)keywords:\s+(?P.+)$`, "m"); + static topic_register = ctRegex!(`(?:^|\s~\s*)topic_register:\s+(?P.+)$`, "m"); + static subject = ctRegex!(`(?:^|\s~\s*)subject:\s+(?P.+)$`, "m"); + static description = ctRegex!(`(?:^|\s~\s*)description:\s+(?P.+)$`, "m"); + static publisher = ctRegex!(`(?:^|\s~\s*)publisher:\s+(?P.+)$`, "m"); + static editor = ctRegex!(`(?:^|\s~\s*)editor:\s+(?P.+)$`, "m"); + static contributor = ctRegex!(`(?:^|\s~\s*)contributor:\s+(?P.+)$`, "m"); + 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"); + static coverage = ctRegex!(`(?:^|\s~\s*)coverage:\s+(?P.+)$`, "m"); + static rights = ctRegex!(`(?:^|\s~\s*)rights:\s+(?P.+)$`, "m"); + static comment = ctRegex!(`(?:^|\s~\s*)comment:\s+(?P.+)$`, "m"); + // static abstract_ = ctRegex!(`(?:^|\s~\s*)abstract:\s+(?P.+)$`, "m"); + static src_filename_base = ctRegex!(`^src_filename_base:\s+(?P.+)$`, "m"); + } +#+END_SRC + +***** searchfields + +#+NAME: cgi_sqlite_initialize_fields +#+BEGIN_SRC d + struct searchFields { + string canned_query = ""; // GET canned_query == cq + string search_text_area = ""; // POST search_text_area == tsa + string text = ""; // text == txt + string author = ""; // author == au + string title = ""; // title == ti + string uid = ""; // uid == uid + string fn = ""; // fn == fn + string keywords = ""; // keywords == kw + string topic_register = ""; // topic_register == tr + string subject = ""; // subject == su + string description = ""; // description == de + string publisher = ""; // publisher == pb + string editor = ""; // editor == ed + 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 + string coverage = ""; // coverage == cv + string rights = ""; // rights == rgt + string comment = ""; // comment == cmt + // string abstract = ""; + string src_filename_base = ""; // src_filename_base == bfn + string results_type = ""; // results_type == rt radio + string sql_match_limit = ""; // sql_match_limit == sml radio + string sql_match_offset = ""; // sql_match_offset == smo + string stats = ""; // stats == sts checked + string echo = ""; // echo == ec checked + string url = ""; // url == url checked + string searched = ""; // searched == se checked + string sql = ""; // sql == sql checked + } + auto rgx = Rgx(); + auto got = searchFields(); +#+END_SRC + +***** env +****** POST + +#+NAME: cgi_sqlite_initialize_env +#+BEGIN_SRC d + if (environment.get("REQUEST_METHOD", "POST") == "POST") { + if ("sf" in cgi.post) { + got.search_text_area = cgi.post["sf"]; + if (auto m = got.search_text_area.matchFirst(rgx.text)) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } else if (auto m = got.search_text_area.matchFirst(rgx.line)) { + if ( + !(m["matched"].matchFirst(rgx.author)) + && !(m["matched"].matchFirst(rgx.title)) + ) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } + } + if (auto m = got.search_text_area.matchFirst(rgx.author)) { + got.author = m["matched"]; + got.canned_query ~= "&au=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.title)) { + got.title = m["matched"]; + got.canned_query ~= "&ti=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.uid)) { + got.uid = m["matched"]; + got.canned_query ~= "&uid=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.fn)) { + got.fn = m["matched"]; + got.canned_query ~= "&fn=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.keywords)) { + got.keywords = m["matched"]; + got.canned_query ~= "&kw=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.topic_register)) { + got.topic_register = m["matched"]; + got.canned_query ~= "&tr=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.subject)) { + got.subject = m["matched"]; + got.canned_query ~= "&su=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.description)) { + got.description = m["matched"]; + got.canned_query ~= "&de=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.publisher)) { + got.publisher = m["matched"]; + got.canned_query ~= "&pb=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.editor)) { + got.editor = m["matched"]; + got.canned_query ~= "&ed=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.contributor)) { + got.contributor = m["matched"]; + got.canned_query ~= "&ct=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.date)) { + got.date = m["matched"]; + got.canned_query ~= "&dt=" ~ m["matched"]; + } + // if (auto m = got.search_text_area.matchFirst(rgx.results_type)) { + // got.results_type = m["matched"]; + // got.canned_query ~= "&rt=" ~ m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.format)) { + 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"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.language)) { + got.language = m["matched"]; + got.canned_query ~= "&lng=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.relation)) { + got.relation = m["matched"]; + got.canned_query ~= "&rl=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.coverage)) { + got.coverage = m["matched"]; + got.canned_query ~= "&cv=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.rights)) { + got.rights = m["matched"]; + got.canned_query ~= "&rgt=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.comment)) { + got.comment = m["matched"]; + got.canned_query ~= "&cmt=" ~ m["matched"]; + } + // if (auto m = search_text_area.matchFirst(rgx.abstract)) { + // got.abstract = m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.src_filename_base)) { + got.src_filename_base = m["matched"]; + got.canned_query ~= "&bfn=" ~ m["matched"]; + } + } + if ("fn" in cgi.post) { + got.fn = cgi.post["fn"]; + got.canned_query ~= "&fn=" ~ cgi.post["fn"]; + } + if ("rt" in cgi.post) { + got.results_type = cgi.post["rt"]; + got.canned_query ~= "&rt=" ~ cgi.post["rt"]; + } + if ("sts" in cgi.post) { + got.stats = cgi.post["sts"]; + got.canned_query ~= "&sts=" ~ cgi.post["sts"]; + } + if ("ec" in cgi.post) { + got.echo = cgi.post["ec"]; + got.canned_query ~= "&ec=" ~ cgi.post["ec"]; + } + if ("url" in cgi.post) { + got.url = cgi.post["url"]; + got.canned_query ~= "&url=" ~ cgi.post["url"]; + } + if ("se" in cgi.post) { + got.searched = cgi.post["se"]; + got.canned_query ~= "&se=" ~ cgi.post["se"]; + } + if ("sql" in cgi.post) { + got.sql = cgi.post["sql"]; + got.canned_query ~= "&sql=" ~ cgi.post["sql"]; + } + if ("sml" in cgi.post) { + got.sql_match_limit = cgi.post["sml"]; + got.canned_query ~= "&sml=" ~ cgi.post["sml"]; + } + if ("smo" in cgi.post) { + got.sql_match_offset = "0"; // cgi.post["smo"]; + got.canned_query ~= "&smo=0"; // ~ cgi.post["smo"]; + } + got.canned_query = got.canned_query.strip.split(" ").join("%%20"); + conf.query_string = got.canned_query; + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); +#+END_SRC + +****** GET + +#+NAME: cgi_sqlite_initialize_env +#+BEGIN_SRC d + } else if (environment.get("REQUEST_METHOD", "POST") == "GET") { + got.canned_query = environment.get("QUERY_STRING", ""); + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); + got.search_text_area = ""; + if ("sf" in canned_query && !(canned_query["sf"]).empty) { + got.text = canned_query["sf"].split("%%20").join(" "); + got.search_text_area ~= "text: " ~ got.text ~ "\n"; + } + if ("au" in canned_query && !(canned_query["au"]).empty) { + got.author = canned_query["au"].split("%%20").join(" "); + got.search_text_area ~= "author: " ~ got.author ~ "\n"; + } + if ("ti" in canned_query && !(canned_query["ti"]).empty) { + got.title = canned_query["ti"].split("%%20").join(" "); + got.search_text_area ~= "title: " ~ got.title ~ "\n"; + } + if ("uid" in canned_query && !(canned_query["uid"]).empty) { + got.uid = canned_query["uid"].split("%%20").join(" "); + got.search_text_area ~= "uid: " ~ got.uid ~ "\n"; + } + if ("fn" in canned_query && !(canned_query["fn"]).empty) { + got.fn = canned_query["fn"].split("%%20").join(" "); + got.search_text_area ~= "fn: " ~ got.fn ~ "\n"; + } + if ("kw" in canned_query && !(canned_query["kw"]).empty) { + got.keywords = canned_query["kw"].split("%%20").join(" "); + got.search_text_area ~= "keywords: " ~ got.keywords ~ "\n"; + } + if ("tr" in canned_query && !(canned_query["tr"]).empty) { + got.topic_register = canned_query["tr"].split("%%20").join(" "); + got.search_text_area ~= "topic_register: " ~ got.topic_register ~ "\n"; + } + if ("su" in canned_query && !(canned_query["su"]).empty) { + got.subject = canned_query["su"].split("%%20").join(" "); + got.search_text_area ~= "subject: " ~ got.subject ~ "\n"; + } + if ("de" in canned_query && !(canned_query["de"]).empty) { + got.description = canned_query["de"].split("%%20").join(" "); + got.search_text_area ~= "description: " ~ got.description ~ "\n"; + } + if ("pb" in canned_query && !(canned_query["pb"]).empty) { + got.publisher = canned_query["pb"].split("%%20").join(" "); + got.search_text_area ~= "publisher: " ~ got.publisher ~ "\n"; + } + if ("ed" in canned_query && !(canned_query["ed"]).empty) { + got.editor = canned_query["ed"].split("%%20").join(" "); + got.search_text_area ~= "editor: " ~ got.editor ~ "\n"; + } + if ("ct" in canned_query && !(canned_query["ct"]).empty) { + got.contributor = canned_query["ct"].split("%%20").join(" "); + got.search_text_area ~= "contributor: " ~ got.contributor ~ "\n"; + } + if ("dt" in canned_query && !(canned_query["dt"]).empty) { + got.date = canned_query["dt"].split("%%20").join(" "); + got.search_text_area ~= "date: " ~ got.date ~ "\n"; + } + if ("rt" in canned_query && !(canned_query["rt"]).empty) { + got.results_type = canned_query["rt"].split("%%20").join(" "); + // got.search_text_area ~= "results_type: " ~ got.results_type ~ "\n"; + } + if ("fmt" in canned_query && !(canned_query["fmt"]).empty) { + 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"; + } + if ("lng" in canned_query && !(canned_query["lng"]).empty) { + got.language = canned_query["lng"].split("%%20").join(" "); + got.search_text_area ~= "language: " ~ got.language ~ "\n"; + } + if ("rl" in canned_query && !(canned_query["rl"]).empty) { + got.relation = canned_query["rl"].split("%%20").join(" "); + got.search_text_area ~= "relation: " ~ got.relation ~ "\n"; + } + if ("cv" in canned_query && !(canned_query["cv"]).empty) { + got.coverage = canned_query["cv"].split("%%20").join(" "); + got.search_text_area ~= "coverage: " ~ got.coverage ~ "\n"; + } + if ("rgt" in canned_query && !(canned_query["rgt"]).empty) { + got.rights = canned_query["rgt"].split("%%20").join(" "); + got.search_text_area ~= "rights: " ~ got.rights ~ "\n"; + } + if ("cmt" in canned_query && !(canned_query["cmt"]).empty) { + got.comment = canned_query["cmt"].split("%%20").join(" "); + got.search_text_area ~= "comment: " ~ got.comment ~ "\n"; + } + // if ("abstract" in canned_query && !(canned_query["abstract"]).empty) { + // got.abstract = canned_query["abstract"]; + // } + if ("bfn" in canned_query && !(canned_query["bfn"]).empty) { // search_field + got.src_filename_base = canned_query["bfn"].split("%%20").join(" "); + got.search_text_area ~= "src_filename_base: " ~ got.src_filename_base ~ "\n"; + } + if ("sml" in canned_query && !(canned_query["sml"]).empty) { + got.sql_match_limit = canned_query["sml"].split("%%20").join(" "); + // got.search_text_area ~= "sql_match_limit: " ~ got.sql_match_limit ~ "\n"; + } + // cgi.write("f.search_text_area: " ~ got.search_text_area ~ "
"); + } + return got; +#+END_SRC + +***** tail + +#+NAME: cgi_sqlite_initialize_tail +#+BEGIN_SRC d +} +auto tf = text_fields; // +#+END_SRC + +**** SQL select + +#+NAME: cgi_sqlite_initialize_sql_select +#+BEGIN_SRC d +struct SQL_select { + string the_body = ""; + string the_range = ""; +} +auto sql_select = SQL_select(); +#+END_SRC + +**** misc + +#+NAME: cgi_sqlite_initialize_previous_next +#+BEGIN_SRC d +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(); + string _previous_next = ""; + int _current_offset_value = 0; + string _set_offset_next = ""; + string _set_offset_previous = ""; + string _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; + _url_next = _url.replace(rgx.track_offset, _set_offset_next); + if (_current_offset_value < cv.sql_match_limit.to!int) { + _url_previous = ""; + } else { + _url_previous = ""; + _set_offset_previous = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int - cv.sql_match_limit.to!int).to!string; + _url_previous = _url.replace(rgx.track_offset, _set_offset_previous); + } + } else {// _current_offset_value = 0; + _url_next = _url ~= "&smo=" ~ cv.sql_match_limit.to!string; + } + if (_url_previous.empty) { + arrow_previous = ""; + } else { + arrow_previous = + "" + ~ "" + ~ "<< prev" + ~ " || "; + } + arrow_next = + "" + ~ "" + ~ "next >>" + ~ ""; + _previous_next = "
" ~ arrow_previous ~ arrow_next; + return _previous_next; +} +#+END_SRC + +** cgi +*** cgi html header + +#+NAME: cgi_sqlite_header +#+BEGIN_SRC d + { + header = format(q"┃ + + + + + + ≅ SiSU spine search form + + + + + + + +┃", + conf.http_host, + ); + } +#+END_SRC + +*** cgi html table + +#+NAME: cgi_sqlite_table +#+BEGIN_SRC d + { + table = format(q"┃ + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+ ┃"); + } +#+END_SRC + +*** cgi html form + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + { + string post_value(string field_name, string type="box", string set="on") { + string val = ""; + switch (type) { + case "field": + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? cgi.post[field_name] + : (field_name in cgi.get) + ? cgi.get[field_name] + : ""); + val = tf.search_text_area; + break; + case "box": // generic for checkbox or radio; checkbox set == "on" radio set == "name set" + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "off"); + break; + case "radio": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + case "checkbox": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + default: + } + return val; + } +#+END_SRC + +**** canned search + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + string the_can(string fv) { + string show_the_can = post_value("url"); + string _the_can = ""; + if (show_the_can == "checked") { + tf = text_fields; + string method_get_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", ""); + string method_post_url_construct = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query; + // assert(method_get_url == environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string)); + if (conf.request_method == "POST") { + _the_can = + "" + ~ "POST: " + ~ "" + ~ method_post_url_construct + ~ "" + ~ "
"; + } else if (conf.request_method == "GET") { + _the_can = + "" + ~ "GET:  " + ~ "" + ~ method_get_url + ~ ""; + } + conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ tf.canned_query; + } + return _the_can; + } +#+END_SRC + +**** provide tip + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + string provide_tip() { + string searched_tip = post_value("se"); + string tip = ""; + if (searched_tip == "checked") { + string search_field = post_value("sf", "field"); + tf = text_fields; + tip = format(q"┃ + +database: %%s; selected view: index +search string: %%s %%s %%s %%s %%s %%s
+%%s %%s %%s %%s %%s %%s +
+┃", + cv.db_selected, + (tf.text.empty ? "" : "\"text: " ~ tf.text ~ "; "), + (tf.title.empty ? "" : "\"title: " ~ tf.title ~ "; "), + (tf.author.empty ? "" : "\"author: " ~ tf.author ~ "; "), + (tf.date.empty ? "" : "\"date " ~ tf.date ~ "; "), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + (tf.text.empty ? "" : "text: " ~ tf.text ~ "
"), + (tf.title.empty ? "" : "title: " ~ tf.title ~ "
"), + (tf.author.empty ? "" : "author: " ~ tf.author ~ "
"), + (tf.date.empty ? "" : "date: " ~ tf.date ~ "
"), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + ); + } + return tip; + } +#+END_SRC + +**** the form +***** form html + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + form = format(q"┃ +
+ + +
+ + + %%s + %%s + %%s +
+ + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep; + match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement + +
+
+ + +
+┃", +#+END_SRC + +***** form values + +#+NAME: cgi_sqlite_form_post +#+BEGIN_SRC d + (post_value("ec") == "checked") ? post_value("sf", "field") : "", + provide_tip, + search_note, + the_can(post_value("sf", "field")), + cv.db_selected, + cv.db_selected, + post_value("rt", "box", "idx"), + post_value("rt", "box", "txt"), + post_value("sml", "box", "1000"), + post_value("sml", "box", "2500"), + post_value("ec"), + post_value("sts"), + post_value("url"), + post_value("se"), + post_value("tip"), + post_value("sql"), + ); +#+END_SRC + +**** set value (debug) + +#+NAME: cgi_sqlite_form_post +#+BEGIN_SRC d + { + string set_value(string field_name, string default_val) { + string val; + if (field_name in cgi.post) { + val = cgi.post[field_name]; + } else if (field_name in cgi.get) { + val = cgi.get[field_name]; + } else { val = default_val; } + return val; + } + bool set_bool(string field_name) { + bool val; + if (field_name in cgi.post + && cgi.post[field_name] == "on") { + val = true; + } else if (field_name in cgi.get + && cgi.get[field_name] == "on") { + val = true; + } else { val = false; } + return val; + } + cv.db_selected = set_value("selected_db", "spine.search.db"); // selected_db == db + cv.sql_match_limit = set_value("sml", "1000"); + cv.sql_match_offset = set_value("smo", "0"); + cv.search_text = set_value("sf", ""); + cv.results_type = set_value("rt", "idx"); + cv.checked_echo = set_bool("ec"); + cv.checked_stats = set_bool("sts"); + cv.checked_url = set_bool("url"); + cv.checked_searched = set_bool("se"); + cv.checked_tip = set_bool("tip"); + cv.checked_sql = set_bool("sql"); + tf = text_fields; + } + } +#+END_SRC + +*** cgi write + +#+NAME: cgi_sqlite_write +#+BEGIN_SRC d +{ + cgi.write(header); + cgi.write(table); + cgi.write(form); + // cgi.write(previous_next); + { // debug environment + // foreach (k, d; environment.toAA) { + // cgi.write(k ~ ": " ~ d ~ "
"); + // } + } + { // debug cgi info + // cgi.write("db_selected: " ~ cv.db_selected ~ "
\n"); + // cgi.write("search_text: " ~ cv.search_text ~ "
\n"); + // cgi.write("sql_match_limit: " ~ cv.sql_match_limit ~ ";\n"); + // cgi.write("sql_match_offset: " ~ cv.sql_match_offset ~ ";\n"); + // cgi.write("results_type: " ~ cv.results_type ~ "
\n"); + // cgi.write("cv.checked_echo: " ~ (cv.checked_echo ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_stats: " ~ (cv.checked_stats ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_url: " ~ (cv.checked_url ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_searched: " ~ (cv.checked_searched ? "checked" : "off") ~ ";
\n"); + // cgi.write("cv.checked_tip: " ~ (cv.checked_tip ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_sql: " ~ (cv.checked_sql ? "checked" : "off") ~ "
\n"); + } +} +#+END_SRC + +** db +*** db set + +#+NAME: cgi_sqlite_set_db +#+BEGIN_SRC d +auto db = Database(conf.db_path ~ cv.db_selected); +#+END_SRC + +*** db select statement +**** select where + +#+NAME: cgi_sqlite_select_statement_0 +#+BEGIN_SRC d + { + uint sql_match_offset_counter(T)(T cv) { + sql_match_offset_count += cv.sql_match_limit.to!uint; + return sql_match_offset_count; + } + void sql_search_query() { + string select_field_like(string db_field, string search_field) { + string where_ = ""; + if (!(search_field.empty)) { + string _sf = search_field.strip.split("%%20").join(" "); + if (_sf.match(r" OR ")) { + _sf = _sf.split(" OR ").join("%%' OR " ~ db_field ~ " LIKE '%%"); + } + if (_sf.match(r" AND ")) { + _sf = _sf.split(" AND ").join("%%' AND " ~ db_field ~ " LIKE '%%"); + } + _sf = "( " ~ db_field ~ " LIKE\n '%%" ~ _sf ~ "%%' )"; + where_ ~= format(q"┃ + %%s +┃", + _sf + ); + } + return where_; + } + string[] _fields; + _fields ~= select_field_like("doc_objects.clean", tf.text); + _fields ~= select_field_like("metadata_and_text.title", tf.title); + _fields ~= select_field_like("metadata_and_text.creator_author", tf.author); + _fields ~= select_field_like("metadata_and_text.uid", tf.uid); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.fn); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.src_filename_base); + _fields ~= select_field_like("metadata_and_text.language_document_char", tf.language); + _fields ~= select_field_like("metadata_and_text.date_published", tf.date); + _fields ~= select_field_like("metadata_and_text.classify_keywords", tf.keywords); + _fields ~= select_field_like("metadata_and_text.classify_topic_register", tf.topic_register); + string[] fields; + foreach (f; _fields) { + if (!(f.empty)) { fields ~= f; } + } + string fields_str = ""; + fields_str ~= fields.join(" AND "); +#+END_SRC + +**** db select statement +***** the body + +#+NAME: cgi_sqlite_select_statement_0 +#+BEGIN_SRC d + sql_select.the_body ~= format(q"┃ +SELECT + metadata_and_text.uid, + metadata_and_text.title, + metadata_and_text.creator_author_last_first, + metadata_and_text.creator_author, + metadata_and_text.src_filename_base, + metadata_and_text.language_document_char, + metadata_and_text.date_published, + metadata_and_text.classify_keywords, + metadata_and_text.classify_topic_register, + doc_objects.body, + doc_objects.seg_name, + doc_objects.ocn, + metadata_and_text.uid +FROM + doc_objects, + metadata_and_text +WHERE ( + %%s + ) +AND + doc_objects.uid_metadata_and_text = metadata_and_text.uid +ORDER BY + metadata_and_text.creator_author_last_first, + metadata_and_text.date_published DESC, + metadata_and_text.title, + metadata_and_text.language_document_char, + metadata_and_text.src_filename_base, + doc_objects.ocn +LIMIT %%s OFFSET %%s +;┃", + fields_str, + cv.sql_match_limit, + cv.sql_match_offset, + ); +#+END_SRC + +***** html write selected +****** ocn index + +#+NAME: cgi_sqlite_select_statement_0 +#+BEGIN_SRC d + (cv.checked_sql) + ? cgi.write(previous_next ~ "
" ~ sql_select.the_body.split("\n ").join(" ").split("\n").join("
") ~ "
\n") + : ""; + cgi.write(previous_next); + auto select_query_results = db.execute(sql_select.the_body).cached; + string _old_uid = ""; + if (!select_query_results.empty) { + foreach (row; select_query_results) { + if (row["uid"].as!string != _old_uid) { + _old_uid = row["uid"].as!string; + auto m = (row["date_published"].as!string).match(regex(r"^([0-9]{4})")); // breaks if row missing or no match? + cgi.write( + "
\"" + ~ row["title"].as!string ~ "\"" + ~ " (" + ~ m.hit + ~ ") " + ~ "[" + ~ row["language_document_char"].as!string + ~ "] " + ~ row["creator_author_last_first"].as!string + ~ ":
\n" + ); + } + if (cv.results_type == "txt") { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } else { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } + } + cgi.write( previous_next); + } else { // offset_not_beyond_limit = false; + cgi.write("select_query_results empty

\n"); + } + } + sql_search_query; + } +#+END_SRC + +****** text found + +*** db close + +#+NAME: cgi_sqlite_db_close +#+BEGIN_SRC d +{ + db.close; +} +#+END_SRC + +** tail +*** cgi tail + +#+NAME: cgi_sqlite_db_tail +#+BEGIN_SRC d + { + string tail = format(q"┃ + +┃"); + cgi.write(tail); + } +#+END_SRC + +* cgi-search dub.sdl + +#+NAME: cgi_dub_sdl +#+BEGIN_SRC d +name "spine_cgi_sqlite_search" +description "spine cgi sqlite search" +authors "Ralph Amissah" +copyright "Copyright © 2020, Ralph Amissah" +license "GPL-3.0+" +dependency "d2sqlite3" version="%s" +targetType "executable" +targetPath "./cgi-bin" +mainSourceFile "%s" +configuration "default" { + targetType "executable" + targetName "%s" + postGenerateCommands "/usr/bin/notify-send -t 0 'D executable ready' 'spine cgi sqlite search d'" +} +#+END_SRC + +* cgi-search README + +#+BEGIN_SRC text :NO-tangle "../util/d/cgi/search/README" +change db name to match name of db you create +cv.db_selected = "spine.search.sql.db"; + +~dr/bin/spine-ldc -v --sqlite-db-create --sqlite-db-filename="spine.search.db" --cgi-sqlite-search-filename="spine-search" --output=/var/www ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +~dr/bin/spine-ldc -v --sqlite-update --sqlite-db-filename="spine.search.db" --output=/var/www ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +cd util/d/cgi/search/src +dub --force --compiler=ldc2 && sudo cp -v cgi-bin/spine-search /usr/lib/cgi-bin/. + +http://localhost/cgi-bin/spine-search? +#+END_SRC diff --git a/org/out_harvest_metadata.org b/org/out_harvest_metadata.org index c130f9f..bcd4472 100644 --- a/org/out_harvest_metadata.org +++ b/org/out_harvest_metadata.org @@ -16,6 +16,11 @@ * document harvest _summary_ :module:spine:metadoc_show_summary: +- html + ~dr/bin/spine-ldc -v --html --html-link-harvest --harvest \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + ** _module template_ metadoc harvest #+BEGIN_SRC d :tangle "../src/doc_reform/meta/metadoc_harvest.d" diff --git a/org/out_latex.org b/org/out_latex.org index 501fba7..66f086c 100644 --- a/org/out_latex.org +++ b/org/out_latex.org @@ -1884,7 +1884,7 @@ string latex_tail(M)( * latex system command helper script ** latex command, ruby script -#+BEGIN_SRC ruby :tangle "../util/dr_tex.rb" :tangle-mode (identity #o755) :shebang #!/usr/bin/env ruby +#+BEGIN_SRC ruby :tangle "../util/rb/tex/dr_tex.rb" :tangle-mode (identity #o755) :shebang #!/usr/bin/env ruby require 'fileutils' pwd = Dir.pwd argv,texfiles_with_path,flags=[],[],[] diff --git a/org/out_metadata.org b/org/out_metadata.org index 4ed857b..f7f8700 100644 --- a/org/out_metadata.org +++ b/org/out_metadata.org @@ -77,7 +77,7 @@ metadata_ ~= format(q"┃ ┃"); -if (doc_matters.opt.action.harvest_link) { +if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= format(q"┃

[ HOME ] Metadata Harvest [ Authors ] [ Topics ]

@@ -94,7 +94,7 @@ if (!(doc_matters.conf_make_meta.meta.title_full.empty)) { writeln("ERROR no Title information provided in document header ", doc_matters.src.filename_base); } if (!(doc_matters.conf_make_meta.meta.creator_author.empty)) { - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

Author: " ~ doc_matters.conf_make_meta.meta.creator_author ~ "

"; } else { @@ -139,7 +139,7 @@ if (doc_matters.conf_make_meta.meta.classify_topic_register_arr.length > 0) { if (subject_tree.length > 0) { if (subject_tree[0] != _top[0]) { _top[0] = subject_tree[0]; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

" @@ -154,7 +154,7 @@ if (doc_matters.conf_make_meta.meta.classify_topic_register_arr.length > 0) { if (subject_tree[1] != _top[1]) { _top[1] = subject_tree[1]; _top[2] = ""; _top[3] = ""; _top[4] = ""; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

0) { if (subject_tree[2] != _top[2]) { _top[2] = subject_tree[2]; _top[3] = ""; _top[4] = ""; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

0) { if (subject_tree[3] != _top[3]) { _top[3] = subject_tree[3]; _top[4] = ""; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

0) { if (subject_tree.length > 4) { if (subject_tree[4] != _top[4]) { _top[4] = subject_tree[4]; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

+ diff --git a/org/out_odt.org b/org/out_odt.org index b4a8acd..d7d1100 100644 --- a/org/out_odt.org +++ b/org/out_odt.org @@ -70,7 +70,6 @@ template outputODT() { <> <> <> - <> <> } #+END_SRC diff --git a/org/out_sqlite.org b/org/out_sqlite.org index 32daf8e..944ed18 100644 --- a/org/out_sqlite.org +++ b/org/out_sqlite.org @@ -17,19 +17,61 @@ - [[./spine.org][spine]] [[./][org/]] - [[./output_hub.org][output_hub]] +sudo chown ralph:ralph /var/www + +- create db + ~dr/bin/spine-ldc -v \ + --sqlite-db-create --sqlite-db-filename="spine.search.db" \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +- update db + ~dr/bin/spine-ldc -v \ + --sqlite-update --sqlite-db-filename="spine.search.db" \ + --output=/var/www/html \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +- produce html (and some other) output files + ~dr/bin/spine-ldc -v --html --epub --latex --odt \ + --output=/var/www \ + ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + * sql ** _module, templates_ :module: -*** hub -**** collection +*** template #+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" module doc_reform.io_out.sqlite; -<> +<> +<> +<> +<> +<> +<> +<> +<> +<> +<> +<> +<> +#+END_SRC + +*** hub +**** common + +#+NAME: sqlite_common +#+BEGIN_SRC d mixin spineRgxOut; mixin InternalMarkup; static auto rgx = RgxO(); static auto mkup = InlineMarkup(); long _metadata_tid_lastrowid; +#+END_SRC + +**** collection + +#+NAME: sqlite_collection +#+BEGIN_SRC d template SQLiteHubBuildTablesAndPopulate() { void SQLiteHubBuildTablesAndPopulate(D,M)( const D doc_abstraction, @@ -57,13 +99,14 @@ template SQLiteHubBuildTablesAndPopulate() { **** discrete -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_discrete +#+BEGIN_SRC d template SQLiteHubDiscreteBuildTablesAndPopulate() { void SQLiteHubDiscreteBuildTablesAndPopulate(D,M)( const D doc_abstraction, M doc_matters, ) { - auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); + auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.w_srv_data_root_url, doc_matters.src.language); auto pth_sqlite = spinePathsSQLiteDiscrete!()(doc_matters.output_path, doc_matters.src.language); pth_sqlite.base.mkdirRecurse; auto db = Database(pth_sqlite.sqlite_file(doc_matters.src.filename)); @@ -86,7 +129,8 @@ template SQLiteHubDiscreteBuildTablesAndPopulate() { *** db run -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_run +#+BEGIN_SRC d template SQLiteDbRun() { void SQLiteDbRun(Db,St,O)( Db db, @@ -127,7 +171,8 @@ template SQLiteDbRun() { *** munge -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_munge +#+BEGIN_SRC d template SQLinsertDelimiter() { string SQLinsertDelimiter(string _txt) { _txt = _txt @@ -155,7 +200,8 @@ template SQLiteFormatAndLoadObject() { *** sqlite instructions **** create -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_create +#+BEGIN_SRC d template SQLiteTablesReCreate() { string SQLiteTablesReCreate()() { string _sql_instruct; @@ -174,7 +220,8 @@ template SQLiteTablesReCreate() { **** delete -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_delete +#+BEGIN_SRC d template SQLiteDeleteDocument() { string SQLiteDeleteDocument(M)( M doc_matters, @@ -187,7 +234,8 @@ template SQLiteDeleteDocument() { **** insert -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_insert +#+BEGIN_SRC d template SQLiteInsertMetadata() { string SQLiteInsertMetadata(M)( M doc_matters, @@ -201,14 +249,15 @@ template SQLiteInsertMetadata() { **** insert doc objects loop -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_insert_doc_objects_loop +#+BEGIN_SRC d template SQLiteInsertDocObjectsLoop() { string SQLiteInsertDocObjectsLoop(D,M)( const D doc_abstraction, M doc_matters, ) { string _uid = SQLinsertDelimiter!()(doc_matters.src.doc_uid); - auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); + auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.w_srv_data_root_url, doc_matters.src.language); string insertDocObjectsRow(O)(O obj) { <> return _insert_doc_objects_row; @@ -220,7 +269,8 @@ template SQLiteInsertDocObjectsLoop() { **** tables create -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_tables_create +#+BEGIN_SRC d template SQLiteTablesCreate() { void SQLiteTablesCreate(E,O)(E env, O opt_action) { import d2sqlite3; @@ -254,7 +304,8 @@ template SQLiteTablesCreate() { **** tables drop -#+BEGIN_SRC d :tangle "../src/doc_reform/io_out/sqlite.d" +#+NAME: sqlite_tables_drop +#+BEGIN_SRC d template SQLiteDbDrop() { void SQLiteDbDrop(O)(O opt_action) { writeln("db drop"); @@ -321,7 +372,7 @@ template SQLiteDbDrop() { ** 2. imports -#+NAME: output_imports +#+NAME: sqlite_imports #+BEGIN_SRC d import doc_reform.io_out; import @@ -507,7 +558,7 @@ string inline_images(M,O)( M doc_matters, const O obj, string _txt, - string _suffix = ".html", + string _suffix = ".html", string _xml_type = "seg", ) { string _img_pth; @@ -560,7 +611,7 @@ string inline_links(M,O)( _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ doc_matters.conf_make_meta.conf.w_srv_data_root_url ~ "/" ~ pth_html.tail_fn_seg(doc_matters.src.filename, "$3.html") ~ "├" @@ -569,7 +620,7 @@ string inline_links(M,O)( _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ doc_matters.conf_make_meta.conf.w_srv_data_root_url ~ "/" ~ doc_matters.has.tag_associations[(m.captures[3])]["seg_lv4"] ~ ".html" @@ -594,7 +645,7 @@ string inline_links(M,O)( _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ doc_matters.conf_make_meta.conf.w_srv_data_root_url ~ "/" ~ pth_html.tail_fn_scroll(doc_matters.src.filename) ~ "#" ~ "$3" @@ -1451,8 +1502,8 @@ DROP INDEX IF EXISTS idx_digest_clean; DROP INDEX IF EXISTS idx_digest_all; DROP INDEX IF EXISTS idx_clean; DROP INDEX IF EXISTS idx_title; -DROP INDEX IF EXISTS idx_creator_author; -DROP INDEX IF EXISTS src_filename; +DROP INDEX IF EXISTS idx_author; +DROP INDEX IF EXISTS src_filename_base; DROP INDEX IF EXISTS idx_language_document_char; DROP INDEX IF EXISTS idx_classify_topic_register; #+END_SRC @@ -1484,6 +1535,7 @@ CREATE TABLE metadata_and_text ( title_language VARCHAR(100) NULL, title_language_char VARCHAR(6) NULL, creator_author VARCHAR(600) NOT NULL, + creator_author_last_first VARCHAR(600) NOT NULL, creator_author_email VARCHAR(100) NULL, creator_author_hon VARCHAR(100) NULL, creator_author_nationality VARCHAR(100) NULL, @@ -1546,7 +1598,8 @@ CREATE TABLE metadata_and_text ( notes_prefix_b TEXT NULL, notes_suffix TEXT NULL, publisher VARCHAR(600) NULL, - src_filename VARCHAR(256) NOT NULL, + src_filename_base VARCHAR(256) NOT NULL, + src_filename_suffix VARCHAR(6) NOT NULL, src_fingerprint VARCHAR(256) NULL, src_filesize VARCHAR(10) NULL, src_wordcount VARCHAR(10) NULL, @@ -1617,7 +1670,7 @@ CREATE TABLE doc_objects ( last_decendant VARCHAR(16) NULL, -- headings only digest_clean CHAR(256), digest_all CHAR(256), - html_seg_url CHAR(256), + seg_name CHAR(256), types CHAR(1) NULL ); #+END_SRC @@ -1631,9 +1684,9 @@ CREATE INDEX idx_digest_clean ON doc_objects(digest_clean); CREATE INDEX idx_digest_all ON doc_objects(digest_all); CREATE INDEX idx_clean ON doc_objects(clean); CREATE INDEX idx_title ON metadata_and_text(title); -CREATE INDEX idx_author ON metadata_and_text(creator_author); +CREATE INDEX idx_author ON metadata_and_text(creator_author_last_first); CREATE INDEX idx_uid ON metadata_and_text(uid); -CREATE INDEX idx_filename ON metadata_and_text(src_filename); +CREATE INDEX idx_filename ON metadata_and_text(src_filename_base); CREATE INDEX idx_language ON metadata_and_text(language_document_char); CREATE INDEX idx_topics ON metadata_and_text(classify_topic_register); #+END_SRC @@ -1686,7 +1739,8 @@ string _insert_metadata = format(q"┃ #+BEGIN_SRC sql INSERT INTO metadata_and_text ( uid, - src_filename, + src_filename_base, + src_filename_suffix, src_composite_id_per_txt, src_composite_id_per_pod, title, @@ -1696,6 +1750,7 @@ string _insert_metadata = format(q"┃ title_edition, title_language, creator_author, + creator_author_last_first, creator_author_email, creator_illustrator, creator_translator, @@ -1741,7 +1796,7 @@ string _insert_metadata = format(q"┃ #+NAME: sqlite_formatted_insertions_doc_matters_metadata #+BEGIN_SRC sql VALUES ( - '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' + '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ); #+END_SRC @@ -1751,7 +1806,8 @@ string _insert_metadata = format(q"┃ #+BEGIN_SRC d ┃", _uid, - SQLinsertDelimiter!()(doc_matters.src.filename), + SQLinsertDelimiter!()(doc_matters.src.filename_base), + SQLinsertDelimiter!()(doc_matters.src.filename_extension), SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_doc), SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_pod), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_full), @@ -1761,6 +1817,7 @@ string _insert_metadata = format(q"┃ SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_edition), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_language), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author_surname_fn), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author_email), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_illustrator), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_translator), @@ -1797,7 +1854,7 @@ string _insert_metadata = format(q"┃ SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_language_char), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_source), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.publisher), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root) + SQLinsertDelimiter!()(doc_matters.conf_make_meta.conf.w_srv_data_root_url) ); #+END_SRC @@ -1897,7 +1954,7 @@ string _insert_doc_objects_row = format(q"┃ lev, is_of_type, is_a, - html_seg_url + seg_name ) #+END_SRC @@ -1923,7 +1980,7 @@ string _insert_doc_objects_row = format(q"┃ obj.metainfo.heading_lev_markup, obj.metainfo.is_of_type, obj.metainfo.is_a, - url_html.fn_seg_obj_num(doc_matters.src.filename, obj.tags.html_segment_anchor_tag_is, obj.metainfo.identifier), + obj.tags.html_segment_anchor_tag_is ); #+END_SRC diff --git a/org/out_xmls.org b/org/out_xmls.org index c76d6ab..db3f0e5 100644 --- a/org/out_xmls.org +++ b/org/out_xmls.org @@ -185,7 +185,7 @@ import string _publisher="Publisher"; // TODO string o; o = format(q"┃ - + @@ -255,28 +255,28 @@ import @safe string inline_search_form(M)( M doc_matters, ) { - string _action="http://www.sisudoc.org/cgi-bin/search.cgi"; - string _db="spine.7a.manual"; string o; string _form; - if (doc_matters.opt.action.workon) { + if (doc_matters.opt.action.html_search_link) { o = format(q"┃

+ -
+ - + - - -
- - + + + + +
-
- ┃", - _action, - _db, + +┃", + doc_matters.conf_make_meta.conf.w_srv_cgi_action, + doc_matters.conf_make_meta.conf.w_srv_db_sqlite, + doc_matters.src.filename_base, ); } else { o = ""; @@ -294,10 +294,18 @@ import string type, ) { string o; + string metadata_links = ((doc_matters.opt.action.html_harvest_link) + ? format(q"┃

[ m | A | T ]

┃", + (type == "seg") ? "../" : "", + doc_matters.src.filename_base, + (type == "seg") ? "../" : "", + (type == "seg") ? "../" : "", + ) + : ""); o = format(q"┃ - + %s%s @@ -326,14 +334,7 @@ import : "../../css/html_scroll.css"), doc_matters.src.language, site_info_button(doc_matters), - ((doc_matters.opt.action.harvest_link) - ? format(q"┃

[ m | A | T ]

┃", - (type == "seg") ? "../" : "", - doc_matters.src.filename_base, - (type == "seg") ? "../" : "", - (type == "seg") ? "../" : "", - ) - : ""), + metadata_links, inline_search_form(doc_matters), (type == "seg") ? "" : "\n", ); diff --git a/org/output_hub.org b/org/output_hub.org index e6b429c..560cc2e 100644 --- a/org/output_hub.org +++ b/org/output_hub.org @@ -58,7 +58,7 @@ template outputHub() { } template outputHubOp() { <> - @system void outputHubOp(E,O)(E env, O opt_action) { + @system void outputHubOp(E,O,M)(E env, O opt_action, M make_and_meta_struct) { mixin spineRgxOut; static auto rgx = RgxO(); <> @@ -73,7 +73,6 @@ template outputHubOp() { import doc_reform.io_out, doc_reform.io_out.metadata, doc_reform.io_out.xmls, - doc_reform.io_out.odt, doc_reform.io_out.create_zip_file, doc_reform.io_out.paths_output; #+END_SRC @@ -240,6 +239,7 @@ if ((opt_action.sqlite_db_drop)) { #+BEGIN_SRC d if ((opt_action.sqlite_db_create)) { if ((opt_action.verbose)) { + auto pth_sqlite_db = spinePathsSQLite!()(opt_action.cgi_sqlite_search_filename, opt_action.output_dir_set); writeln("sqlite create table..."); } import doc_reform.io_out.sqlite; @@ -250,4 +250,31 @@ if ((opt_action.sqlite_db_create)) { } #+END_SRC +**** cgi sqlite search form + +#+NAME: output_options_op +#+BEGIN_SRC d +if ((opt_action.cgi_search_form_codegen)) { + if ((opt_action.verbose)) { + string _sqlite_db_fn = (opt_action.sqlite_filename.empty) + ? make_and_meta_struct.conf.w_srv_db_sqlite + : opt_action.sqlite_filename; + string _cgi_search_script = (opt_action.cgi_sqlite_search_filename.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script + : opt_action.cgi_sqlite_search_filename; + string _cgi_search_script_raw_fn_d = (opt_action.cgi_sqlite_search_filename_d.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script_raw_fn_d + : opt_action.cgi_sqlite_search_filename_d; + auto pth_sqlite_cgi = spinePathsSQLiteCGI!()(_cgi_search_script_raw_fn_d, _cgi_search_script, opt_action.output_dir_set); + writeln("sqlite cgi search form..."); + writeln(" ", pth_sqlite_cgi.search_form_path_out); + } + import doc_reform.io_out.cgi_sqlite_search_form; + CGIsearchSQLite!()(env, opt_action, make_and_meta_struct); + if ((opt_action.very_verbose)) { + writeln("sqlite cgi search form done"); + } +} +#+END_SRC + * __END__ diff --git a/org/output_show.org b/org/output_show.org index 4fd23de..3a1832b 100644 --- a/org/output_show.org +++ b/org/output_show.org @@ -160,32 +160,44 @@ template spineShowConfig() { #+NAME: meta_metadoc_show_config #+BEGIN_SRC d writefln( - "%s\n\"%s\", %s\n%s\n%s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n", + "%s\n\"%s\", %s\n%s\n%s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n", markup.repeat_character_by_number_provided("-", char_repeat_number), doc_matters.conf_make_meta.meta.title_full, doc_matters.conf_make_meta.meta.creator_author, doc_matters.src.filename, markup.repeat_character_by_number_provided("-", char_repeat_number), - "- webserv url domain:", - doc_matters.conf_make_meta.conf.webserv_url_domain, - "- webserv doc root:", - doc_matters.conf_make_meta.conf.webserv_url_doc_root, + "- webserv domain name:", + doc_matters.conf_make_meta.conf.w_srv_domain, + "- webserv doc root (part):", + doc_matters.conf_make_meta.conf.w_srv_data_root_part, "- webserv doc path:", - doc_matters.conf_make_meta.conf.webserv_url_doc_path, + doc_matters.conf_make_meta.conf.w_srv_data_root_path, "- webserv images (location):", - doc_matters.conf_make_meta.conf.webserv_images, - "- webserv cgi:", - doc_matters.conf_make_meta.conf.webserv_cgi, - "- webserv cgi host:", - doc_matters.conf_make_meta.conf.webserv_cgi_host, + doc_matters.conf_make_meta.conf.w_srv_images_root_part, + "- webserv doc root url:", + doc_matters.conf_make_meta.conf.w_srv_data_root_url, + "- webserv cgi domain (host):", + doc_matters.conf_make_meta.conf.w_srv_cgi_domain, "- webserv cgi host path:", - doc_matters.conf_make_meta.conf.webserv_cgi_host_path, + doc_matters.conf_make_meta.conf.w_srv_cgi_bin_path, + "- webserv cgi host (part):", + doc_matters.conf_make_meta.conf.w_srv_cgi_bin_part, + "- webserv cgi search script:", + doc_matters.conf_make_meta.conf.w_srv_cgi_search_script, + "- webserv cgi search script in d:", + doc_matters.conf_make_meta.conf.w_srv_cgi_search_script_raw_fn_d, "- webserv cgi port:", - doc_matters.conf_make_meta.conf.webserv_cgi_port, + doc_matters.conf_make_meta.conf.w_srv_cgi_port, "- webserv cgi user:", - doc_matters.conf_make_meta.conf.webserv_cgi_user, - "- webserv cgi file links:", - doc_matters.conf_make_meta.conf.webserv_cgi_file_links, + doc_matters.conf_make_meta.conf.w_srv_cgi_user, + "- webserv cgi url:", + doc_matters.conf_make_meta.conf.w_srv_cgi_bin_url, + "- webserv cgi action:", + doc_matters.conf_make_meta.conf.w_srv_cgi_action, + // "- webserv cgi file links:", + // doc_matters.conf_make_meta.conf.w_srv_cgi_file_links, + "- webserv sqlite db:", + doc_matters.conf_make_meta.conf.w_srv_db_sqlite, "- output path:", doc_matters.conf_make_meta.conf.output_path, "- processing concordance max:", diff --git a/org/spine.org b/org/spine.org index 79787c2..253720f 100644 --- a/org/spine.org +++ b/org/spine.org @@ -41,7 +41,7 @@ struct Version { #+NAME: spine_version_current_set #+BEGIN_SRC d -enum _ver = Version(0, 9, 2); +enum _ver = Version(0, 10, 0); #+END_SRC ** compilation restrictions (supported compilers) @@ -353,134 +353,140 @@ scope(failure) { #+NAME: spine_args #+BEGIN_SRC d bool[string] opts = [ - "abstraction" : false, - "assertions" : false, - "concordance" : false, - "dark" : false, - "debug" : false, - "digest" : false, - "epub" : false, - "harvest" : false, - "harvest-authors" : false, - "harvest-topics" : false, - "harvest-link" : false, - "html" : false, - "html-seg" : false, - "html-scroll" : false, - "latex" : false, - "latex-color-links" : false, - "light" : false, - "manifest" : false, - "hide-ocn" : false, - "ocn-off" : false, - "odf" : false, - "odt" : false, - "parallel" : false, - "parallel-subprocesses" : false, - "pdf" : false, - "pdf-color-links" : false, - "quiet" : false, - "pod" : false, - "serial" : false, - "show-summary" : false, - "show-metadata" : false, - "show-make" : false, - "show-config" : false, - "source" : false, - "sqlite-discrete" : false, - "sqlite-db-create" : false, - "sqlite-db-drop" : false, - "sqlite-db-recreate" : false, - "sqlite-delete" : false, - "sqlite-insert" : false, - "sqlite-update" : false, - "text" : false, - "verbose" : false, - "very-verbose" : false, - "xhtml" : false, - "section_toc" : true, - "section_body" : true, - "section_endnotes" : true, - "section_glossary" : true, - "section_biblio" : true, - "section_bookindex" : true, - "section_blurb" : true, - "backmatter" : true, - "skip-output" : false, - "theme-dark" : false, - "theme-light" : false, - "workon" : false, + "abstraction" : false, + "assertions" : false, + "cgi-search-form-codegen" : false, + "concordance" : false, + "dark" : false, + "debug" : false, + "digest" : false, + "epub" : false, + "harvest" : false, + "harvest-authors" : false, + "harvest-topics" : false, + "html" : false, + "html-link-harvest" : false, + "html-link-search" : false, + "html-seg" : false, + "html-scroll" : false, + "latex" : false, + "latex-color-links" : false, + "light" : false, + "manifest" : false, + "hide-ocn" : false, + "ocn-off" : false, + "odf" : false, + "odt" : false, + "parallel" : false, + "parallel-subprocesses" : false, + "pdf" : false, + "pdf-color-links" : false, + "quiet" : false, + "pod" : false, + "serial" : false, + "show-summary" : false, + "show-metadata" : false, + "show-make" : false, + "show-config" : false, + "source" : false, + "sqlite-discrete" : false, + "sqlite-db-create" : false, + "sqlite-db-drop" : false, + "sqlite-db-recreate" : false, + "sqlite-delete" : false, + "sqlite-insert" : false, + "sqlite-update" : false, + "text" : false, + "verbose" : false, + "very-verbose" : false, + "xhtml" : false, + "section_toc" : true, + "section_body" : true, + "section_endnotes" : true, + "section_glossary" : true, + "section_biblio" : true, + "section_bookindex" : true, + "section_blurb" : true, + "backmatter" : true, + "skip-output" : false, + "theme-dark" : false, + "theme-light" : false, + "workon" : false, ]; string[string] settings = [ + "cgi-sqlite-search-filename" : "", // "spine-search" "config" : "", "output" : "", "lang" : "all", - "sqlite-filename" : "documents", + "sqlite-db-filename" : "", // "spine-search.db" ]; auto helpInfo = getopt(args, std.getopt.config.passThrough, - "abstraction", "--abstraction document abstraction ", &opts["abstraction"], - "assert", "--assert set optional assertions on", &opts["assertions"], - "concordance", "--concordance file for document", &opts["concordance"], - "dark", "--dark alternative dark theme", &opts["dark"], - "debug", "--debug", &opts["debug"], - "digest", "--digest hash digest for each object", &opts["digest"], - "epub", "--epub process epub output", &opts["epub"], - "harvest", "--harvest extract info on authors & topics from document header metadata", &opts["harvest"], - "harvest-authors", "--harvest-authors extract info on authors from document header metadata", &opts["harvest-authors"], - "harvest-topics", "--harvest-topics extract info on topics from document header metadata", &opts["harvest-topics"], - "harvest-link", "--harvest-link place links back to harvest in segmented html", &opts["harvest-link"], - "html", "--html process html output", &opts["html"], - "html-seg", "--html-seg process html output", &opts["html-seg"], - "html-scroll", "--html-seg process html output", &opts["html-scroll"], - "latex", "--latex output for pdfs", &opts["latex"], - "latex-color-links", "--latex-color-links mono or color links for pdfs", &opts["latex-color-links"], - "light", "--light default light theme", &opts["light"], - "manifest", "--manifest process manifest output", &opts["manifest"], - "hide-ocn", "--hide-ocn object cite numbers", &opts["hide-ocn"], - "ocn-off", "--ocn-off object cite numbers", &opts["ocn-off"], - "odf", "--odf open document format text (--odt)", &opts["odf"], - "odt", "--odt open document format text", &opts["odt"], - "parallel", "--parallel parallelisation", &opts["parallel"], - "parallel-subprocesses", "--parallel-subprocesses nested parallelisation", &opts["parallel-subprocesses"], - "quiet|q", "--quiet output to terminal", &opts["quiet"], - "pdf", "--pdf latex output for pdfs", &opts["pdf"], - "pdf-color-links", "--pdf-color-links mono or color links for pdfs", &opts["pdf-color-links"], - "pod", "--pod spine (doc reform) pod source content bundled", &opts["pod"], - "serial", "--serial serial processing", &opts["serial"], - "show-summary", "--show-summary", &opts["show-summary"], - "show-make", "--show-make", &opts["show-make"], - "show-metadata", "--show-metadata", &opts["show-metadata"], - "show-config", "--show-config", &opts["show-config"], - "source", "--source markup source text content", &opts["source"], - "sqlite-discrete", "--sqlite process discrete sqlite output", &opts["sqlite-discrete"], - "sqlite-db-create", "--sqlite-db-create create db, create tables", &opts["sqlite-db-create"], - "sqlite-db-drop", "--sqlite-db-drop drop tables & db", &opts["sqlite-db-drop"], - "sqlite-db-recreate", "--sqlite-db-recreate create db, create tables", &opts["sqlite-db-recreate"], - "sqlite-delete", "--sqlite-delete process sqlite output", &opts["sqlite-delete"], - "sqlite-insert", "--sqlite-insert process sqlite output", &opts["sqlite-insert"], - "sqlite-update", "--sqlite-update process sqlite output", &opts["sqlite-update"], - "text", "--text process text output", &opts["text"], - "txt", "--txt process text output", &opts["text"], - "verbose|v", "--verbose output to terminal", &opts["verbose"], - "very-verbose", "--very-verbose output to terminal", &opts["very-verbose"], - "xhtml", "--xhtml process xhtml output", &opts["xhtml"], - "section-toc", "--section-toc process table of contents (default)", &opts["section_toc"], - "section-body", "--section-body process document body (default)", &opts["section_body"], - "section-endnotes", "--section-endnotes process document endnotes (default)", &opts["section_endnotes"], - "section-glossary", "--section-glossary process document glossary (default)", &opts["section_glossary"], - "section-biblio", "--section-biblio process document biblio (default)", &opts["section_biblio"], - "section-bookindex", "--section-bookindex process document bookindex (default)", &opts["section_bookindex"], - "section-blurb", "--section-blurb process document blurb (default)", &opts["section_blurb"], - "backmatter", "--section-backmatter process document backmatter (default)", &opts["backmatter"], - "skip-output", "--skip-output", &opts["skip-output"], - "theme-dark", "--theme-dark alternative dark theme", &opts["theme-dark"], - "theme-light", "--theme-light default light theme", &opts["theme-light"], - "workon", "--workon (reserved for some matters under development & testing)", &opts["workon"], - "config", "--config=/path/to/config/file/including/filename", &settings["config"], - "output", "--output=/path/to/output/dir specify where to place output", &settings["output"], - "sqlite-filename", "--sqlite-filename=[filename].sqlite", &settings["sqlite-filename"], - "lang", "--lang=[lang code e.g. =en or =en,es]", &settings["lang"], + "abstraction", "--abstraction document abstraction ", &opts["abstraction"], + "assert", "--assert set optional assertions on", &opts["assertions"], + "cgi-search-form-codegen", "--cgi-search-form-codegen pre-compiled d code search of specified db", &opts["cgi-search-form-codegen"], + "concordance", "--concordance file for document", &opts["concordance"], + "dark", "--dark alternative dark theme", &opts["dark"], + "debug", "--debug", &opts["debug"], + "digest", "--digest hash digest for each object", &opts["digest"], + "epub", "--epub process epub output", &opts["epub"], + "harvest", "--harvest extract info on authors & topics from document header metadata", &opts["harvest"], + "harvest-authors", "--harvest-authors extract info on authors from document header metadata", &opts["harvest-authors"], + "harvest-topics", "--harvest-topics extract info on topics from document header metadata", &opts["harvest-topics"], + "html", "--html process html output", &opts["html"], + "html-link-harvest", "--html-link-harvest place links back to harvest in segmented html", &opts["html-link-harvest"], + "html-link-search", "--html-link-search html embedded search submission", &opts["html-link-search"], + "html-seg", "--html-seg process html output", &opts["html-seg"], + "html-scroll", "--html-seg process html output", &opts["html-scroll"], + "latex", "--latex output for pdfs", &opts["latex"], + "latex-color-links", "--latex-color-links mono or color links for pdfs", &opts["latex-color-links"], + "light", "--light default light theme", &opts["light"], + "manifest", "--manifest process manifest output", &opts["manifest"], + "hide-ocn", "--hide-ocn object cite numbers", &opts["hide-ocn"], + "ocn-off", "--ocn-off object cite numbers", &opts["ocn-off"], + "odf", "--odf open document format text (--odt)", &opts["odf"], + "odt", "--odt open document format text", &opts["odt"], + "parallel", "--parallel parallelisation", &opts["parallel"], + "parallel-subprocesses", "--parallel-subprocesses nested parallelisation", &opts["parallel-subprocesses"], + "quiet|q", "--quiet output to terminal", &opts["quiet"], + "pdf", "--pdf latex output for pdfs", &opts["pdf"], + "pdf-color-links", "--pdf-color-links mono or color links for pdfs", &opts["pdf-color-links"], + "pod", "--pod spine (doc reform) pod source content bundled", &opts["pod"], + "serial", "--serial serial processing", &opts["serial"], + "show-summary", "--show-summary", &opts["show-summary"], + "show-make", "--show-make", &opts["show-make"], + "show-metadata", "--show-metadata", &opts["show-metadata"], + "show-config", "--show-config", &opts["show-config"], + "source", "--source markup source text content", &opts["source"], + "sqlite-discrete", "--sqlite process discrete sqlite output", &opts["sqlite-discrete"], + "sqlite-db-create", "--sqlite-db-create create db, create tables", &opts["sqlite-db-create"], + "sqlite-db-drop", "--sqlite-db-drop drop tables & db", &opts["sqlite-db-drop"], + "sqlite-db-recreate", "--sqlite-db-recreate create db, create tables", &opts["sqlite-db-recreate"], + "sqlite-delete", "--sqlite-delete process sqlite output", &opts["sqlite-delete"], + "sqlite-insert", "--sqlite-insert process sqlite output", &opts["sqlite-insert"], + "sqlite-update", "--sqlite-update process sqlite output", &opts["sqlite-update"], + "text", "--text process text output", &opts["text"], + "txt", "--txt process text output", &opts["text"], + "verbose|v", "--verbose output to terminal", &opts["verbose"], + "very-verbose", "--very-verbose output to terminal", &opts["very-verbose"], + "xhtml", "--xhtml process xhtml output", &opts["xhtml"], + "section-toc", "--section-toc process table of contents (default)", &opts["section_toc"], + "section-body", "--section-body process document body (default)", &opts["section_body"], + "section-endnotes", "--section-endnotes process document endnotes (default)", &opts["section_endnotes"], + "section-glossary", "--section-glossary process document glossary (default)", &opts["section_glossary"], + "section-biblio", "--section-biblio process document biblio (default)", &opts["section_biblio"], + "section-bookindex", "--section-bookindex process document bookindex (default)", &opts["section_bookindex"], + "section-blurb", "--section-blurb process document blurb (default)", &opts["section_blurb"], + "backmatter", "--section-backmatter process document backmatter (default)", &opts["backmatter"], + "skip-output", "--skip-output", &opts["skip-output"], + "theme-dark", "--theme-dark alternative dark theme", &opts["theme-dark"], + "theme-light", "--theme-light default light theme", &opts["theme-light"], + "workon", "--workon (reserved for some matters under development & testing)", &opts["workon"], + "cgi-sqlite-search-filename", "--cgi-sqlite-search-filename=[filename]", &settings["cgi-sqlite-search-filename"], + "config", "--config=/path/to/config/file/including/filename", &settings["config"], + "output", "--output=/path/to/output/dir specify where to place output", &settings["output"], + "sqlite-db-filename", "--sqlite-db-filename=[filename].sql.db", &settings["sqlite-db-filename"], + "lang", "--lang=[lang code e.g. =en or =en,es]", &settings["lang"], ); if (helpInfo.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInfo.options); @@ -497,6 +503,9 @@ struct OptActions { @trusted bool assertions() { return opts["assertions"]; } + @trusted bool cgi_search_form_codegen() { + return opts["cgi-search-form-codegen"]; + } @trusted bool concordance() { return opts["concordance"]; } @@ -523,8 +532,11 @@ struct OptActions { @trusted bool epub() { return opts["epub"]; } - @trusted bool harvest_link() { - return (opts["harvest-link"]) ? true : false; + @trusted bool html_harvest_link() { + return (opts["html-link-harvest"]) ? true : false; + } + @trusted bool html_search_link() { + return (opts["html-link-search"]) ? true : false; } @trusted bool harvest() { return (opts["harvest"] || opts["harvest-authors"] || opts["harvest-topics"]) ? true : false; @@ -662,7 +674,13 @@ struct OptActions { return settings["output"]; } auto sqlite_filename() { - return settings["sqlite-filename"]; + return settings["sqlite-db-filename"]; + } + auto cgi_sqlite_search_filename() { + return settings["cgi-sqlite-search-filename"]; + } + auto cgi_sqlite_search_filename_d() { + return (settings["cgi-sqlite-search-filename"].translate(['-' : "_"]) ~ ".d"); } @trusted bool parallelise() { bool _is; @@ -997,7 +1015,7 @@ if (!(_opt_action.skip_output)) { ) { writeln("step0 commence → (without processing files)"); } - outputHubOp!()(_env, _opt_action); + outputHubOp!()(_env, _opt_action, _make_and_meta_struct); if ((_opt_action.debug_do) || (_opt_action.very_verbose) ) { @@ -1488,6 +1506,12 @@ struct DocumentMatters { @safe string filename() { return _opt_action.sqlite_filename; } + @safe string cgi_filename() { + return _opt_action.cgi_sqlite_search_filename; + } + @safe string cgi_filename_d() { + return _opt_action.cgi_sqlite_search_filename_d; + } } return SQLite_(); } diff --git a/org/spine_build_scaffold.org b/org/spine_build_scaffold.org index 863dd25..ac1fc98 100644 --- a/org/spine_build_scaffold.org +++ b/org/spine_build_scaffold.org @@ -1029,6 +1029,7 @@ spine_sources = [ 'src/doc_reform/io_in/paths_source.d', 'src/doc_reform/io_in/read_config_files.d', 'src/doc_reform/io_in/read_source_files.d', + 'src/doc_reform/io_out/cgi_sqlite_search_form.d', 'src/doc_reform/io_out/create_zip_file.d', 'src/doc_reform/io_out/defaults.d', 'src/doc_reform/io_out/epub3.d', @@ -1133,12 +1134,11 @@ spine_exe = executable('spine', !conf.sdl !org !util +!util/** +!ext_lib +!ext_lib/** !src -!src/doc_reform -!src/doc_reform/* -!src_yaml -!src_yaml/doc_reform -!src_yaml/doc_reform/* +!src/** !data !data/* !data/src/** @@ -1162,6 +1162,8 @@ notes/** !notes/reminders !notes/reminders/** .dub/** +**/.dub/** +**/cgi-bin/** tmp/** *_.org *_.d diff --git a/org/util_cgi_d_sqlite_search.org b/org/util_cgi_d_sqlite_search.org new file mode 100644 index 0000000..43844a5 --- /dev/null +++ b/org/util_cgi_d_sqlite_search.org @@ -0,0 +1,1179 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) hub +#+DESCRIPTION: documents - structuring, various output representations & search +#+FILETAGS: :spine:hub: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2020 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: content hideblocks hidestars noindent entitiespretty +#+PROPERTY: header-args :exports code +#+PROPERTY: header-args+ :noweb yes +#+PROPERTY: header-args+ :eval no +#+PROPERTY: header-args+ :results no +#+PROPERTY: header-args+ :cache no +#+PROPERTY: header-args+ :padline no + +[[../maker.org][maker.org makefile]] [[./][org/]] + +* cgi search + +cd util/d/cgi/search +dub --force --compiler=ldc2 && sudo cp -v cgi-bin/spine-search /usr/lib/cgi-bin/. + +** 0. set program tangle + +#+BEGIN_SRC d :tangle "../util/d/cgi/search/src/spine_cgi_sqlite_search.d" +<> +<> +void cgi_function_intro(Cgi cgi) { + <> +<> +<> +<> + <> + <> +<> + <> +<> +} +mixin GenericMain!cgi_function_intro; +#+END_SRC + +** header + +#+NAME: cgi_sqlite_head +#+BEGIN_SRC d +/+ dub.sdl + name "spine search" + description "spine cgi search" ++/ +#+END_SRC + +** imports + +#+NAME: cgi_sqlite_imports +#+BEGIN_SRC d +import std.format; +import std.range; +import std.regex; +import arsd.cgi; +import d2sqlite3; +import std.process : environment; +#+END_SRC + +** void main +*** initialize + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +string header; +string table; +string form; +#+END_SRC + +**** config + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +struct Config { + string http_request_type; + string http_host; + // string server_name; + string doc_root; + string cgi_root; + string cgi_script; + string data_path_html; + string db_path; + string query_string; + string http_url; + string request_method; +} +auto conf = Config(); +conf.http_request_type = environment.get("REQUEST_SCHEME", "http"); +conf.http_host = environment.get("HTTP_HOST", "localhost"); +// conf.server_name = environment.get("SERVER_NAME", "localhost"); +conf.doc_root = environment.get("DOCUMENT_ROOT", "/var/www/html"); +conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", "/usr/lib/cgi-bin/"); +// conf.cgi_script = environment.get("SCRIPT_NAME", "/cgi-bin/spine-search"); +conf.query_string = environment.get("QUERY_STRING", ""); +conf.http_url = environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string); +conf.db_path = "/var/www/html/sqlite/"; // conf.http_host ~ "/sqlite/"; +conf.request_method = environment.get("REQUEST_METHOD", "POST"); +#+END_SRC + +# REQUEST_URI QUERY_STRING + +**** cgi val + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +struct CGI_val { + string db_selected = ""; + string sql_match_limit = ""; // radio: ( 1000 | 2500 ) + string sql_match_offset = ""; + string search_text = ""; + string results_type = ""; // index + bool checked_echo = false; + bool checked_stats = false; + bool checked_url = false; + bool checked_searched = false; + bool checked_tip = false; + bool checked_sql = false; +} +auto cv = CGI_val(); +cv.db_selected = "spine.search.db"; // config, set db name +#+END_SRC + +**** text fields +***** open + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +auto text_fields() { + string canned_query_str = environment.get("QUERY_STRING", ""); + if ("query_string" in cgi.post) { + canned_query_str = environment.get("QUERY_STRING", ""); + } + string[string] canned_query; + if (conf.request_method == "POST") { + } else if (conf.request_method == "GET") { + foreach (pair_str; canned_query_str.split("&")) { + // cgi.write(pair_str ~ "
"); + string[] pair = pair_str.split("="); + canned_query[pair[0]] = pair[1]; + } + // foreach (field, content; canned_query) { + // cgi.write(field ~ ": " ~ content ~ "
"); + // } + } +#+END_SRC + +***** rgx + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d + static struct Rgx { + // static canned_query = ctRegex!(`\A(?P.+)\Z`, "m"); + static search_text_area = ctRegex!(`\A(?P.+)\Z`, "m"); + // static fulltext = ctRegex!(`\A(?P.+)\Z`, "m"); + static line = ctRegex!(`^(?P.+?)(?: ~|$)`, "m"); + static text = ctRegex!(`(?:^|\s~\s*)text:\s+(?P.+?)(?: ~|$)`, "m"); + static author = ctRegex!(`(?:^|\s~\s*)author:\s+(?P.+)$`, "m"); + static title = ctRegex!(`(?:^|\s~\s*)title:\s+(?P.+)$`, "m"); + static uid = ctRegex!(`(?:^|\s~\s*)uid:\s+(?P.+)$`, "m"); + static fn = ctRegex!(`(?:^|\s~\s*)fn:\s+(?P.+)$`, "m"); + static keywords = ctRegex!(`(?:^|\s~\s*)keywords:\s+(?P.+)$`, "m"); + static topic_register = ctRegex!(`(?:^|\s~\s*)topic_register:\s+(?P.+)$`, "m"); + static subject = ctRegex!(`(?:^|\s~\s*)subject:\s+(?P.+)$`, "m"); + static description = ctRegex!(`(?:^|\s~\s*)description:\s+(?P.+)$`, "m"); + static publisher = ctRegex!(`(?:^|\s~\s*)publisher:\s+(?P.+)$`, "m"); + static editor = ctRegex!(`(?:^|\s~\s*)editor:\s+(?P.+)$`, "m"); + static contributor = ctRegex!(`(?:^|\s~\s*)contributor:\s+(?P.+)$`, "m"); + 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"); + static coverage = ctRegex!(`(?:^|\s~\s*)coverage:\s+(?P.+)$`, "m"); + static rights = ctRegex!(`(?:^|\s~\s*)rights:\s+(?P.+)$`, "m"); + static comment = ctRegex!(`(?:^|\s~\s*)comment:\s+(?P.+)$`, "m"); + // static abstract_ = ctRegex!(`(?:^|\s~\s*)abstract:\s+(?P.+)$`, "m"); + static src_filename_base = ctRegex!(`^src_filename_base:\s+(?P.+)$`, "m"); + } +#+END_SRC + +***** searchfields + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d + struct searchFields { + string canned_query = ""; // GET canned_query == cq + string search_text_area = ""; // POST search_text_area == tsa + string text = ""; // text == txt + string author = ""; // author == au + string title = ""; // title == ti + string uid = ""; // uid == uid + string fn = ""; // fn == fn + string keywords = ""; // keywords == kw + string topic_register = ""; // topic_register == tr + string subject = ""; // subject == su + string description = ""; // description == de + string publisher = ""; // publisher == pb + string editor = ""; // editor == ed + 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 + string coverage = ""; // coverage == cv + string rights = ""; // rights == rgt + string comment = ""; // comment == cmt + // string abstract = ""; + string src_filename_base = ""; // src_filename_base == bfn + string results_type = ""; // results_type == rt radio + string sql_match_limit = ""; // sql_match_limit == sml radio + string sql_match_offset = ""; // sql_match_offset == smo + string stats = ""; // stats == sts checked + string echo = ""; // echo == ec checked + string url = ""; // url == url checked + string searched = ""; // searched == se checked + string sql = ""; // sql == sql checked + } + auto rgx = Rgx(); + auto got = searchFields(); +#+END_SRC + +***** env +****** POST + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d + if (environment.get("REQUEST_METHOD", "POST") == "POST") { + if ("sf" in cgi.post) { + got.search_text_area = cgi.post["sf"]; + if (auto m = got.search_text_area.matchFirst(rgx.text)) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } else if (auto m = got.search_text_area.matchFirst(rgx.line)) { + if ( + !(m["matched"].matchFirst(rgx.author)) + && !(m["matched"].matchFirst(rgx.title)) + ) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } + } + if (auto m = got.search_text_area.matchFirst(rgx.author)) { + got.author = m["matched"]; + got.canned_query ~= "&au=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.title)) { + got.title = m["matched"]; + got.canned_query ~= "&ti=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.uid)) { + got.uid = m["matched"]; + got.canned_query ~= "&uid=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.fn)) { + got.fn = m["matched"]; + got.canned_query ~= "&fn=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.keywords)) { + got.keywords = m["matched"]; + got.canned_query ~= "&kw=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.topic_register)) { + got.topic_register = m["matched"]; + got.canned_query ~= "&tr=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.subject)) { + got.subject = m["matched"]; + got.canned_query ~= "&su=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.description)) { + got.description = m["matched"]; + got.canned_query ~= "&de=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.publisher)) { + got.publisher = m["matched"]; + got.canned_query ~= "&pb=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.editor)) { + got.editor = m["matched"]; + got.canned_query ~= "&ed=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.contributor)) { + got.contributor = m["matched"]; + got.canned_query ~= "&ct=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.date)) { + got.date = m["matched"]; + got.canned_query ~= "&dt=" ~ m["matched"]; + } + // if (auto m = got.search_text_area.matchFirst(rgx.results_type)) { + // got.results_type = m["matched"]; + // got.canned_query ~= "&rt=" ~ m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.format)) { + 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"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.language)) { + got.language = m["matched"]; + got.canned_query ~= "&lng=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.relation)) { + got.relation = m["matched"]; + got.canned_query ~= "&rl=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.coverage)) { + got.coverage = m["matched"]; + got.canned_query ~= "&cv=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.rights)) { + got.rights = m["matched"]; + got.canned_query ~= "&rgt=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.comment)) { + got.comment = m["matched"]; + got.canned_query ~= "&cmt=" ~ m["matched"]; + } + // if (auto m = search_text_area.matchFirst(rgx.abstract)) { + // got.abstract = m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.src_filename_base)) { + got.src_filename_base = m["matched"]; + got.canned_query ~= "&bfn=" ~ m["matched"]; + } + } + if ("fn" in cgi.post) { + got.fn = cgi.post["fn"]; + got.canned_query ~= "&fn=" ~ cgi.post["fn"]; + } + if ("rt" in cgi.post) { + got.results_type = cgi.post["rt"]; + got.canned_query ~= "&rt=" ~ cgi.post["rt"]; + } + if ("sts" in cgi.post) { + got.stats = cgi.post["sts"]; + got.canned_query ~= "&sts=" ~ cgi.post["sts"]; + } + if ("ec" in cgi.post) { + got.echo = cgi.post["ec"]; + got.canned_query ~= "&ec=" ~ cgi.post["ec"]; + } + if ("url" in cgi.post) { + got.url = cgi.post["url"]; + got.canned_query ~= "&url=" ~ cgi.post["url"]; + } + if ("se" in cgi.post) { + got.searched = cgi.post["se"]; + got.canned_query ~= "&se=" ~ cgi.post["se"]; + } + if ("sql" in cgi.post) { + got.sql = cgi.post["sql"]; + got.canned_query ~= "&sql=" ~ cgi.post["sql"]; + } + if ("sml" in cgi.post) { + got.sql_match_limit = cgi.post["sml"]; + got.canned_query ~= "&sml=" ~ cgi.post["sml"]; + } + if ("smo" in cgi.post) { + got.sql_match_offset = "0"; // cgi.post["smo"]; + got.canned_query ~= "&smo=0"; // ~ cgi.post["smo"]; + } + got.canned_query = got.canned_query.strip.split(" ").join("%20"); + conf.query_string = got.canned_query; + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); +#+END_SRC + +****** GET + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d + } else if (environment.get("REQUEST_METHOD", "POST") == "GET") { + got.canned_query = environment.get("QUERY_STRING", ""); + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); + got.search_text_area = ""; + if ("sf" in canned_query && !(canned_query["sf"]).empty) { + got.text = canned_query["sf"].split("%20").join(" "); + got.search_text_area ~= "text: " ~ got.text ~ "\n"; + } + if ("au" in canned_query && !(canned_query["au"]).empty) { + got.author = canned_query["au"].split("%20").join(" "); + got.search_text_area ~= "author: " ~ got.author ~ "\n"; + } + if ("ti" in canned_query && !(canned_query["ti"]).empty) { + got.title = canned_query["ti"].split("%20").join(" "); + got.search_text_area ~= "title: " ~ got.title ~ "\n"; + } + if ("uid" in canned_query && !(canned_query["uid"]).empty) { + got.uid = canned_query["uid"].split("%20").join(" "); + got.search_text_area ~= "uid: " ~ got.uid ~ "\n"; + } + if ("fn" in canned_query && !(canned_query["fn"]).empty) { + got.fn = canned_query["fn"].split("%20").join(" "); + got.search_text_area ~= "fn: " ~ got.fn ~ "\n"; + } + if ("kw" in canned_query && !(canned_query["kw"]).empty) { + got.keywords = canned_query["kw"].split("%20").join(" "); + got.search_text_area ~= "keywords: " ~ got.keywords ~ "\n"; + } + if ("tr" in canned_query && !(canned_query["tr"]).empty) { + got.topic_register = canned_query["tr"].split("%20").join(" "); + got.search_text_area ~= "topic_register: " ~ got.topic_register ~ "\n"; + } + if ("su" in canned_query && !(canned_query["su"]).empty) { + got.subject = canned_query["su"].split("%20").join(" "); + got.search_text_area ~= "subject: " ~ got.subject ~ "\n"; + } + if ("de" in canned_query && !(canned_query["de"]).empty) { + got.description = canned_query["de"].split("%20").join(" "); + got.search_text_area ~= "description: " ~ got.description ~ "\n"; + } + if ("pb" in canned_query && !(canned_query["pb"]).empty) { + got.publisher = canned_query["pb"].split("%20").join(" "); + got.search_text_area ~= "publisher: " ~ got.publisher ~ "\n"; + } + if ("ed" in canned_query && !(canned_query["ed"]).empty) { + got.editor = canned_query["ed"].split("%20").join(" "); + got.search_text_area ~= "editor: " ~ got.editor ~ "\n"; + } + if ("ct" in canned_query && !(canned_query["ct"]).empty) { + got.contributor = canned_query["ct"].split("%20").join(" "); + got.search_text_area ~= "contributor: " ~ got.contributor ~ "\n"; + } + if ("dt" in canned_query && !(canned_query["dt"]).empty) { + got.date = canned_query["dt"].split("%20").join(" "); + got.search_text_area ~= "date: " ~ got.date ~ "\n"; + } + if ("rt" in canned_query && !(canned_query["rt"]).empty) { + got.results_type = canned_query["rt"].split("%20").join(" "); + // got.search_text_area ~= "results_type: " ~ got.results_type ~ "\n"; + } + if ("fmt" in canned_query && !(canned_query["fmt"]).empty) { + 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"; + } + if ("lng" in canned_query && !(canned_query["lng"]).empty) { + got.language = canned_query["lng"].split("%20").join(" "); + got.search_text_area ~= "language: " ~ got.language ~ "\n"; + } + if ("rl" in canned_query && !(canned_query["rl"]).empty) { + got.relation = canned_query["rl"].split("%20").join(" "); + got.search_text_area ~= "relation: " ~ got.relation ~ "\n"; + } + if ("cv" in canned_query && !(canned_query["cv"]).empty) { + got.coverage = canned_query["cv"].split("%20").join(" "); + got.search_text_area ~= "coverage: " ~ got.coverage ~ "\n"; + } + if ("rgt" in canned_query && !(canned_query["rgt"]).empty) { + got.rights = canned_query["rgt"].split("%20").join(" "); + got.search_text_area ~= "rights: " ~ got.rights ~ "\n"; + } + if ("cmt" in canned_query && !(canned_query["cmt"]).empty) { + got.comment = canned_query["cmt"].split("%20").join(" "); + got.search_text_area ~= "comment: " ~ got.comment ~ "\n"; + } + // if ("abstract" in canned_query && !(canned_query["abstract"]).empty) { + // got.abstract = canned_query["abstract"]; + // } + if ("bfn" in canned_query && !(canned_query["bfn"]).empty) { // search_field + got.src_filename_base = canned_query["bfn"].split("%20").join(" "); + got.search_text_area ~= "src_filename_base: " ~ got.src_filename_base ~ "\n"; + } + if ("sml" in canned_query && !(canned_query["sml"]).empty) { + got.sql_match_limit = canned_query["sml"].split("%20").join(" "); + // got.search_text_area ~= "sql_match_limit: " ~ got.sql_match_limit ~ "\n"; + } + // cgi.write("f.search_text_area: " ~ got.search_text_area ~ "
"); + } + return got; +#+END_SRC + +***** tail + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +} +auto tf = text_fields; // +#+END_SRC + +**** SQL select + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +struct SQL_select { + string the_body = ""; + string the_range = ""; +} +auto sql_select = SQL_select(); +#+END_SRC + +**** misc + +#+NAME: cgi_sqlite_initialize +#+BEGIN_SRC d +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(); + string _previous_next = ""; + int _current_offset_value = 0; + string _set_offset_next = ""; + string _set_offset_previous = ""; + string _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; + _url_next = _url.replace(rgx.track_offset, _set_offset_next); + if (_current_offset_value < cv.sql_match_limit.to!int) { + _url_previous = ""; + } else { + _url_previous = ""; + _set_offset_previous = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int - cv.sql_match_limit.to!int).to!string; + _url_previous = _url.replace(rgx.track_offset, _set_offset_previous); + } + } else {// _current_offset_value = 0; + _url_next = _url ~= "&smo=" ~ cv.sql_match_limit.to!string; + } + if (_url_previous.empty) { + arrow_previous = ""; + } else { + arrow_previous = + "" + ~ "" + ~ "<< prev" + ~ " || "; + } + arrow_next = + "" + ~ "" + ~ "next >>" + ~ ""; + _previous_next = "
" ~ arrow_previous ~ arrow_next; + return _previous_next; +} +#+END_SRC + +** cgi +*** cgi html header + +#+NAME: cgi_sqlite_header +#+BEGIN_SRC d + { + header = format(q"┃ + + + + + + SiSU spine search form (sample) + + + + + + + +┃", + conf.http_host, + ); + } +#+END_SRC + +*** cgi html table + +#+NAME: cgi_sqlite_table +#+BEGIN_SRC d + { + table = format(q"┃ + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+ ┃"); + } +#+END_SRC + +*** cgi html form + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + { + string post_value(string field_name, string type="box", string set="on") { + string val = ""; + switch (type) { + case "field": + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? cgi.post[field_name] + : (field_name in cgi.get) + ? cgi.get[field_name] + : ""); + val = tf.search_text_area; + break; + case "box": // generic for checkbox or radio; checkbox set == "on" radio set == "name set" + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "off"); + break; + case "radio": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + case "checkbox": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + default: + } + return val; + } +#+END_SRC + +**** canned search + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + string the_can(string fv) { + string show_the_can = post_value("url"); + string _the_can = ""; + if (show_the_can == "checked") { + tf = text_fields; + string method_get_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", ""); + string method_post_url_construct = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query; + // assert(method_get_url == environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string)); + if (conf.request_method == "POST") { + _the_can = + "" + ~ "POST: " + ~ "" + ~ method_post_url_construct + ~ "" + ~ "
"; + } else if (conf.request_method == "GET") { + _the_can = + "" + ~ "GET:  " + ~ "" + ~ method_get_url + ~ ""; + } + conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ tf.canned_query; + } + return _the_can; + } +#+END_SRC + +**** provide tip + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + string provide_tip() { + string searched_tip = post_value("se"); + string tip = ""; + if (searched_tip == "checked") { + string search_field = post_value("sf", "field"); + tf = text_fields; + tip = format(q"┃ + +database: %s; selected view: index +search string: %s %s %s %s %s %s
+%s %s %s %s %s %s +
+┃", + cv.db_selected, + (tf.text.empty ? "" : "\"text: " ~ tf.text ~ "; "), + (tf.title.empty ? "" : "\"title: " ~ tf.title ~ "; "), + (tf.author.empty ? "" : "\"author: " ~ tf.author ~ "; "), + (tf.date.empty ? "" : "\"date " ~ tf.date ~ "; "), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + (tf.text.empty ? "" : "text: " ~ tf.text ~ "
"), + (tf.title.empty ? "" : "title: " ~ tf.title ~ "
"), + (tf.author.empty ? "" : "author: " ~ tf.author ~ "
"), + (tf.date.empty ? "" : "date: " ~ tf.date ~ "
"), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + ); + } + return tip; + } +#+END_SRC + +**** the form +***** form html + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + form = format(q"┃ +
+ + +
+ + + %s + %s + %s +
+ + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep; + match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement + +
+
+ + +
+┃", +#+END_SRC + +***** form values + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + "spine-search", + (post_value("ec") == "checked") ? post_value("sf", "field") : "", + provide_tip, + search_note, + the_can(post_value("sf", "field")), + cv.db_selected, + cv.db_selected, + post_value("rt", "box", "idx"), + post_value("rt", "box", "txt"), + post_value("sml", "box", "1000"), + post_value("sml", "box", "2500"), + post_value("ec"), + post_value("sts"), + post_value("url"), + post_value("se"), + post_value("tip"), + post_value("sql"), + ); +#+END_SRC + +**** set value (debug) + +#+NAME: cgi_sqlite_form +#+BEGIN_SRC d + { + string set_value(string field_name, string default_val) { + string val; + if (field_name in cgi.post) { + val = cgi.post[field_name]; + } else if (field_name in cgi.get) { + val = cgi.get[field_name]; + } else { val = default_val; } + return val; + } + bool set_bool(string field_name) { + bool val; + if (field_name in cgi.post + && cgi.post[field_name] == "on") { + val = true; + } else if (field_name in cgi.get + && cgi.get[field_name] == "on") { + val = true; + } else { val = false; } + return val; + } + cv.db_selected = set_value("selected_db", "spine.search.db"); // selected_db == db + cv.sql_match_limit = set_value("sml", "1000"); + cv.sql_match_offset = set_value("smo", "0"); + cv.search_text = set_value("sf", "test"); // remove test + cv.results_type = set_value("rt", "idx"); + cv.checked_echo = set_bool("ec"); + cv.checked_stats = set_bool("sts"); + cv.checked_url = set_bool("url"); + cv.checked_searched = set_bool("se"); + cv.checked_tip = set_bool("tip"); + cv.checked_sql = set_bool("sql"); + tf = text_fields; + } + } +#+END_SRC + +*** cgi write + +#+NAME: cgi_sqlite_write +#+BEGIN_SRC d +{ + cgi.write(header); + cgi.write(table); + cgi.write(form); + // cgi.write(previous_next); + { // debug environment + // foreach (k, d; environment.toAA) { + // cgi.write(k ~ ": " ~ d ~ "
"); + // } + } + { // debug cgi info + // cgi.write("db_selected: " ~ cv.db_selected ~ "
\n"); + // cgi.write("search_text: " ~ cv.search_text ~ "
\n"); + // cgi.write("sql_match_limit: " ~ cv.sql_match_limit ~ ";\n"); + // cgi.write("sql_match_offset: " ~ cv.sql_match_offset ~ ";\n"); + // cgi.write("results_type: " ~ cv.results_type ~ "
\n"); + // cgi.write("cv.checked_echo: " ~ (cv.checked_echo ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_stats: " ~ (cv.checked_stats ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_url: " ~ (cv.checked_url ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_searched: " ~ (cv.checked_searched ? "checked" : "off") ~ ";
\n"); + // cgi.write("cv.checked_tip: " ~ (cv.checked_tip ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_sql: " ~ (cv.checked_sql ? "checked" : "off") ~ "
\n"); + } +} +#+END_SRC + +** db +*** db set + +#+NAME: cgi_sqlite_set_db +#+BEGIN_SRC d +auto db = Database(conf.db_path ~ cv.db_selected); +#+END_SRC + +*** db select statement +**** select where + +#+NAME: cgi_sqlite_select_statement_0 +#+BEGIN_SRC d + { + uint sql_match_offset_counter(T)(T cv) { + sql_match_offset_count += cv.sql_match_limit.to!uint; + return sql_match_offset_count; + } + void sql_search_query() { + string select_field_like(string db_field, string search_field) { + string where_ = ""; + if (!(search_field.empty)) { + string _sf = search_field.strip.split("%20").join(" "); + if (_sf.match(r" OR ")) { + _sf = _sf.split(" OR ").join("%' OR " ~ db_field ~ " LIKE '%"); + } + if (_sf.match(r" AND ")) { + _sf = _sf.split(" AND ").join("%' AND " ~ db_field ~ " LIKE '%"); + } + _sf = "( " ~ db_field ~ " LIKE\n '%" ~ _sf ~ "%' )"; + where_ ~= format(q"┃ + %s +┃", + _sf + ); + } + return where_; + } + string[] _fields; + _fields ~= select_field_like("doc_objects.clean", tf.text); + _fields ~= select_field_like("metadata_and_text.title", tf.title); + _fields ~= select_field_like("metadata_and_text.creator_author", tf.author); + _fields ~= select_field_like("metadata_and_text.uid", tf.uid); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.fn); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.src_filename_base); + _fields ~= select_field_like("metadata_and_text.language_document_char", tf.language); + _fields ~= select_field_like("metadata_and_text.date_published", tf.date); + _fields ~= select_field_like("metadata_and_text.classify_keywords", tf.keywords); + _fields ~= select_field_like("metadata_and_text.classify_topic_register", tf.topic_register); + string[] fields; + foreach (f; _fields) { + if (!(f.empty)) { fields ~= f; } + } + string fields_str = ""; + fields_str ~= fields.join(" AND "); +#+END_SRC + +**** db select statement +***** the body + +#+NAME: cgi_sqlite_select_statement_0 +#+BEGIN_SRC d + sql_select.the_body ~= format(q"┃ +SELECT + metadata_and_text.uid, + metadata_and_text.title, + metadata_and_text.creator_author_last_first, + metadata_and_text.creator_author, + metadata_and_text.src_filename_base, + metadata_and_text.language_document_char, + metadata_and_text.date_published, + metadata_and_text.classify_keywords, + metadata_and_text.classify_topic_register, + doc_objects.body, + doc_objects.seg_name, + doc_objects.ocn, + metadata_and_text.uid +FROM + doc_objects, + metadata_and_text +WHERE ( + %s + ) +AND + doc_objects.uid_metadata_and_text = metadata_and_text.uid +ORDER BY + metadata_and_text.creator_author_last_first, + metadata_and_text.date_published DESC, + metadata_and_text.title, + metadata_and_text.language_document_char, + metadata_and_text.src_filename_base, + doc_objects.ocn +LIMIT %s OFFSET %s +;┃", + fields_str, + cv.sql_match_limit, + cv.sql_match_offset, + ); +#+END_SRC + +***** html write selected +****** ocn index + +#+NAME: cgi_sqlite_select_statement_0 +#+BEGIN_SRC d + (cv.checked_sql) + ? cgi.write(previous_next ~ "
" ~ sql_select.the_body.split("\n ").join(" ").split("\n").join("
") ~ "
\n") + : ""; + cgi.write(previous_next); + auto select_query_results = db.execute(sql_select.the_body).cached; + string _old_uid = ""; + if (!select_query_results.empty) { + foreach (row; select_query_results) { + if (row["uid"].as!string != _old_uid) { + _old_uid = row["uid"].as!string; + auto m = (row["date_published"].as!string).match(regex(r"^([0-9]{4})")); // breaks if row missing or no match? + cgi.write( + "
\"" + ~ row["title"].as!string ~ "\"" + ~ " (" + ~ m.hit + ~ ") " + ~ "[" + ~ row["language_document_char"].as!string + ~ "] " + ~ row["creator_author_last_first"].as!string + ~ ":
\n" + ); + } + if (cv.results_type == "txt") { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } else { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } + } + cgi.write( previous_next); + } else { // offset_not_beyond_limit = false; + cgi.write("select_query_results empty

\n"); + } + } + sql_search_query; + } +#+END_SRC + +****** text found + +*** db close + +#+NAME: cgi_sqlite_db_close +#+BEGIN_SRC d +{ + db.close; +} +#+END_SRC + +** tail +*** cgi tail + +#+NAME: cgi_sqlite_db_tail +#+BEGIN_SRC d + { + string tail = format(q"┃ + +┃"); + cgi.write(tail); + } +#+END_SRC + +* cgi-search dub.sdl + +#+BEGIN_SRC d :tangle "../util/d/cgi/search/dub.sdl" +name "spine-search" +description "A minimal D application." +authors "ralph" +copyright "Copyright © 2020, ralph" +license "GPL-3.0+" +dependency "d2sqlite3" version="~>0.18.3" +targetType "executable" +targetPath "./cgi-bin" +mainSourceFile "src/spine_cgi_sqlite_search.d" +configuration "default" { + targetType "executable" + targetName "spine-search" + postGenerateCommands "/usr/bin/notify-send -t 0 'D executable ready' 'spine cgi sqlite search d'" +} +#+END_SRC + +* cgi.d arsd Adam Ruppe + + used for cgi + + https://dlang.org/phobos/std_net_curl.html + https://dlang.org/library/std/net/curl.html + + curl https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d -o cgi.d + wget https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d + aria2c https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d + +* cgi-search README + +#+BEGIN_SRC text :tangle "../util/d/cgi/search/README" +change db name to match name of db you create +cv.db_selected = "spine.search.sql.db"; + +~dr/bin/spine-ldc -v --sqlite-db-create --sqlite-db-filename="spine.search.db" --cgi-sqlite-search-filename="spine-search" --output=/var/www ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +~dr/bin/spine-ldc -v --sqlite-update --sqlite-db-filename="spine.search.db" --output=/var/www ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +cd util/d/cgi/search/src +dub --force --compiler=ldc2 && sudo cp -v cgi-bin/spine-search /usr/lib/cgi-bin/. + +http://localhost/cgi-bin/spine-search? +#+END_SRC diff --git a/org/util_cgi_rb_fcgi_sqlite_search.org b/org/util_cgi_rb_fcgi_sqlite_search.org new file mode 100644 index 0000000..3460b32 --- /dev/null +++ b/org/util_cgi_rb_fcgi_sqlite_search.org @@ -0,0 +1,1071 @@ +-*- mode: org -*- +#+TITLE: spine (doc_reform) rb cgi (fcgi) +#+DESCRIPTION: documents - structuring, various output representations & search +#+FILETAGS: :spine:hub: +#+AUTHOR: Ralph Amissah +#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] +#+COPYRIGHT: Copyright (C) 2015 - 2020 Ralph Amissah +#+LANGUAGE: en +#+STARTUP: content hideblocks hidestars noindent entitiespretty +#+PROPERTY: header-args :exports code +#+PROPERTY: header-args+ :noweb yes +#+PROPERTY: header-args+ :eval no +#+PROPERTY: header-args+ :results no +#+PROPERTY: header-args+ :cache no +#+PROPERTY: header-args+ :padline no +- [[./spine.org][spine]] [[./][org/]] +- [[./output_hub.org][output_hub]] + +* cgi +** search ruby scripts + +#+BEGIN_SRC sh +cd /etc/apache2/conf-enabled && sudo ln -s ../conf-available/serve-cgi-bin.conf +cd /etc/apache2/mods-enabled && sudo ln -s ../mods-available/cgi.load +sudo cp -vi ../utils/cgi/spine.search.cgi /usr/lib/cgi-bin/. +document home currently at /var/www/html (better placed at /var/www or srv/project_name/www) +~dr/bin/spine-ldc -v --sqlite-db-create --sqlite-db-filename=spine.sqlite.db --output=/tmp/dr ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* +~dr/bin/spine-ldc -v --sqlite-update --sqlite-db-filename=spine.sqlite.db --output=/tmp/dr ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* +#+END_SRC + +*** sqlite cgi search TODO +**** head + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" :tangle-mode (identity #o755) :shebang #!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (sqlite) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2014, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end +#+END_SRC + +**** initialize + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +begin + require 'cgi' + require 'fcgi' + require 'sqlite3' +rescue LoadError + puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)' +end +@stub_default = 'search' +@image_src = "http://#{ENV['HTTP_HOST']}/image_sys" +@hosturl_cgi = "http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" +@hosturl_files = "http://#{ENV['HTTP_HOST']}" +@output_dir_structure_by = 'language' +@lingual = 'multi' +@db_name_prefix = 'spine.' +@base = "http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP +@@offset = 0 +@@canned_search_url = @base +@color_heading = '#DDFFAA' +@color_match = '#ffff48' +#+END_SRC + +**** form +***** initialize form + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note = '' if checked_searched !~ /\S/ + the_can = '' if checked_url !~ /\S/ + search_field = '' if checked_echo !~ /\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip = if checked_tip =~ /\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; src_filename_base:__;
' + else '' + end + end +#+END_SRC + +***** submission form + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + def submission_form + search_form =<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+

+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end +end +#+END_SRC + +**** search request +***** initialize request + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:src_filename_base + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1 = text_to_match('text:') + @fulltext = text_to_match('fulltxt:') + @topic_register = text_to_match('topic_register:') + @title = text_to_match('title:') # DublinCore 1 - title + @author = text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject = text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description = text_to_match('description:') # DublinCore 4 - description + @publisher = text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor = text_to_match('editor:') + @contributor = text_to_match('contributor:') # DublinCore 6 - contributor + @date = text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type = text_to_match('type:') # DublinCore 8 - type + @format = text_to_match('format:') # DublinCore 9 - format + @identifier = text_to_match('identifier:') # DublinCore 10 - identifier + @source = text_to_match('source:') # DublinCore 11 - source + @language = text_to_match('language:') # DublinCore 12 - language + @relation = text_to_match('relation:') # DublinCore 13 - relation + @coverage = text_to_match('coverage:') # DublinCore 14 - coverage + @rights = text_to_match('rights:') # DublinCore 15 - rights + @keywords = text_to_match('key(?:words?)?:') + @comment = text_to_match('comment:') + @abstract = text_to_match('abs(?:tract)?:') + @owner = text_to_match('owner:') + @date_created = text_to_match('date_created:') + @date_issued = text_to_match('date_issued:') + @date_modified = text_to_match('date_modified:') + @date_available = text_to_match('date_available:') + @date_valid = text_to_match('date_valid:') + @filename = text_to_match('src_filename_base:') + @text1 = text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1 = q['s1'] if q['s1'] =~ /\S/ + @fulltext = q['ft'] if q['ft'] =~ /\S/ + @keywords = q['key'] if q['key'] =~ /\S/ + @title = q['ti'] if q['ti'] =~ /\S/ + @author = q['au'] if q['au'] =~ /\S/ + @topic_register = q['tr'] if q['tr'] =~ /\S/ + @subject = q['sj'] if q['sj'] =~ /\S/ + @description = q['dsc'] if q['dsc'] =~ /\S/ + @publisher = q['pb'] if q['pb'] =~ /\S/ + @editor = q['cntr'] if q['cntr'] =~ /\S/ + @contributor = q['cntr'] if q['cntr'] =~ /\S/ + @date = q['dt'] if q['dt'] =~ /\S/ + @type = q['ty'] if q['ty'] =~ /\S/ + @identifier = q['id'] if q['id'] =~ /\S/ + @source = q['src'] if q['src'] =~ /\S/ + @language = q['lang'] if q['lang'] =~ /\S/ + @relation = q['rel'] if q['rel'] =~ /\S/ + @coverage = q['cov'] if q['cov'] =~ /\S/ + @rights = q['cr'] if q['cr'] =~ /\S/ + @comment = q['co'] if q['co'] =~ /\S/ + @abstract = q['ab'] if q['ab'] =~ /\S/ + @date_created = q['dtc'] if q['dtc'] =~ /\S/ + @date_issued = q['dti'] if q['dti'] =~ /\S/ + @date_modified = q['dtm'] if q['dtm'] =~ /\S/ + @date_available = q['dta'] if q['dta'] =~ /\S/ + @date_valid = q['dtv'] if q['dtv'] =~ /\S/ + @filename = if q['doc'] and q['search'] !~ /search db/ then q['doc'] + elsif q['fns'] =~ /\S/ then q['fns'] + end + @@limit = q['ltd'] if q['ltd'] =~ /\d+/ # 1000 + @@offset = q['off'] if q['off'] =~ /\d+/ # 0 + end + end +#+END_SRC + +***** text to match + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end +end +#+END_SRC + +**** search string + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q=l,t,q + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=unescaped_search.gsub(/\s*(AND|OR)\s*/,"%' \) \\1 #{@l} LIKE \( '%"). + gsub(/(.+)/,"#{@l} LIKE \( '%\\1%' \)") + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end +end +#+END_SRC + +**** search statement +***** init + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.src_filename_base',search_for.src_filename_base,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\))+)/,'(\1)') + end +#+END_SRC + +***** misc + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end +#+END_SRC + +***** select statement + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + def sql_select_body + limit ||= @@limit + offset ||= @@offset + @sql_statement[:body] = %{ + SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename_base, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg_name, doc_objects.ocn, metadata_and_text.uid + FROM doc_objects, metadata_and_text + WHERE #{@search_text} AND doc_objects.uid_metadata_and_text = metadata_and_text.uid + ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename_base, doc_objects.ocn + } + @sql_statement[:range] = %{LIMIT #{limit} OFFSET #{offset} ;} + select = @sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.execute(sql_select_body) + end +end +#+END_SRC + +**** tail + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 6.3.1 2014-10-19 (2014w41/7) +
+ + SiSU © Ralph Amissah + 1993, current 2014. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2014. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK +end +#+END_SRC + +**** fcgi each +***** init & start loop + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" +@tail=tail +@counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 +@counters_txt,@counters_endn,@sql_select_body='','','' +FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo = 'checked' if cgi['echo'] =~/\S/ + checked_stats = 'checked' if cgi['stats'] =~/\S/ + checked_url = 'checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched = 'checked' if cgi['searched'] =~/\S/ + checked_tip = 'checked' if cgi['tip'] =~/\S/ + checked_case = 'checked' if cgi['casesense'] =~/\S/ + checked_sql = 'checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~ /check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all = 'checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none ='' + elsif cgi['checks'] =~ /check_none/ + checked_none = 'checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~ /check_selected/ + checked_selected = 'checked' + elsif cgi['checks'] =~ /check_default/ + checked_default = 'checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=case cgi['db'] + when /spine.sqlite/ then '' + end + db_name='spine.search.sql.db' + #db_name='spine.sqlite.db' + #db_name='sisu_sqlite.db' + db_sqlite=case cgi['db'] + when /spine.sqlite/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + else "/var/www/sqlite/#{db_name}" + end + #when /spine.sqlite/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + #else "/srv/complete.sisudoc.org/web/manual/#{db_name}" + #end + #@conn=SQLite3::Database.new(db_sqlite) + @conn=SQLite3::Database.new("/var/www/sqlite/spine.search.sql.db") + #@conn=SQLite3::Database.new("/var/www/spine.sqlite.db") + @conn.results_as_hash=true + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches +#+END_SRC + +***** canned search + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1 = 's1=' + CGI.escape(@search_for.text1) if @search_for.text1 =~ /\S/ + ft = '&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext =~ /\S/ + key = 'key=' + CGI.escape(@search_for.keywords) if @search_for.keywords =~ /\S/ + ti = '&ti=' + CGI.escape(@search_for.title) if @search_for.title =~ /\S/ + au = '&au=' + CGI.escape(@search_for.author) if @search_for.author =~ /\S/ + tr = '&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register =~ /\S/ + sj = '&sj=' + CGI.escape(@search_for.subject) if @search_for.subject =~ /\S/ + dsc = '&dsc=' + CGI.escape(@search_for.description) if @search_for.description =~ /\S/ + pb = '&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher =~ /\S/ + edt = '&edt=' + CGI.escape(@search_for.editor) if @search_for.editor =~ /\S/ + cntr = '&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor =~ /\S/ + dt = '&dt=' + CGI.escape(@search_for.date) if @search_for.date =~ /\S/ + ty = '&ty=' + CGI.escape(@search_for.type) if @search_for.type =~ /\S/ + id = '&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier =~ /\S/ + src = '&src=' + CGI.escape(@search_for.source) if @search_for.source =~ /\S/ + lang = '&lang=' + CGI.escape(@search_for.language) if @search_for.language =~ /\S/ + rel = '&rel=' + CGI.escape(@search_for.relation) if @search_for.relation =~ /\S/ + cov = '&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage =~ /\S/ + cr = '&cr=' + CGI.escape(@search_for.rights) if @search_for.rights =~ /\S/ + co = '&co=' + CGI.escape(@search_for.comment) if @search_for.comment =~ /\S/ + ab = '&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract =~ /\S/ + dtc = '&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created =~ /\S/ + dti = '&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued =~ /\S/ + dtm = '&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified =~ /\S/ + dta = '&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available =~ /\S/ + dtv = '&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid =~ /\S/ + fns = '&fns=' + CGI.escape(@search_for.src_filename_base) if @search_for.src_filename_base =~ /\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'src_filename_base: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename = %{src_filename_base: #{green}#{@search_for.src_filename_base}

} if @search_for.src_filename_base =~ /\S+/ + p_text = %{text: #{green}#{@search_for.text1}
} if @search_for.text1 =~ /\S+/ + p_fulltext = %{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~ /\S+/ + p_title = %{title: #{green}#{@search_for.title}
} if @search_for.title =~ /\S+/ + p_author = %{author: #{green}#{@search_for.author}
} if @search_for.author =~ /\S+/ + p_editor = %{editor: #{green}#{@search_for.editor}
} if @search_for.editor =~ /\S+/ + p_contributor = %{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~ /\S+/ + p_date = %{date: #{green}#{@search_for.date}
} if @search_for.date =~ /\S+/ + p_rights = %{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~ /\S+/ + p_topic_register = %{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~ /\S+/ + p_subject = %{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~ /\S+/ + p_keywords = %{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~ /\S+/ + p_identifier = %{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~ /\S+/ + p_type = %{type: #{green}#{@search_for.type}
} if @search_for.type =~ /\S+/ + p_format = %{format: #{green}#{@search_for.format}
} if @search_for.format =~ /\S+/ + p_relation = %{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~ /\S+/ + p_coverage = %{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~ /\S+/ + p_description = %{description: #{green}#{@search_for.description}
} if @search_for.description =~ /\S+/ + p_abstract = %{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~ /\S+/ + p_comment = %{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~ /\S+/ + p_publisher = %{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~ /\S+/ + p_source = %{source: #{green}#{@search_for.source}
} if @search_for.source =~ /\S+/ + p_language = %{language: #{green}#{@search_for.language}
} if @search_for.language =~ /\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning +#+END_SRC + +***** submission form + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + @header = Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + olduid="" + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + #@body_main << '



Main Text:
' << sql_select_body + else + end + @hostpath = "#{@hosturl_files}" + #@hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg_name,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg_name}.html" + : "#{path_html_seg(fn,ln)}/#{seg_name}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg_name}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end +#+END_SRC + +***** contents each, text body + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename_base'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename_base'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['uid'] != olduid + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title = %{ #{ti} [#{c['language_document_char']}] by #{c['creator_author']} #{can_txt_srch}
} + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + olduid=c['uid'] + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=[] + build=unescaped_search.scan(/\S+/).each do |g| + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') + : (search_regex << %{#{g.to_s}}) + end + search_regex=search_regex.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg_name'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end +#+END_SRC + +***** after + +#+BEGIN_SRC ruby :tangle "../util/rb/cgi/spine.search.cgi" + olduid = "" + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{ + @header.force_encoding("UTF-8") \ + + @counters_txt.force_encoding("UTF-8") \ + + @counters_endn.force_encoding("UTF-8") \ + + canned.force_encoding("UTF-8") \ + + @body_main.force_encoding("UTF-8") \ + + canned.force_encoding("UTF-8") \ + + @tail.force_encoding("UTF-8") + } #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+    s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end +end +#+END_SRC diff --git a/src/doc_reform/io_in/read_config_files.d b/src/doc_reform/io_in/read_config_files.d index 9daf362..69c2f55 100644 --- a/src/doc_reform/io_in/read_config_files.d +++ b/src/doc_reform/io_in/read_config_files.d @@ -19,30 +19,37 @@ template readConfigSite() { string config_file_str; string default_config_file_str = format(q"┃ flag: - act0: --html - act1: --html --epub -#output: -# path: "" + act0: "--html" + act1: "--html --epub" +output: + path: "/var/www/html" default: - language: "en" - papersize: "a4" - text_wrap: "80" - digest: "sha256" -search: - title: "" - flag: "" - action: "" - db: "" + language: "en" + papersize: "a4" + text_wrap: "80" + digest: "sha256" webserv: - url_domain: "not-configured" - url_root: "doc" - doc_path: "doc" - images: "" - cgi: "" - cgi_host: "" - cgi_host_path: "" - cgi_port: "" - cgi_user: "" + http: "http" + domain: "localhost" + data_http: "http" + data_domain: "localhost" + data_root_url: "http://localhost" + data_root_path: "/var/www/html" + data_root_part: "" + images_root_part: "image" + cgi_title: "≅ SiSU Spine search" + cgi_http: "http" + cgi_domain: "localhost" + cgi_bin_url: "http://localhost/cgi-bin" + cgi_bin_part: "cgi-bin" + cgi_bin_path: "/usr/lib/cgi-bin" + cgi_search_script: "spine-search" + cgi_port: "" + cgi_user: "" + cgi_action: "http://localhost/cgi-bin/spine-search" + db_sqlite: "spine.search.db" + db_pg_table: "" + db_pg_user: "" ┃"); foreach(conf_fn; [_conf_file_details.config_filename_site]) { foreach(pth; _conf_file_details.possible_config_path_locations.config_local_site) { diff --git a/src/doc_reform/io_in/read_source_files.d b/src/doc_reform/io_in/read_source_files.d index 7d826a9..2959cc6 100644 --- a/src/doc_reform/io_in/read_source_files.d +++ b/src/doc_reform/io_in/read_source_files.d @@ -187,7 +187,7 @@ template spineRawMarkupContent() { } contents_insert ~= line; } else if (line.matchFirst(rgx.block_curly_code_open)) { - type1["curly_code"] = 1; + type1["curly_code"] = 1; type1["header_make"] = 0; type1["header_meta"] = 0; contents_insert ~= line; @@ -199,7 +199,7 @@ template spineRawMarkupContent() { } contents_insert ~= line; } else if (line.matchFirst(rgx.block_tic_code_open)) { - type1["tic_code"] = 1; + type1["tic_code"] = 1; type1["header_make"] = 0; type1["header_meta"] = 0; contents_insert ~= line; @@ -265,7 +265,7 @@ template spineRawMarkupContent() { auto fn_pth_full = fn_src.match(rgx.src_pth_sst_or_ssm); auto markup_src_file_path = fn_pth_full.captures[1]; char[][] contents_insert; - string[] _images =[]; + string[] _images =[]; string[] insert_file_list =[]; foreach (line; sourcefile_body_content) { if (type["curly_code"] == 1) { @@ -285,7 +285,7 @@ template spineRawMarkupContent() { type["tic_code"] = 1; contents ~= line; } else if (auto m = line.match(rgx.insert_src_fn_ssi_or_sst)) { - auto insert_fn = m.captures[2]; + auto insert_fn = m.captures[2]; auto insert_sub_pth = m.captures[1]; auto fn_src_insert = chainPath(markup_src_file_path, insert_sub_pth ~ insert_fn).array; diff --git a/src/doc_reform/io_out/cgi_sqlite_search_form.d b/src/doc_reform/io_out/cgi_sqlite_search_form.d new file mode 100644 index 0000000..b1c64eb --- /dev/null +++ b/src/doc_reform/io_out/cgi_sqlite_search_form.d @@ -0,0 +1,988 @@ +module doc_reform.io_out.cgi_sqlite_search_form; +template CGIsearchSQLite() { + void CGIsearchSQLite(E,O,M)(E env, O opt_action, M make_and_meta_struct) { + import + std.file, + std.format; + import doc_reform.io_out; + string _sqlite_db_fn = (opt_action.sqlite_filename.empty) + ? make_and_meta_struct.conf.w_srv_db_sqlite + : opt_action.sqlite_filename; + string _cgi_search_script = (opt_action.cgi_sqlite_search_filename.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script + : opt_action.cgi_sqlite_search_filename; + string _cgi_search_script_raw_fn_d = (opt_action.cgi_sqlite_search_filename_d.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script_raw_fn_d + : opt_action.cgi_sqlite_search_filename_d; + string the_cgi_search_form = format(q"≓ +/+ dub.sdl + name "spine search" + description "spine cgi search" ++/ +import std.format; +import std.range; +import std.regex; +import arsd.cgi; +import d2sqlite3; +import std.process : environment; +void cgi_function_intro(Cgi cgi) { + string header; + string table; + string form; + struct Config { + string http_request_type; + string http_host; + // string server_name; + string doc_root; + string cgi_root; + string cgi_script; + string data_path_html; + string db_path; + string query_string; + string http_url; + string request_method; + } + auto conf = Config(); + conf.http_request_type = environment.get("REQUEST_SCHEME", "http"); + conf.http_host = environment.get("HTTP_HOST", "localhost"); + // conf.server_name = environment.get("SERVER_NAME", "localhost"); + conf.doc_root = environment.get("DOCUMENT_ROOT", "/var/www/html"); + conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", "/usr/lib/cgi-bin/"); + // conf.cgi_script = environment.get("SCRIPT_NAME", "/cgi-bin/spine-search"); + conf.query_string = environment.get("QUERY_STRING", ""); + conf.http_url = environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string); + conf.db_path = "/var/www/html/sqlite/"; // conf.http_host ~ "/sqlite/"; + conf.request_method = environment.get("REQUEST_METHOD", "POST"); + struct CGI_val { + string db_selected = ""; + string sql_match_limit = ""; // radio: ( 1000 | 2500 ) + string sql_match_offset = ""; + string search_text = ""; + string results_type = ""; // index + bool checked_echo = false; + bool checked_stats = false; + bool checked_url = false; + bool checked_searched = false; + bool checked_tip = false; + bool checked_sql = false; + } + auto cv = CGI_val(); + cv.db_selected = "%s"; + auto text_fields() { + string canned_query_str = environment.get("QUERY_STRING", ""); + if ("query_string" in cgi.post) { + canned_query_str = environment.get("QUERY_STRING", ""); + } + string[string] canned_query; + if (conf.request_method == "POST") { + } else if (conf.request_method == "GET") { + foreach (pair_str; canned_query_str.split("&")) { + // cgi.write(pair_str ~ "
"); + string[] pair = pair_str.split("="); + canned_query[pair[0]] = pair[1]; + } + // foreach (field, content; canned_query) { + // cgi.write(field ~ ": " ~ content ~ "
"); + // } + } + static struct Rgx { + // static canned_query = ctRegex!(`\A(?P.+)\Z`, "m"); + static search_text_area = ctRegex!(`\A(?P.+)\Z`, "m"); + // static fulltext = ctRegex!(`\A(?P.+)\Z`, "m"); + static line = ctRegex!(`^(?P.+?)(?: ~|$)`, "m"); + static text = ctRegex!(`(?:^|\s~\s*)text:\s+(?P.+?)(?: ~|$)`, "m"); + static author = ctRegex!(`(?:^|\s~\s*)author:\s+(?P.+)$`, "m"); + static title = ctRegex!(`(?:^|\s~\s*)title:\s+(?P.+)$`, "m"); + static uid = ctRegex!(`(?:^|\s~\s*)uid:\s+(?P.+)$`, "m"); + static fn = ctRegex!(`(?:^|\s~\s*)fn:\s+(?P.+)$`, "m"); + static keywords = ctRegex!(`(?:^|\s~\s*)keywords:\s+(?P.+)$`, "m"); + static topic_register = ctRegex!(`(?:^|\s~\s*)topic_register:\s+(?P.+)$`, "m"); + static subject = ctRegex!(`(?:^|\s~\s*)subject:\s+(?P.+)$`, "m"); + static description = ctRegex!(`(?:^|\s~\s*)description:\s+(?P.+)$`, "m"); + static publisher = ctRegex!(`(?:^|\s~\s*)publisher:\s+(?P.+)$`, "m"); + static editor = ctRegex!(`(?:^|\s~\s*)editor:\s+(?P.+)$`, "m"); + static contributor = ctRegex!(`(?:^|\s~\s*)contributor:\s+(?P.+)$`, "m"); + 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"); + static coverage = ctRegex!(`(?:^|\s~\s*)coverage:\s+(?P.+)$`, "m"); + static rights = ctRegex!(`(?:^|\s~\s*)rights:\s+(?P.+)$`, "m"); + static comment = ctRegex!(`(?:^|\s~\s*)comment:\s+(?P.+)$`, "m"); + // static abstract_ = ctRegex!(`(?:^|\s~\s*)abstract:\s+(?P.+)$`, "m"); + static src_filename_base = ctRegex!(`^src_filename_base:\s+(?P.+)$`, "m"); + } + struct searchFields { + string canned_query = ""; // GET canned_query == cq + string search_text_area = ""; // POST search_text_area == tsa + string text = ""; // text == txt + string author = ""; // author == au + string title = ""; // title == ti + string uid = ""; // uid == uid + string fn = ""; // fn == fn + string keywords = ""; // keywords == kw + string topic_register = ""; // topic_register == tr + string subject = ""; // subject == su + string description = ""; // description == de + string publisher = ""; // publisher == pb + string editor = ""; // editor == ed + 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 + string coverage = ""; // coverage == cv + string rights = ""; // rights == rgt + string comment = ""; // comment == cmt + // string abstract = ""; + string src_filename_base = ""; // src_filename_base == bfn + string results_type = ""; // results_type == rt radio + string sql_match_limit = ""; // sql_match_limit == sml radio + string sql_match_offset = ""; // sql_match_offset == smo + string stats = ""; // stats == sts checked + string echo = ""; // echo == ec checked + string url = ""; // url == url checked + string searched = ""; // searched == se checked + string sql = ""; // sql == sql checked + } + auto rgx = Rgx(); + auto got = searchFields(); + if (environment.get("REQUEST_METHOD", "POST") == "POST") { + if ("sf" in cgi.post) { + got.search_text_area = cgi.post["sf"]; + if (auto m = got.search_text_area.matchFirst(rgx.text)) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } else if (auto m = got.search_text_area.matchFirst(rgx.line)) { + if ( + !(m["matched"].matchFirst(rgx.author)) + && !(m["matched"].matchFirst(rgx.title)) + ) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } + } + if (auto m = got.search_text_area.matchFirst(rgx.author)) { + got.author = m["matched"]; + got.canned_query ~= "&au=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.title)) { + got.title = m["matched"]; + got.canned_query ~= "&ti=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.uid)) { + got.uid = m["matched"]; + got.canned_query ~= "&uid=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.fn)) { + got.fn = m["matched"]; + got.canned_query ~= "&fn=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.keywords)) { + got.keywords = m["matched"]; + got.canned_query ~= "&kw=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.topic_register)) { + got.topic_register = m["matched"]; + got.canned_query ~= "&tr=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.subject)) { + got.subject = m["matched"]; + got.canned_query ~= "&su=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.description)) { + got.description = m["matched"]; + got.canned_query ~= "&de=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.publisher)) { + got.publisher = m["matched"]; + got.canned_query ~= "&pb=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.editor)) { + got.editor = m["matched"]; + got.canned_query ~= "&ed=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.contributor)) { + got.contributor = m["matched"]; + got.canned_query ~= "&ct=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.date)) { + got.date = m["matched"]; + got.canned_query ~= "&dt=" ~ m["matched"]; + } + // if (auto m = got.search_text_area.matchFirst(rgx.results_type)) { + // got.results_type = m["matched"]; + // got.canned_query ~= "&rt=" ~ m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.format)) { + 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"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.language)) { + got.language = m["matched"]; + got.canned_query ~= "&lng=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.relation)) { + got.relation = m["matched"]; + got.canned_query ~= "&rl=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.coverage)) { + got.coverage = m["matched"]; + got.canned_query ~= "&cv=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.rights)) { + got.rights = m["matched"]; + got.canned_query ~= "&rgt=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.comment)) { + got.comment = m["matched"]; + got.canned_query ~= "&cmt=" ~ m["matched"]; + } + // if (auto m = search_text_area.matchFirst(rgx.abstract)) { + // got.abstract = m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.src_filename_base)) { + got.src_filename_base = m["matched"]; + got.canned_query ~= "&bfn=" ~ m["matched"]; + } + } + if ("fn" in cgi.post) { + got.fn = cgi.post["fn"]; + got.canned_query ~= "&fn=" ~ cgi.post["fn"]; + } + if ("rt" in cgi.post) { + got.results_type = cgi.post["rt"]; + got.canned_query ~= "&rt=" ~ cgi.post["rt"]; + } + if ("sts" in cgi.post) { + got.stats = cgi.post["sts"]; + got.canned_query ~= "&sts=" ~ cgi.post["sts"]; + } + if ("ec" in cgi.post) { + got.echo = cgi.post["ec"]; + got.canned_query ~= "&ec=" ~ cgi.post["ec"]; + } + if ("url" in cgi.post) { + got.url = cgi.post["url"]; + got.canned_query ~= "&url=" ~ cgi.post["url"]; + } + if ("se" in cgi.post) { + got.searched = cgi.post["se"]; + got.canned_query ~= "&se=" ~ cgi.post["se"]; + } + if ("sql" in cgi.post) { + got.sql = cgi.post["sql"]; + got.canned_query ~= "&sql=" ~ cgi.post["sql"]; + } + if ("sml" in cgi.post) { + got.sql_match_limit = cgi.post["sml"]; + got.canned_query ~= "&sml=" ~ cgi.post["sml"]; + } + if ("smo" in cgi.post) { + got.sql_match_offset = "0"; // cgi.post["smo"]; + got.canned_query ~= "&smo=0"; // ~ cgi.post["smo"]; + } + got.canned_query = got.canned_query.strip.split(" ").join("%%20"); + conf.query_string = got.canned_query; + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); + } else if (environment.get("REQUEST_METHOD", "POST") == "GET") { + got.canned_query = environment.get("QUERY_STRING", ""); + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); + got.search_text_area = ""; + if ("sf" in canned_query && !(canned_query["sf"]).empty) { + got.text = canned_query["sf"].split("%%20").join(" "); + got.search_text_area ~= "text: " ~ got.text ~ "\n"; + } + if ("au" in canned_query && !(canned_query["au"]).empty) { + got.author = canned_query["au"].split("%%20").join(" "); + got.search_text_area ~= "author: " ~ got.author ~ "\n"; + } + if ("ti" in canned_query && !(canned_query["ti"]).empty) { + got.title = canned_query["ti"].split("%%20").join(" "); + got.search_text_area ~= "title: " ~ got.title ~ "\n"; + } + if ("uid" in canned_query && !(canned_query["uid"]).empty) { + got.uid = canned_query["uid"].split("%%20").join(" "); + got.search_text_area ~= "uid: " ~ got.uid ~ "\n"; + } + if ("fn" in canned_query && !(canned_query["fn"]).empty) { + got.fn = canned_query["fn"].split("%%20").join(" "); + got.search_text_area ~= "fn: " ~ got.fn ~ "\n"; + } + if ("kw" in canned_query && !(canned_query["kw"]).empty) { + got.keywords = canned_query["kw"].split("%%20").join(" "); + got.search_text_area ~= "keywords: " ~ got.keywords ~ "\n"; + } + if ("tr" in canned_query && !(canned_query["tr"]).empty) { + got.topic_register = canned_query["tr"].split("%%20").join(" "); + got.search_text_area ~= "topic_register: " ~ got.topic_register ~ "\n"; + } + if ("su" in canned_query && !(canned_query["su"]).empty) { + got.subject = canned_query["su"].split("%%20").join(" "); + got.search_text_area ~= "subject: " ~ got.subject ~ "\n"; + } + if ("de" in canned_query && !(canned_query["de"]).empty) { + got.description = canned_query["de"].split("%%20").join(" "); + got.search_text_area ~= "description: " ~ got.description ~ "\n"; + } + if ("pb" in canned_query && !(canned_query["pb"]).empty) { + got.publisher = canned_query["pb"].split("%%20").join(" "); + got.search_text_area ~= "publisher: " ~ got.publisher ~ "\n"; + } + if ("ed" in canned_query && !(canned_query["ed"]).empty) { + got.editor = canned_query["ed"].split("%%20").join(" "); + got.search_text_area ~= "editor: " ~ got.editor ~ "\n"; + } + if ("ct" in canned_query && !(canned_query["ct"]).empty) { + got.contributor = canned_query["ct"].split("%%20").join(" "); + got.search_text_area ~= "contributor: " ~ got.contributor ~ "\n"; + } + if ("dt" in canned_query && !(canned_query["dt"]).empty) { + got.date = canned_query["dt"].split("%%20").join(" "); + got.search_text_area ~= "date: " ~ got.date ~ "\n"; + } + if ("rt" in canned_query && !(canned_query["rt"]).empty) { + got.results_type = canned_query["rt"].split("%%20").join(" "); + // got.search_text_area ~= "results_type: " ~ got.results_type ~ "\n"; + } + if ("fmt" in canned_query && !(canned_query["fmt"]).empty) { + 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"; + } + if ("lng" in canned_query && !(canned_query["lng"]).empty) { + got.language = canned_query["lng"].split("%%20").join(" "); + got.search_text_area ~= "language: " ~ got.language ~ "\n"; + } + if ("rl" in canned_query && !(canned_query["rl"]).empty) { + got.relation = canned_query["rl"].split("%%20").join(" "); + got.search_text_area ~= "relation: " ~ got.relation ~ "\n"; + } + if ("cv" in canned_query && !(canned_query["cv"]).empty) { + got.coverage = canned_query["cv"].split("%%20").join(" "); + got.search_text_area ~= "coverage: " ~ got.coverage ~ "\n"; + } + if ("rgt" in canned_query && !(canned_query["rgt"]).empty) { + got.rights = canned_query["rgt"].split("%%20").join(" "); + got.search_text_area ~= "rights: " ~ got.rights ~ "\n"; + } + if ("cmt" in canned_query && !(canned_query["cmt"]).empty) { + got.comment = canned_query["cmt"].split("%%20").join(" "); + got.search_text_area ~= "comment: " ~ got.comment ~ "\n"; + } + // if ("abstract" in canned_query && !(canned_query["abstract"]).empty) { + // got.abstract = canned_query["abstract"]; + // } + if ("bfn" in canned_query && !(canned_query["bfn"]).empty) { // search_field + got.src_filename_base = canned_query["bfn"].split("%%20").join(" "); + got.search_text_area ~= "src_filename_base: " ~ got.src_filename_base ~ "\n"; + } + if ("sml" in canned_query && !(canned_query["sml"]).empty) { + got.sql_match_limit = canned_query["sml"].split("%%20").join(" "); + // got.search_text_area ~= "sql_match_limit: " ~ got.sql_match_limit ~ "\n"; + } + // cgi.write("f.search_text_area: " ~ got.search_text_area ~ "
"); + } + return got; + } + auto tf = text_fields; // + struct SQL_select { + string the_body = ""; + string the_range = ""; + } + auto sql_select = SQL_select(); + 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(); + string _previous_next = ""; + int _current_offset_value = 0; + string _set_offset_next = ""; + string _set_offset_previous = ""; + string _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; + _url_next = _url.replace(rgx.track_offset, _set_offset_next); + if (_current_offset_value < cv.sql_match_limit.to!int) { + _url_previous = ""; + } else { + _url_previous = ""; + _set_offset_previous = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int - cv.sql_match_limit.to!int).to!string; + _url_previous = _url.replace(rgx.track_offset, _set_offset_previous); + } + } else {// _current_offset_value = 0; + _url_next = _url ~= "&smo=" ~ cv.sql_match_limit.to!string; + } + if (_url_previous.empty) { + arrow_previous = ""; + } else { + arrow_previous = + "" + ~ "" + ~ "<< prev" + ~ " || "; + } + arrow_next = + "" + ~ "" + ~ "next >>" + ~ ""; + _previous_next = "
" ~ arrow_previous ~ arrow_next; + return _previous_next; + } + { + header = format(q"┃ + + + + + + ≅ SiSU spine search form + + + + + + + +┃", + conf.http_host, + ); + } + { + table = format(q"┃ + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+ ┃"); + } + { + string post_value(string field_name, string type="box", string set="on") { + string val = ""; + switch (type) { + case "field": + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? cgi.post[field_name] + : (field_name in cgi.get) + ? cgi.get[field_name] + : ""); + val = tf.search_text_area; + break; + case "box": // generic for checkbox or radio; checkbox set == "on" radio set == "name set" + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "off"); + break; + case "radio": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + case "checkbox": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + default: + } + return val; + } + string the_can(string fv) { + string show_the_can = post_value("url"); + string _the_can = ""; + if (show_the_can == "checked") { + tf = text_fields; + string method_get_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", ""); + string method_post_url_construct = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query; + // assert(method_get_url == environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string)); + if (conf.request_method == "POST") { + _the_can = + "" + ~ "POST: " + ~ "" + ~ method_post_url_construct + ~ "" + ~ "
"; + } else if (conf.request_method == "GET") { + _the_can = + "" + ~ "GET:  " + ~ "" + ~ method_get_url + ~ ""; + } + conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ tf.canned_query; + } + return _the_can; + } + string provide_tip() { + string searched_tip = post_value("se"); + string tip = ""; + if (searched_tip == "checked") { + string search_field = post_value("sf", "field"); + tf = text_fields; + tip = format(q"┃ + +database: %%s; selected view: index +search string: %%s %%s %%s %%s %%s %%s
+%%s %%s %%s %%s %%s %%s +
+┃", + cv.db_selected, + (tf.text.empty ? "" : "\"text: " ~ tf.text ~ "; "), + (tf.title.empty ? "" : "\"title: " ~ tf.title ~ "; "), + (tf.author.empty ? "" : "\"author: " ~ tf.author ~ "; "), + (tf.date.empty ? "" : "\"date " ~ tf.date ~ "; "), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + (tf.text.empty ? "" : "text: " ~ tf.text ~ "
"), + (tf.title.empty ? "" : "title: " ~ tf.title ~ "
"), + (tf.author.empty ? "" : "author: " ~ tf.author ~ "
"), + (tf.date.empty ? "" : "date: " ~ tf.date ~ "
"), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + ); + } + return tip; + } + form = format(q"┃ +
+ + +
+ + + %%s + %%s + %%s +
+ + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep; + match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement + +
+
+ + +
+┃", + "%s", + (post_value("ec") == "checked") ? post_value("sf", "field") : "", + provide_tip, + search_note, + the_can(post_value("sf", "field")), + cv.db_selected, + cv.db_selected, + post_value("rt", "box", "idx"), + post_value("rt", "box", "txt"), + post_value("sml", "box", "1000"), + post_value("sml", "box", "2500"), + post_value("ec"), + post_value("sts"), + post_value("url"), + post_value("se"), + post_value("tip"), + post_value("sql"), + ); + { + string set_value(string field_name, string default_val) { + string val; + if (field_name in cgi.post) { + val = cgi.post[field_name]; + } else if (field_name in cgi.get) { + val = cgi.get[field_name]; + } else { val = default_val; } + return val; + } + bool set_bool(string field_name) { + bool val; + if (field_name in cgi.post + && cgi.post[field_name] == "on") { + val = true; + } else if (field_name in cgi.get + && cgi.get[field_name] == "on") { + val = true; + } else { val = false; } + return val; + } + cv.db_selected = set_value("selected_db", "spine.search.db"); // selected_db == db + cv.sql_match_limit = set_value("sml", "1000"); + cv.sql_match_offset = set_value("smo", "0"); + cv.search_text = set_value("sf", ""); + cv.results_type = set_value("rt", "idx"); + cv.checked_echo = set_bool("ec"); + cv.checked_stats = set_bool("sts"); + cv.checked_url = set_bool("url"); + cv.checked_searched = set_bool("se"); + cv.checked_tip = set_bool("tip"); + cv.checked_sql = set_bool("sql"); + tf = text_fields; + } + } + { + cgi.write(header); + cgi.write(table); + cgi.write(form); + // cgi.write(previous_next); + { // debug environment + // foreach (k, d; environment.toAA) { + // cgi.write(k ~ ": " ~ d ~ "
"); + // } + } + { // debug cgi info + // cgi.write("db_selected: " ~ cv.db_selected ~ "
\n"); + // cgi.write("search_text: " ~ cv.search_text ~ "
\n"); + // cgi.write("sql_match_limit: " ~ cv.sql_match_limit ~ ";\n"); + // cgi.write("sql_match_offset: " ~ cv.sql_match_offset ~ ";\n"); + // cgi.write("results_type: " ~ cv.results_type ~ "
\n"); + // cgi.write("cv.checked_echo: " ~ (cv.checked_echo ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_stats: " ~ (cv.checked_stats ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_url: " ~ (cv.checked_url ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_searched: " ~ (cv.checked_searched ? "checked" : "off") ~ ";
\n"); + // cgi.write("cv.checked_tip: " ~ (cv.checked_tip ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_sql: " ~ (cv.checked_sql ? "checked" : "off") ~ "
\n"); + } + } + auto db = Database(conf.db_path ~ cv.db_selected); + { + uint sql_match_offset_counter(T)(T cv) { + sql_match_offset_count += cv.sql_match_limit.to!uint; + return sql_match_offset_count; + } + void sql_search_query() { + string select_field_like(string db_field, string search_field) { + string where_ = ""; + if (!(search_field.empty)) { + string _sf = search_field.strip.split("%%20").join(" "); + if (_sf.match(r" OR ")) { + _sf = _sf.split(" OR ").join("%%' OR " ~ db_field ~ " LIKE '%%"); + } + if (_sf.match(r" AND ")) { + _sf = _sf.split(" AND ").join("%%' AND " ~ db_field ~ " LIKE '%%"); + } + _sf = "( " ~ db_field ~ " LIKE\n '%%" ~ _sf ~ "%%' )"; + where_ ~= format(q"┃ + %%s +┃", + _sf + ); + } + return where_; + } + string[] _fields; + _fields ~= select_field_like("doc_objects.clean", tf.text); + _fields ~= select_field_like("metadata_and_text.title", tf.title); + _fields ~= select_field_like("metadata_and_text.creator_author", tf.author); + _fields ~= select_field_like("metadata_and_text.uid", tf.uid); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.fn); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.src_filename_base); + _fields ~= select_field_like("metadata_and_text.language_document_char", tf.language); + _fields ~= select_field_like("metadata_and_text.date_published", tf.date); + _fields ~= select_field_like("metadata_and_text.classify_keywords", tf.keywords); + _fields ~= select_field_like("metadata_and_text.classify_topic_register", tf.topic_register); + string[] fields; + foreach (f; _fields) { + if (!(f.empty)) { fields ~= f; } + } + string fields_str = ""; + fields_str ~= fields.join(" AND "); + sql_select.the_body ~= format(q"┃ +SELECT + metadata_and_text.uid, + metadata_and_text.title, + metadata_and_text.creator_author_last_first, + metadata_and_text.creator_author, + metadata_and_text.src_filename_base, + metadata_and_text.language_document_char, + metadata_and_text.date_published, + metadata_and_text.classify_keywords, + metadata_and_text.classify_topic_register, + doc_objects.body, + doc_objects.seg_name, + doc_objects.ocn, + metadata_and_text.uid +FROM + doc_objects, + metadata_and_text +WHERE ( + %%s + ) +AND + doc_objects.uid_metadata_and_text = metadata_and_text.uid +ORDER BY + metadata_and_text.creator_author_last_first, + metadata_and_text.date_published DESC, + metadata_and_text.title, + metadata_and_text.language_document_char, + metadata_and_text.src_filename_base, + doc_objects.ocn +LIMIT %%s OFFSET %%s +;┃", + fields_str, + cv.sql_match_limit, + cv.sql_match_offset, + ); + (cv.checked_sql) + ? cgi.write(previous_next ~ "
" ~ sql_select.the_body.split("\n ").join(" ").split("\n").join("
") ~ "
\n") + : ""; + cgi.write(previous_next); + auto select_query_results = db.execute(sql_select.the_body).cached; + string _old_uid = ""; + if (!select_query_results.empty) { + foreach (row; select_query_results) { + if (row["uid"].as!string != _old_uid) { + _old_uid = row["uid"].as!string; + auto m = (row["date_published"].as!string).match(regex(r"^([0-9]{4})")); // breaks if row missing or no match? + cgi.write( + "
\"" + ~ row["title"].as!string ~ "\"" + ~ " (" + ~ m.hit + ~ ") " + ~ "[" + ~ row["language_document_char"].as!string + ~ "] " + ~ row["creator_author_last_first"].as!string + ~ ":
\n" + ); + } + if (cv.results_type == "txt") { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } else { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } + } + cgi.write( previous_next); + } else { // offset_not_beyond_limit = false; + cgi.write("select_query_results empty

\n"); + } + } + sql_search_query; + } + { + db.close; + } + { + string tail = format(q"┃ + +┃"); + cgi.write(tail); + } +} +mixin GenericMain!cgi_function_intro; +≓", + _sqlite_db_fn, + _cgi_search_script, +).strip; + auto pth_sqlite_cgi = spinePathsSQLiteCGI!()(_cgi_search_script_raw_fn_d, _cgi_search_script, opt_action.output_dir_set); // TODO + { // cgi-bin search form src d + try { + if (!exists(pth_sqlite_cgi.src)) { + pth_sqlite_cgi.src.mkdirRecurse; + } + if (!exists(pth_sqlite_cgi.cgi_bin)) { + pth_sqlite_cgi.cgi_bin.mkdirRecurse; + } + auto f = File(pth_sqlite_cgi.search_form_path_out, "w"); + f.write(the_cgi_search_form); + // foreach (o; metadata_) { + // f.writeln(o); + // } + } catch (ErrnoException ex) { + // Handle error + } + // if (!(opt_action.quiet)) { + // writeln(" ", pth_sqlite_cgi.search_form); + // } + } + string the_dub_sdl = format(q"≓ +name "spine_cgi_sqlite_search" +description "spine cgi sqlite search" +authors "Ralph Amissah" +copyright "Copyright © 2020, Ralph Amissah" +license "GPL-3.0+" +dependency "d2sqlite3" version="%s" +targetType "executable" +targetPath "./cgi-bin" +mainSourceFile "%s" +configuration "default" { + targetType "executable" + targetName "%s" + postGenerateCommands "/usr/bin/notify-send -t 0 'D executable ready' 'spine cgi sqlite search d'" +} +≓", + "~>0.18.3", // d2sqlite3 dependency version + "src/" ~ _cgi_search_script_raw_fn_d, + _cgi_search_script +).strip; + { // dub.sdl + try { + auto f = File(pth_sqlite_cgi.dub_sdl_path_out, "w"); + f.write(the_dub_sdl); + // foreach (o; metadata_) { + // f.writeln(o); + // } + } catch (ErrnoException ex) { + // Handle error + } + } + } +} diff --git a/src/doc_reform/io_out/defaults.d b/src/doc_reform/io_out/defaults.d index 84bac73..36e1428 100644 --- a/src/doc_reform/io_out/defaults.d +++ b/src/doc_reform/io_out/defaults.d @@ -34,7 +34,7 @@ template InternalMarkup() { string tc_c = "┚"; string tc_p = "┆"; string img = "☼"; - string sep = "␣"; + string sep = "␣"; // "~"; string on_o = "「"; string on_c = "」"; string mk_bullet = "● "; static string indent_by_spaces_provided(int indent, string _indent_spaces ="░░") { diff --git a/src/doc_reform/io_out/hub.d b/src/doc_reform/io_out/hub.d index 548cceb..50ee897 100644 --- a/src/doc_reform/io_out/hub.d +++ b/src/doc_reform/io_out/hub.d @@ -7,7 +7,6 @@ template outputHub() { import doc_reform.io_out, doc_reform.io_out.metadata, doc_reform.io_out.xmls, - doc_reform.io_out.odt, doc_reform.io_out.create_zip_file, doc_reform.io_out.paths_output; @system void outputHub(D,I)( @@ -114,10 +113,9 @@ template outputHubOp() { import doc_reform.io_out, doc_reform.io_out.metadata, doc_reform.io_out.xmls, - doc_reform.io_out.odt, doc_reform.io_out.create_zip_file, doc_reform.io_out.paths_output; - @system void outputHubOp(E,O)(E env, O opt_action) { + @system void outputHubOp(E,O,M)(E env, O opt_action, M make_and_meta_struct) { mixin spineRgxOut; static auto rgx = RgxO(); if ((opt_action.sqlite_db_drop)) { @@ -132,6 +130,7 @@ template outputHubOp() { } if ((opt_action.sqlite_db_create)) { if ((opt_action.verbose)) { + auto pth_sqlite_db = spinePathsSQLite!()(opt_action.cgi_sqlite_search_filename, opt_action.output_dir_set); writeln("sqlite create table..."); } import doc_reform.io_out.sqlite; @@ -140,5 +139,26 @@ template outputHubOp() { writeln("sqlite create table done"); } } + if ((opt_action.cgi_search_form_codegen)) { + if ((opt_action.verbose)) { + string _sqlite_db_fn = (opt_action.sqlite_filename.empty) + ? make_and_meta_struct.conf.w_srv_db_sqlite + : opt_action.sqlite_filename; + string _cgi_search_script = (opt_action.cgi_sqlite_search_filename.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script + : opt_action.cgi_sqlite_search_filename; + string _cgi_search_script_raw_fn_d = (opt_action.cgi_sqlite_search_filename_d.empty) + ? make_and_meta_struct.conf.w_srv_cgi_search_script_raw_fn_d + : opt_action.cgi_sqlite_search_filename_d; + auto pth_sqlite_cgi = spinePathsSQLiteCGI!()(_cgi_search_script_raw_fn_d, _cgi_search_script, opt_action.output_dir_set); + writeln("sqlite cgi search form..."); + writeln(" ", pth_sqlite_cgi.search_form_path_out); + } + import doc_reform.io_out.cgi_sqlite_search_form; + CGIsearchSQLite!()(env, opt_action, make_and_meta_struct); + if ((opt_action.very_verbose)) { + writeln("sqlite cgi search form done"); + } + } } } diff --git a/src/doc_reform/io_out/metadata.d b/src/doc_reform/io_out/metadata.d index 65f40b2..6c059ce 100644 --- a/src/doc_reform/io_out/metadata.d +++ b/src/doc_reform/io_out/metadata.d @@ -84,7 +84,7 @@ string theme_light_1 = format(q"┃ Metadata Harvest - Topics - + @@ -230,7 +230,7 @@ string theme_light_1 = format(q"┃ ┃"); - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= format(q"┃

[ HOME ] Metadata Harvest [ Authors ] [ Topics ]

@@ -247,7 +247,7 @@ string theme_light_1 = format(q"┃ writeln("ERROR no Title information provided in document header ", doc_matters.src.filename_base); } if (!(doc_matters.conf_make_meta.meta.creator_author.empty)) { - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

Author: " ~ doc_matters.conf_make_meta.meta.creator_author ~ "

"; } else { @@ -292,7 +292,7 @@ string theme_light_1 = format(q"┃ if (subject_tree.length > 0) { if (subject_tree[0] != _top[0]) { _top[0] = subject_tree[0]; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

" @@ -307,7 +307,7 @@ string theme_light_1 = format(q"┃ if (subject_tree[1] != _top[1]) { _top[1] = subject_tree[1]; _top[2] = ""; _top[3] = ""; _top[4] = ""; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

4) { if (subject_tree[4] != _top[4]) { _top[4] = subject_tree[4]; - if (doc_matters.opt.action.harvest_link) { + if (doc_matters.opt.action.html_harvest_link) { metadata_ ~= "

0) + ? output_pth_root : ""; + } + string output_base() { + return ((output_root).asNormalizedPath).array; + } + } + return _PathsStruct(); + } +} template spineOutPathsFnPd() { /+ TODO stuff to work out here +/ auto spineOutPathsFnPd(Fn,Pn)( @@ -535,9 +551,9 @@ template spinePathsSQLiteDiscrete() { template spinePathsSQLite() { mixin spineRgxIn; static auto rgx = RgxI(); - auto spinePathsSQLite(DbN, Po)( - DbN db_name, - Po output_pth_root, + auto spinePathsSQLite()( + string db_name, + string output_pth_root, ) { struct _PathsStruct { string base_filename(string fn_src) { @@ -549,7 +565,43 @@ template spinePathsSQLite() { return (((out_pth.output_root).chainPath(base_dir)).asNormalizedPath).array; } string sqlite_file() { - return ((base.chainPath(base_filename(db_name) ~ ".sql.db")).asNormalizedPath).array; + return (base.chainPath(db_name).asNormalizedPath).array; + } + } + return _PathsStruct(); + } +} +template spinePathsSQLiteCGI() { + mixin spineRgxIn; + static auto rgx = RgxI(); + auto spinePathsSQLiteCGI()( + string cgi_search_form_d, + string cgi_search_form, + string output_pth_root, + ) { + struct _PathsStruct { + string base_filename(string fn_src) { + return fn_src.baseName.stripExtension; + } + string base() { + auto out_pth = spineOutPathSQLiteCGI!()(output_pth_root); + string base_dir = "cgi"; + return (((out_pth.output_root).chainPath(base_dir)).asNormalizedPath).array; + } + string src() { + return ((base.chainPath("src")).asNormalizedPath).array; + } + string cgi_bin() { + return ((base.chainPath("cgi-bin")).asNormalizedPath).array; + } + string dub_sdl_path_out() { + return ((base.chainPath("dub.sdl")).asNormalizedPath).array; + } + string search_form_dub_path() { + return ("src/".chainPath(base_filename(cgi_search_form_d)).asNormalizedPath).array; + } + string search_form_path_out() { + return (src.chainPath((cgi_search_form_d)).asNormalizedPath).array; } } return _PathsStruct(); diff --git a/src/doc_reform/io_out/sqlite.d b/src/doc_reform/io_out/sqlite.d index 1a30204..ce8f688 100644 --- a/src/doc_reform/io_out/sqlite.d +++ b/src/doc_reform/io_out/sqlite.d @@ -63,7 +63,7 @@ template SQLiteHubDiscreteBuildTablesAndPopulate() { const D doc_abstraction, M doc_matters, ) { - auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); + auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.w_srv_data_root_url, doc_matters.src.language); auto pth_sqlite = spinePathsSQLiteDiscrete!()(doc_matters.output_path, doc_matters.src.language); pth_sqlite.base.mkdirRecurse; auto db = Database(pth_sqlite.sqlite_file(doc_matters.src.filename)); @@ -261,7 +261,7 @@ template SQLiteFormatAndLoadObject() { M doc_matters, const O obj, string _txt, - string _suffix = ".html", + string _suffix = ".html", string _xml_type = "seg", ) { string _img_pth; @@ -307,7 +307,7 @@ template SQLiteFormatAndLoadObject() { _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ doc_matters.conf_make_meta.conf.w_srv_data_root_url ~ "/" ~ pth_html.tail_fn_seg(doc_matters.src.filename, "$3.html") ~ "├" @@ -316,7 +316,7 @@ template SQLiteFormatAndLoadObject() { _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ doc_matters.conf_make_meta.conf.w_srv_data_root_url ~ "/" ~ doc_matters.has.tag_associations[(m.captures[3])]["seg_lv4"] ~ ".html" @@ -341,7 +341,7 @@ template SQLiteFormatAndLoadObject() { _txt = _txt.replaceFirst( rgx.inline_link_hash, "┥$1┝┤" - ~ doc_matters.conf_make_meta.conf.webserv_url_doc_root + ~ doc_matters.conf_make_meta.conf.w_srv_data_root_url ~ "/" ~ pth_html.tail_fn_scroll(doc_matters.src.filename) ~ "#" ~ "$3" @@ -865,8 +865,8 @@ template SQLiteTablesReCreate() { DROP INDEX IF EXISTS idx_digest_all; DROP INDEX IF EXISTS idx_clean; DROP INDEX IF EXISTS idx_title; - DROP INDEX IF EXISTS idx_creator_author; - DROP INDEX IF EXISTS src_filename; + DROP INDEX IF EXISTS idx_author; + DROP INDEX IF EXISTS src_filename_base; DROP INDEX IF EXISTS idx_language_document_char; DROP INDEX IF EXISTS idx_classify_topic_register; DROP TABLE IF EXISTS metadata_and_text; @@ -885,6 +885,7 @@ template SQLiteTablesReCreate() { title_language VARCHAR(100) NULL, title_language_char VARCHAR(6) NULL, creator_author VARCHAR(600) NOT NULL, + creator_author_last_first VARCHAR(600) NOT NULL, creator_author_email VARCHAR(100) NULL, creator_author_hon VARCHAR(100) NULL, creator_author_nationality VARCHAR(100) NULL, @@ -947,7 +948,8 @@ template SQLiteTablesReCreate() { notes_prefix_b TEXT NULL, notes_suffix TEXT NULL, publisher VARCHAR(600) NULL, - src_filename VARCHAR(256) NOT NULL, + src_filename_base VARCHAR(256) NOT NULL, + src_filename_suffix VARCHAR(6) NOT NULL, src_fingerprint VARCHAR(256) NULL, src_filesize VARCHAR(10) NULL, src_wordcount VARCHAR(10) NULL, @@ -991,7 +993,7 @@ template SQLiteTablesReCreate() { last_decendant VARCHAR(16) NULL, -- headings only digest_clean CHAR(256), digest_all CHAR(256), - html_seg_url CHAR(256), + seg_name CHAR(256), types CHAR(1) NULL ); CREATE INDEX idx_ocn ON doc_objects(ocn); @@ -999,9 +1001,9 @@ template SQLiteTablesReCreate() { CREATE INDEX idx_digest_all ON doc_objects(digest_all); CREATE INDEX idx_clean ON doc_objects(clean); CREATE INDEX idx_title ON metadata_and_text(title); - CREATE INDEX idx_author ON metadata_and_text(creator_author); + CREATE INDEX idx_author ON metadata_and_text(creator_author_last_first); CREATE INDEX idx_uid ON metadata_and_text(uid); - CREATE INDEX idx_filename ON metadata_and_text(src_filename); + CREATE INDEX idx_filename ON metadata_and_text(src_filename_base); CREATE INDEX idx_language ON metadata_and_text(language_document_char); CREATE INDEX idx_topics ON metadata_and_text(classify_topic_register); ┃",); @@ -1033,7 +1035,8 @@ template SQLiteInsertMetadata() { string _insert_metadata = format(q"┃ INSERT INTO metadata_and_text ( uid, - src_filename, + src_filename_base, + src_filename_suffix, src_composite_id_per_txt, src_composite_id_per_pod, title, @@ -1043,6 +1046,7 @@ template SQLiteInsertMetadata() { title_edition, title_language, creator_author, + creator_author_last_first, creator_author_email, creator_illustrator, creator_translator, @@ -1082,11 +1086,12 @@ template SQLiteInsertMetadata() { site_url_doc_root ) VALUES ( - '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' + '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ); ┃", _uid, - SQLinsertDelimiter!()(doc_matters.src.filename), + SQLinsertDelimiter!()(doc_matters.src.filename_base), + SQLinsertDelimiter!()(doc_matters.src.filename_extension), SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_doc), SQLinsertDelimiter!()(doc_matters.src.docname_composite_unique_per_src_pod), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_full), @@ -1096,6 +1101,7 @@ template SQLiteInsertMetadata() { SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_edition), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.title_language), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author), + SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author_surname_fn), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_author_email), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_illustrator), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.creator_translator), @@ -1132,7 +1138,7 @@ template SQLiteInsertMetadata() { SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_language_char), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.original_source), SQLinsertDelimiter!()(doc_matters.conf_make_meta.meta.publisher), - SQLinsertDelimiter!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root) + SQLinsertDelimiter!()(doc_matters.conf_make_meta.conf.w_srv_data_root_url) ); if (doc_matters.conf_make_meta.meta.classify_topic_register_arr.length > 0) { @@ -1170,7 +1176,7 @@ template SQLiteInsertDocObjectsLoop() { M doc_matters, ) { string _uid = SQLinsertDelimiter!()(doc_matters.src.doc_uid); - auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.webserv_url_doc_root, doc_matters.src.language); + auto url_html = spineUrlsHTML!()(doc_matters.conf_make_meta.conf.w_srv_data_root_url, doc_matters.src.language); string insertDocObjectsRow(O)(O obj) { string _insert_doc_objects_row = format(q"┃ INSERT INTO doc_objects ( @@ -1182,7 +1188,7 @@ template SQLiteInsertDocObjectsLoop() { lev, is_of_type, is_a, - html_seg_url + seg_name ) VALUES ( '%s', %s, '%s', '%s', '%s', %s, '%s', '%s', '%s' @@ -1196,7 +1202,7 @@ template SQLiteInsertDocObjectsLoop() { obj.metainfo.heading_lev_markup, obj.metainfo.is_of_type, obj.metainfo.is_a, - url_html.fn_seg_obj_num(doc_matters.src.filename, obj.tags.html_segment_anchor_tag_is, obj.metainfo.identifier), + obj.tags.html_segment_anchor_tag_is ); return _insert_doc_objects_row; } @@ -1390,8 +1396,8 @@ template SQLiteTablesCreate() { DROP INDEX IF EXISTS idx_digest_all; DROP INDEX IF EXISTS idx_clean; DROP INDEX IF EXISTS idx_title; - DROP INDEX IF EXISTS idx_creator_author; - DROP INDEX IF EXISTS src_filename; + DROP INDEX IF EXISTS idx_author; + DROP INDEX IF EXISTS src_filename_base; DROP INDEX IF EXISTS idx_language_document_char; DROP INDEX IF EXISTS idx_classify_topic_register; DROP TABLE IF EXISTS metadata_and_text; @@ -1410,6 +1416,7 @@ template SQLiteTablesCreate() { title_language VARCHAR(100) NULL, title_language_char VARCHAR(6) NULL, creator_author VARCHAR(600) NOT NULL, + creator_author_last_first VARCHAR(600) NOT NULL, creator_author_email VARCHAR(100) NULL, creator_author_hon VARCHAR(100) NULL, creator_author_nationality VARCHAR(100) NULL, @@ -1472,7 +1479,8 @@ template SQLiteTablesCreate() { notes_prefix_b TEXT NULL, notes_suffix TEXT NULL, publisher VARCHAR(600) NULL, - src_filename VARCHAR(256) NOT NULL, + src_filename_base VARCHAR(256) NOT NULL, + src_filename_suffix VARCHAR(6) NOT NULL, src_fingerprint VARCHAR(256) NULL, src_filesize VARCHAR(10) NULL, src_wordcount VARCHAR(10) NULL, @@ -1516,7 +1524,7 @@ template SQLiteTablesCreate() { last_decendant VARCHAR(16) NULL, -- headings only digest_clean CHAR(256), digest_all CHAR(256), - html_seg_url CHAR(256), + seg_name CHAR(256), types CHAR(1) NULL ); CREATE INDEX idx_ocn ON doc_objects(ocn); @@ -1524,9 +1532,9 @@ template SQLiteTablesCreate() { CREATE INDEX idx_digest_all ON doc_objects(digest_all); CREATE INDEX idx_clean ON doc_objects(clean); CREATE INDEX idx_title ON metadata_and_text(title); - CREATE INDEX idx_author ON metadata_and_text(creator_author); + CREATE INDEX idx_author ON metadata_and_text(creator_author_last_first); CREATE INDEX idx_uid ON metadata_and_text(uid); - CREATE INDEX idx_filename ON metadata_and_text(src_filename); + CREATE INDEX idx_filename ON metadata_and_text(src_filename_base); CREATE INDEX idx_language ON metadata_and_text(language_document_char); CREATE INDEX idx_topics ON metadata_and_text(classify_topic_register); ┃",); diff --git a/src/doc_reform/io_out/xmls.d b/src/doc_reform/io_out/xmls.d index 89180eb..fb33fd0 100644 --- a/src/doc_reform/io_out/xmls.d +++ b/src/doc_reform/io_out/xmls.d @@ -94,7 +94,7 @@ template outputXHTMLs() { string _publisher="Publisher"; // TODO string o; o = format(q"┃ - + @@ -152,28 +152,28 @@ template outputXHTMLs() { @safe string inline_search_form(M)( M doc_matters, ) { - string _action="http://www.sisudoc.org/cgi-bin/search.cgi"; - string _db="spine.7a.manual"; string o; string _form; - if (doc_matters.opt.action.workon) { + if (doc_matters.opt.action.html_search_link) { o = format(q"┃

+ -
+ - + - - -
- - + + + + +
-
- ┃", - _action, - _db, + + ┃", + doc_matters.conf_make_meta.conf.w_srv_cgi_action, + doc_matters.conf_make_meta.conf.w_srv_db_sqlite, + doc_matters.src.filename_base, ); } else { o = ""; @@ -185,10 +185,18 @@ template outputXHTMLs() { string type, ) { string o; + string metadata_links = ((doc_matters.opt.action.html_harvest_link) + ? format(q"┃

[ m | A | T ]

┃", + (type == "seg") ? "../" : "", + doc_matters.src.filename_base, + (type == "seg") ? "../" : "", + (type == "seg") ? "../" : "", + ) + : ""); o = format(q"┃ - + %s%s @@ -217,14 +225,7 @@ template outputXHTMLs() { : "../../css/html_scroll.css"), doc_matters.src.language, site_info_button(doc_matters), - ((doc_matters.opt.action.harvest_link) - ? format(q"┃

[ m | A | T ]

┃", - (type == "seg") ? "../" : "", - doc_matters.src.filename_base, - (type == "seg") ? "../" : "", - (type == "seg") ? "../" : "", - ) - : ""), + metadata_links, inline_search_form(doc_matters), (type == "seg") ? "" : "\n", ); diff --git a/src/doc_reform/meta/conf_make_meta_json.d b/src/doc_reform/meta/conf_make_meta_json.d index a6214ce..23b9631 100644 --- a/src/doc_reform/meta/conf_make_meta_json.d +++ b/src/doc_reform/meta/conf_make_meta_json.d @@ -199,49 +199,49 @@ static template contentJSONtoSpineStruct() { } /+ conf ------------------------------------------------------------------- +/ if ("webserv" in _json.object) { - if ("url_root" in _json.object["webserv"] - && (_json.object["webserv"]["url_root"].type().to!string == "string") + if ("data_root_url" in _json.object["webserv"] + && (_json.object["webserv"]["data_root_url"].type().to!string == "string") ) { - _struct_composite.conf.webserv_url_doc_root = _json.object["webserv"]["url_root"].str; - if (auto m = _struct_composite.conf.webserv_url_doc_root.match(rgx.webserv_url_doc_root)) { - _struct_composite.conf.webserv_url_domain = m.captures[2].to!string; - _struct_composite.conf.webserv_url_doc_path = m.captures[3].to!string; + _struct_composite.conf.w_srv_data_root_url = _json.object["webserv"]["data_root_url"].str; + if (auto m = _struct_composite.conf.w_srv_data_root_url.match(rgx.webserv_data_root_url)) { + _struct_composite.conf.w_srv_url_domain = m.captures[2].to!string; + _struct_composite.conf.w_srv_url_doc_path = m.captures[3].to!string; } } if ("images" in _json.object["webserv"] && (_json.object["webserv"]["images"].type().to!string == "string") ) { - _struct_composite.conf.webserv_images = _json.object["webserv"]["images"].str; + _struct_composite.conf.w_srv_images = _json.object["webserv"]["images"].str; } if ("cgi" in _json.object["webserv"] && (_json.object["webserv"]["cgi"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi = _json.object["webserv"]["cgi"].str; + _struct_composite.conf.w_srv_cgi = _json.object["webserv"]["cgi"].str; } if ("cgi_host" in _json.object["webserv"] && (_json.object["webserv"]["cgi_host"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_host = _json.object["webserv"]["cgi_host"].str; + _struct_composite.conf.w_srv_cgi_host = _json.object["webserv"]["cgi_host"].str; } if ("cgi_host_path" in _json.object["webserv"] && (_json.object["webserv"]["cgi_host_path"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_host_path = _json.object["webserv"]["cgi_host_path"].str; + _struct_composite.conf.w_srv_cgi_host_path = _json.object["webserv"]["cgi_host_path"].str; } if ("cgi_port" in _json.object["webserv"] && (_json.object["webserv"]["cgi_port"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_port = _json.object["webserv"]["cgi_port"].str; + _struct_composite.conf.w_srv_cgi_port = _json.object["webserv"]["cgi_port"].str; } if ("cgi_user" in _json.object["webserv"] && (_json.object["webserv"]["cgi_user"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_user = _json.object["webserv"]["cgi_user"].str; + _struct_composite.conf.w_srv_cgi_user = _json.object["webserv"]["cgi_user"].str; } if ("cgi_file_links" in _json.object["webserv"] && (_json.object["webserv"]["cgi_file_links"].type().to!string == "string") ) { - _struct_composite.conf.webserv_cgi_file_links = _json.object["webserv"]["cgi_file_links"].str; + _struct_composite.conf.w_srv_cgi_file_links = _json.object["webserv"]["cgi_file_links"].str; } } if ("processing" in _json.object) { diff --git a/src/doc_reform/meta/conf_make_meta_structs.d b/src/doc_reform/meta/conf_make_meta_structs.d index 7698388..9707dab 100644 --- a/src/doc_reform/meta/conf_make_meta_structs.d +++ b/src/doc_reform/meta/conf_make_meta_structs.d @@ -141,16 +141,31 @@ struct ConfCompositeMakeInit { string texpdf_font; } struct ConfCompositeSiteLocal { - string webserv_url_doc_root; - string webserv_url_domain; - string webserv_url_doc_path; - string webserv_images; - string webserv_cgi; - string webserv_cgi_host; - string webserv_cgi_host_path; - string webserv_cgi_port; - string webserv_cgi_user; - string webserv_cgi_file_links; + string w_srv_http; + string w_srv_domain; + string w_srv_data_http; // if not set same as webserv_http + string w_srv_data_domain; // if not set same as webserv_domain + string w_srv_data_root_part; + string w_srv_data_root_url; + string w_srv_data_root_path; + string w_srv_images_root_part; + // string w_srv_url_doc_path; + string w_srv_cgi_title; + string w_srv_cgi_http; // if not set same as webserv_http + string w_srv_cgi_domain; // if not set same as webserv_domain + string w_srv_cgi_bin_part; + string w_srv_cgi_bin_path; + string w_srv_cgi_search_script; + string w_srv_cgi_search_script_raw_fn_d; + string w_srv_cgi_port; + string w_srv_cgi_user; + string w_srv_cgi_action; + string w_srv_cgi_bin_url; + string w_srv_db_sqlite; + // string w_srv_db_pg; + string w_srv_db_pg_table; + string w_srv_db_pg_user; + // string webserv_cgi_file_links; string output_path; string processing_path; string processing_dir; diff --git a/src/doc_reform/meta/conf_make_meta_yaml.d b/src/doc_reform/meta/conf_make_meta_yaml.d index 2efd515..1b5ec70 100644 --- a/src/doc_reform/meta/conf_make_meta_yaml.d +++ b/src/doc_reform/meta/conf_make_meta_yaml.d @@ -187,57 +187,161 @@ template contentYAMLtoSpineStruct() { if (_yaml["webserv"].type.mapping && _yaml["webserv"].tag.match(rgx.yaml_tag_is_map) ) { - if ("url_root" in _yaml["webserv"] - && _yaml["webserv"]["url_root"].type.string - && _yaml["webserv"]["url_root"].tag.match(rgx.yaml_tag_is_str) - ) { - _struct_composite.conf.webserv_url_doc_root = _yaml["webserv"]["url_root"].get!string; - if (auto m = _struct_composite.conf.webserv_url_doc_root.match(rgx.webserv_url_doc_root)) { - _struct_composite.conf.webserv_url_domain = m.captures[2].to!string; - _struct_composite.conf.webserv_url_doc_path = m.captures[3].to!string; - } + if ("http" in _yaml["webserv"] + && _yaml["webserv"]["http"].type.string + && _yaml["webserv"]["http"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_http = _yaml["webserv"]["http"].get!string; + } // else { set default? } + if ("data_http" in _yaml["webserv"] + && _yaml["webserv"]["data_http"].type.string + && _yaml["webserv"]["data_http"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_http = _yaml["webserv"]["data_http"].get!string; + } + if ("cgi_http" in _yaml["webserv"] + && _yaml["webserv"]["cgi_http"].type.string + && _yaml["webserv"]["cgi_http"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_http = _yaml["webserv"]["cgi_http"].get!string; + } + if ("domain" in _yaml["webserv"] + && _yaml["webserv"]["domain"].type.string + && _yaml["webserv"]["domain"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_domain = _yaml["webserv"]["domain"].get!string; + } + // if ("data_root_url" in _yaml["webserv"] + // && _yaml["webserv"]["data_root_url"].type.string + // && _yaml["webserv"]["data_root_url"].tag.match(rgx.yaml_tag_is_str) + // ) { + // _struct_composite.conf.w_srv_data_root_url = _yaml["webserv"]["data_root_url"].get!string; + // if (auto m = _struct_composite.conf.w_srv_data_root_url.match(rgx.webserv_url_doc_root)) { + // _struct_composite.conf.w_srv_url_domain = m.captures[2].to!string; + // _struct_composite.conf.w_srv_url_doc_path = m.captures[3].to!string; + // } + // } + if ("data_root_path" in _yaml["webserv"] + && _yaml["webserv"]["data_root_path"].type.string + && _yaml["webserv"]["data_root_path"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_root_path = _yaml["webserv"]["data_root_path"].get!string; + } + if ("data_root_part" in _yaml["webserv"] + && _yaml["webserv"]["data_root_part"].type.string + && _yaml["webserv"]["data_root_part"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_data_root_part = _yaml["webserv"]["data_root_part"].get!string; + } + if ("images_root_part" in _yaml["webserv"] + && _yaml["webserv"]["images_root_part"].type.string + && _yaml["webserv"]["images_root_part"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_images_root_part = _yaml["webserv"]["images_root_part"].get!string; } - if ("images" in _yaml["webserv"] - && _yaml["webserv"]["images"].type.string - && _yaml["webserv"]["images"].tag.match(rgx.yaml_tag_is_str) + if ("data_root_url" in _yaml["webserv"] + && _yaml["webserv"]["data_root_url"].type.string + && _yaml["webserv"]["data_root_url"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_images = _yaml["webserv"]["images"].get!string; + _struct_composite.conf.w_srv_data_root_url = _yaml["webserv"]["data_root_url"].get!string; + } else { + _struct_composite.conf.w_srv_data_root_url = _struct_composite.conf.w_srv_data_root_part; + } + if ("cgi_domain" in _yaml["webserv"] + && _yaml["webserv"]["cgi_domain"].type.string + && _yaml["webserv"]["cgi_domain"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_domain = _yaml["webserv"]["cgi_domain"].get!string; + } else { // composite construct + _struct_composite.conf.w_srv_cgi_domain = _struct_composite.conf.w_srv_domain; } - if ("cgi" in _yaml["webserv"] - && _yaml["webserv"]["cgi"].type.string - && _yaml["webserv"]["cgi"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_title" in _yaml["webserv"] + && _yaml["webserv"]["cgi_title"].type.string + && _yaml["webserv"]["cgi_title"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi = _yaml["webserv"]["cgi"].get!string; + _struct_composite.conf.w_srv_cgi_title = _yaml["webserv"]["cgi_title"].get!string; } - if ("cgi_host" in _yaml["webserv"] - && _yaml["webserv"]["cgi_host"].type.string - && _yaml["webserv"]["cgi_host"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_bin_part" in _yaml["webserv"] + && _yaml["webserv"]["cgi_bin_part"].type.string + && _yaml["webserv"]["cgi_bin_part"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_host = _yaml["webserv"]["cgi_host"].get!string; + _struct_composite.conf.w_srv_cgi_bin_part = _yaml["webserv"]["cgi_bin_part"].get!string; } - if ("cgi_host_path" in _yaml["webserv"] - && _yaml["webserv"]["cgi_host_path"].type.string - && _yaml["webserv"]["cgi_host_path"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_bin_path" in _yaml["webserv"] + && _yaml["webserv"]["cgi_bin_path"].type.string + && _yaml["webserv"]["cgi_bin_path"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_host_path = _yaml["webserv"]["cgi_host_path"].get!string; + _struct_composite.conf.w_srv_cgi_bin_path = _yaml["webserv"]["cgi_bin_path"].get!string; + } + if ("cgi_search_script" in _yaml["webserv"] + && _yaml["webserv"]["cgi_search_script"].type.string + && _yaml["webserv"]["cgi_search_script"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_search_script = _yaml["webserv"]["cgi_search_script"].get!string; + } else { + _struct_composite.conf.w_srv_cgi_search_script = "spine-search"; + } + if ("cgi_search_script_raw_fn_d" in _yaml["webserv"] + && _yaml["webserv"]["cgi_search_script_raw_fn_d"].type.string + && _yaml["webserv"]["cgi_search_script_raw_fn_d"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_search_script_raw_fn_d = _yaml["webserv"]["cgi_search_script_raw_fn_d"].get!string; + } else if ("cgi_search_script" in _yaml["webserv"] + && _yaml["webserv"]["cgi_search_script"].type.string + && _yaml["webserv"]["cgi_search_script"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_search_script_raw_fn_d = (_yaml["webserv"]["cgi_search_script"].get!string).translate(['-' : "_"]) ~ ".d"; + } else { + _struct_composite.conf.w_srv_cgi_search_script_raw_fn_d = "spine_search.d"; } if ("cgi_port" in _yaml["webserv"] && _yaml["webserv"]["cgi_port"].type.string && _yaml["webserv"]["cgi_port"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_port = _yaml["webserv"]["cgi_port"].get!string; + _struct_composite.conf.w_srv_cgi_port = _yaml["webserv"]["cgi_port"].get!string; } if ("cgi_user" in _yaml["webserv"] && _yaml["webserv"]["cgi_user"].type.string && _yaml["webserv"]["cgi_user"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_user = _yaml["webserv"]["cgi_user"].get!string; + _struct_composite.conf.w_srv_cgi_user = _yaml["webserv"]["cgi_user"].get!string; } - if ("cgi_file_links" in _yaml["webserv"] - && _yaml["webserv"]["cgi_file_links"].type.string - && _yaml["webserv"]["cgi_file_links"].tag.match(rgx.yaml_tag_is_str) + if ("cgi_action" in _yaml["webserv"] + && _yaml["webserv"]["cgi_action"].type.string + && _yaml["webserv"]["cgi_action"].tag.match(rgx.yaml_tag_is_str) ) { - _struct_composite.conf.webserv_cgi_file_links = _yaml["webserv"]["cgi_file_links"].get!string; + _struct_composite.conf.w_srv_cgi_action = _yaml["webserv"]["cgi_action"].get!string; + } else { // action is composite, build + } + if ("cgi_bin_url" in _yaml["webserv"] + && _yaml["webserv"]["cgi_bin_url"].type.string + && _yaml["webserv"]["cgi_bin_url"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_cgi_bin_url = _yaml["webserv"]["cgi_bin_url"].get!string; + } else { + _struct_composite.conf.w_srv_cgi_bin_url = + (_struct_composite.conf.w_srv_cgi_http.empty) + ? _struct_composite.conf.w_srv_http + :_struct_composite.conf.w_srv_cgi_http + ~ "://" + ~ (_struct_composite.conf.w_srv_cgi_domain.empty) + ? _struct_composite.conf.w_srv_cgi_domain + : _struct_composite.conf.w_srv_domain + ~ "/" + ~ _struct_composite.conf.w_srv_cgi_bin_part; + } + // if ("cgi_file_links" in _yaml["webserv"] + // && _yaml["webserv"]["cgi_file_links"].type.string + // && _yaml["webserv"]["cgi_file_links"].tag.match(rgx.yaml_tag_is_str) + // ) { + // _struct_composite.conf.w_srv_cgi_file_links = _yaml["webserv"]["cgi_file_links"].get!string; + // } + if ("db_sqlite" in _yaml["webserv"] + && _yaml["webserv"]["db_sqlite"].type.string + && _yaml["webserv"]["db_sqlite"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.w_srv_db_sqlite = _yaml["webserv"]["db_sqlite"].get!string; + } else { // set default ? } } } diff --git a/src/doc_reform/meta/defaults.d b/src/doc_reform/meta/defaults.d index 63eb5fa..8d34069 100644 --- a/src/doc_reform/meta/defaults.d +++ b/src/doc_reform/meta/defaults.d @@ -187,7 +187,7 @@ template InternalMarkup() { string tc_c = "┚"; string tc_p = "┆"; string img = "☼"; - string sep = "␣"; + string sep = "␣"; // "~"; string on_o = "「"; string on_c = "」"; string mk_bullet = "● "; static string indent_by_spaces_provided(int indent, string _indent_spaces ="░░") { diff --git a/src/doc_reform/meta/metadoc.d b/src/doc_reform/meta/metadoc.d index b0b4fdc..cf74e23 100644 --- a/src/doc_reform/meta/metadoc.d +++ b/src/doc_reform/meta/metadoc.d @@ -186,6 +186,12 @@ template spineAbstraction() { @safe string filename() { return _opt_action.sqlite_filename; } + @safe string cgi_filename() { + return _opt_action.cgi_sqlite_search_filename; + } + @safe string cgi_filename_d() { + return _opt_action.cgi_sqlite_search_filename_d; + } } return SQLite_(); } diff --git a/src/doc_reform/meta/metadoc_show_config.d b/src/doc_reform/meta/metadoc_show_config.d index a432c3b..630fe0c 100644 --- a/src/doc_reform/meta/metadoc_show_config.d +++ b/src/doc_reform/meta/metadoc_show_config.d @@ -31,32 +31,44 @@ template spineShowConfig() { } if (doc_matters.opt.action.show_config) { writefln( - "%s\n\"%s\", %s\n%s\n%s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n", + "%s\n\"%s\", %s\n%s\n%s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n%30-s%10-s\n", markup.repeat_character_by_number_provided("-", char_repeat_number), doc_matters.conf_make_meta.meta.title_full, doc_matters.conf_make_meta.meta.creator_author, doc_matters.src.filename, markup.repeat_character_by_number_provided("-", char_repeat_number), - "- webserv url domain:", - doc_matters.conf_make_meta.conf.webserv_url_domain, - "- webserv doc root:", - doc_matters.conf_make_meta.conf.webserv_url_doc_root, + "- webserv domain name:", + doc_matters.conf_make_meta.conf.w_srv_domain, + "- webserv doc root (part):", + doc_matters.conf_make_meta.conf.w_srv_data_root_part, "- webserv doc path:", - doc_matters.conf_make_meta.conf.webserv_url_doc_path, + doc_matters.conf_make_meta.conf.w_srv_data_root_path, "- webserv images (location):", - doc_matters.conf_make_meta.conf.webserv_images, - "- webserv cgi:", - doc_matters.conf_make_meta.conf.webserv_cgi, - "- webserv cgi host:", - doc_matters.conf_make_meta.conf.webserv_cgi_host, + doc_matters.conf_make_meta.conf.w_srv_images_root_part, + "- webserv doc root url:", + doc_matters.conf_make_meta.conf.w_srv_data_root_url, + "- webserv cgi domain (host):", + doc_matters.conf_make_meta.conf.w_srv_cgi_domain, "- webserv cgi host path:", - doc_matters.conf_make_meta.conf.webserv_cgi_host_path, + doc_matters.conf_make_meta.conf.w_srv_cgi_bin_path, + "- webserv cgi host (part):", + doc_matters.conf_make_meta.conf.w_srv_cgi_bin_part, + "- webserv cgi search script:", + doc_matters.conf_make_meta.conf.w_srv_cgi_search_script, + "- webserv cgi search script in d:", + doc_matters.conf_make_meta.conf.w_srv_cgi_search_script_raw_fn_d, "- webserv cgi port:", - doc_matters.conf_make_meta.conf.webserv_cgi_port, + doc_matters.conf_make_meta.conf.w_srv_cgi_port, "- webserv cgi user:", - doc_matters.conf_make_meta.conf.webserv_cgi_user, - "- webserv cgi file links:", - doc_matters.conf_make_meta.conf.webserv_cgi_file_links, + doc_matters.conf_make_meta.conf.w_srv_cgi_user, + "- webserv cgi url:", + doc_matters.conf_make_meta.conf.w_srv_cgi_bin_url, + "- webserv cgi action:", + doc_matters.conf_make_meta.conf.w_srv_cgi_action, + // "- webserv cgi file links:", + // doc_matters.conf_make_meta.conf.w_srv_cgi_file_links, + "- webserv sqlite db:", + doc_matters.conf_make_meta.conf.w_srv_db_sqlite, "- output path:", doc_matters.conf_make_meta.conf.output_path, "- processing concordance max:", diff --git a/src/doc_reform/spine.d b/src/doc_reform/spine.d index 3f422b4..3a64726 100755 --- a/src/doc_reform/spine.d +++ b/src/doc_reform/spine.d @@ -112,134 +112,140 @@ string program_name = "spine"; } } bool[string] opts = [ - "abstraction" : false, - "assertions" : false, - "concordance" : false, - "dark" : false, - "debug" : false, - "digest" : false, - "epub" : false, - "harvest" : false, - "harvest-authors" : false, - "harvest-topics" : false, - "harvest-link" : false, - "html" : false, - "html-seg" : false, - "html-scroll" : false, - "latex" : false, - "latex-color-links" : false, - "light" : false, - "manifest" : false, - "hide-ocn" : false, - "ocn-off" : false, - "odf" : false, - "odt" : false, - "parallel" : false, - "parallel-subprocesses" : false, - "pdf" : false, - "pdf-color-links" : false, - "quiet" : false, - "pod" : false, - "serial" : false, - "show-summary" : false, - "show-metadata" : false, - "show-make" : false, - "show-config" : false, - "source" : false, - "sqlite-discrete" : false, - "sqlite-db-create" : false, - "sqlite-db-drop" : false, - "sqlite-db-recreate" : false, - "sqlite-delete" : false, - "sqlite-insert" : false, - "sqlite-update" : false, - "text" : false, - "verbose" : false, - "very-verbose" : false, - "xhtml" : false, - "section_toc" : true, - "section_body" : true, - "section_endnotes" : true, - "section_glossary" : true, - "section_biblio" : true, - "section_bookindex" : true, - "section_blurb" : true, - "backmatter" : true, - "skip-output" : false, - "theme-dark" : false, - "theme-light" : false, - "workon" : false, + "abstraction" : false, + "assertions" : false, + "cgi-search-form-codegen" : false, + "concordance" : false, + "dark" : false, + "debug" : false, + "digest" : false, + "epub" : false, + "harvest" : false, + "harvest-authors" : false, + "harvest-topics" : false, + "html" : false, + "html-link-harvest" : false, + "html-link-search" : false, + "html-seg" : false, + "html-scroll" : false, + "latex" : false, + "latex-color-links" : false, + "light" : false, + "manifest" : false, + "hide-ocn" : false, + "ocn-off" : false, + "odf" : false, + "odt" : false, + "parallel" : false, + "parallel-subprocesses" : false, + "pdf" : false, + "pdf-color-links" : false, + "quiet" : false, + "pod" : false, + "serial" : false, + "show-summary" : false, + "show-metadata" : false, + "show-make" : false, + "show-config" : false, + "source" : false, + "sqlite-discrete" : false, + "sqlite-db-create" : false, + "sqlite-db-drop" : false, + "sqlite-db-recreate" : false, + "sqlite-delete" : false, + "sqlite-insert" : false, + "sqlite-update" : false, + "text" : false, + "verbose" : false, + "very-verbose" : false, + "xhtml" : false, + "section_toc" : true, + "section_body" : true, + "section_endnotes" : true, + "section_glossary" : true, + "section_biblio" : true, + "section_bookindex" : true, + "section_blurb" : true, + "backmatter" : true, + "skip-output" : false, + "theme-dark" : false, + "theme-light" : false, + "workon" : false, ]; string[string] settings = [ + "cgi-sqlite-search-filename" : "", // "spine-search" "config" : "", "output" : "", "lang" : "all", - "sqlite-filename" : "documents", + "sqlite-db-filename" : "", // "spine-search.db" ]; auto helpInfo = getopt(args, std.getopt.config.passThrough, - "abstraction", "--abstraction document abstraction ", &opts["abstraction"], - "assert", "--assert set optional assertions on", &opts["assertions"], - "concordance", "--concordance file for document", &opts["concordance"], - "dark", "--dark alternative dark theme", &opts["dark"], - "debug", "--debug", &opts["debug"], - "digest", "--digest hash digest for each object", &opts["digest"], - "epub", "--epub process epub output", &opts["epub"], - "harvest", "--harvest extract info on authors & topics from document header metadata", &opts["harvest"], - "harvest-authors", "--harvest-authors extract info on authors from document header metadata", &opts["harvest-authors"], - "harvest-topics", "--harvest-topics extract info on topics from document header metadata", &opts["harvest-topics"], - "harvest-link", "--harvest-link place links back to harvest in segmented html", &opts["harvest-link"], - "html", "--html process html output", &opts["html"], - "html-seg", "--html-seg process html output", &opts["html-seg"], - "html-scroll", "--html-seg process html output", &opts["html-scroll"], - "latex", "--latex output for pdfs", &opts["latex"], - "latex-color-links", "--latex-color-links mono or color links for pdfs", &opts["latex-color-links"], - "light", "--light default light theme", &opts["light"], - "manifest", "--manifest process manifest output", &opts["manifest"], - "hide-ocn", "--hide-ocn object cite numbers", &opts["hide-ocn"], - "ocn-off", "--ocn-off object cite numbers", &opts["ocn-off"], - "odf", "--odf open document format text (--odt)", &opts["odf"], - "odt", "--odt open document format text", &opts["odt"], - "parallel", "--parallel parallelisation", &opts["parallel"], - "parallel-subprocesses", "--parallel-subprocesses nested parallelisation", &opts["parallel-subprocesses"], - "quiet|q", "--quiet output to terminal", &opts["quiet"], - "pdf", "--pdf latex output for pdfs", &opts["pdf"], - "pdf-color-links", "--pdf-color-links mono or color links for pdfs", &opts["pdf-color-links"], - "pod", "--pod spine (doc reform) pod source content bundled", &opts["pod"], - "serial", "--serial serial processing", &opts["serial"], - "show-summary", "--show-summary", &opts["show-summary"], - "show-make", "--show-make", &opts["show-make"], - "show-metadata", "--show-metadata", &opts["show-metadata"], - "show-config", "--show-config", &opts["show-config"], - "source", "--source markup source text content", &opts["source"], - "sqlite-discrete", "--sqlite process discrete sqlite output", &opts["sqlite-discrete"], - "sqlite-db-create", "--sqlite-db-create create db, create tables", &opts["sqlite-db-create"], - "sqlite-db-drop", "--sqlite-db-drop drop tables & db", &opts["sqlite-db-drop"], - "sqlite-db-recreate", "--sqlite-db-recreate create db, create tables", &opts["sqlite-db-recreate"], - "sqlite-delete", "--sqlite-delete process sqlite output", &opts["sqlite-delete"], - "sqlite-insert", "--sqlite-insert process sqlite output", &opts["sqlite-insert"], - "sqlite-update", "--sqlite-update process sqlite output", &opts["sqlite-update"], - "text", "--text process text output", &opts["text"], - "txt", "--txt process text output", &opts["text"], - "verbose|v", "--verbose output to terminal", &opts["verbose"], - "very-verbose", "--very-verbose output to terminal", &opts["very-verbose"], - "xhtml", "--xhtml process xhtml output", &opts["xhtml"], - "section-toc", "--section-toc process table of contents (default)", &opts["section_toc"], - "section-body", "--section-body process document body (default)", &opts["section_body"], - "section-endnotes", "--section-endnotes process document endnotes (default)", &opts["section_endnotes"], - "section-glossary", "--section-glossary process document glossary (default)", &opts["section_glossary"], - "section-biblio", "--section-biblio process document biblio (default)", &opts["section_biblio"], - "section-bookindex", "--section-bookindex process document bookindex (default)", &opts["section_bookindex"], - "section-blurb", "--section-blurb process document blurb (default)", &opts["section_blurb"], - "backmatter", "--section-backmatter process document backmatter (default)", &opts["backmatter"], - "skip-output", "--skip-output", &opts["skip-output"], - "theme-dark", "--theme-dark alternative dark theme", &opts["theme-dark"], - "theme-light", "--theme-light default light theme", &opts["theme-light"], - "workon", "--workon (reserved for some matters under development & testing)", &opts["workon"], - "config", "--config=/path/to/config/file/including/filename", &settings["config"], - "output", "--output=/path/to/output/dir specify where to place output", &settings["output"], - "sqlite-filename", "--sqlite-filename=[filename].sqlite", &settings["sqlite-filename"], - "lang", "--lang=[lang code e.g. =en or =en,es]", &settings["lang"], + "abstraction", "--abstraction document abstraction ", &opts["abstraction"], + "assert", "--assert set optional assertions on", &opts["assertions"], + "cgi-search-form-codegen", "--cgi-search-form-codegen pre-compiled d code search of specified db", &opts["cgi-search-form-codegen"], + "concordance", "--concordance file for document", &opts["concordance"], + "dark", "--dark alternative dark theme", &opts["dark"], + "debug", "--debug", &opts["debug"], + "digest", "--digest hash digest for each object", &opts["digest"], + "epub", "--epub process epub output", &opts["epub"], + "harvest", "--harvest extract info on authors & topics from document header metadata", &opts["harvest"], + "harvest-authors", "--harvest-authors extract info on authors from document header metadata", &opts["harvest-authors"], + "harvest-topics", "--harvest-topics extract info on topics from document header metadata", &opts["harvest-topics"], + "html", "--html process html output", &opts["html"], + "html-link-harvest", "--html-link-harvest place links back to harvest in segmented html", &opts["html-link-harvest"], + "html-link-search", "--html-link-search html embedded search submission", &opts["html-link-search"], + "html-seg", "--html-seg process html output", &opts["html-seg"], + "html-scroll", "--html-seg process html output", &opts["html-scroll"], + "latex", "--latex output for pdfs", &opts["latex"], + "latex-color-links", "--latex-color-links mono or color links for pdfs", &opts["latex-color-links"], + "light", "--light default light theme", &opts["light"], + "manifest", "--manifest process manifest output", &opts["manifest"], + "hide-ocn", "--hide-ocn object cite numbers", &opts["hide-ocn"], + "ocn-off", "--ocn-off object cite numbers", &opts["ocn-off"], + "odf", "--odf open document format text (--odt)", &opts["odf"], + "odt", "--odt open document format text", &opts["odt"], + "parallel", "--parallel parallelisation", &opts["parallel"], + "parallel-subprocesses", "--parallel-subprocesses nested parallelisation", &opts["parallel-subprocesses"], + "quiet|q", "--quiet output to terminal", &opts["quiet"], + "pdf", "--pdf latex output for pdfs", &opts["pdf"], + "pdf-color-links", "--pdf-color-links mono or color links for pdfs", &opts["pdf-color-links"], + "pod", "--pod spine (doc reform) pod source content bundled", &opts["pod"], + "serial", "--serial serial processing", &opts["serial"], + "show-summary", "--show-summary", &opts["show-summary"], + "show-make", "--show-make", &opts["show-make"], + "show-metadata", "--show-metadata", &opts["show-metadata"], + "show-config", "--show-config", &opts["show-config"], + "source", "--source markup source text content", &opts["source"], + "sqlite-discrete", "--sqlite process discrete sqlite output", &opts["sqlite-discrete"], + "sqlite-db-create", "--sqlite-db-create create db, create tables", &opts["sqlite-db-create"], + "sqlite-db-drop", "--sqlite-db-drop drop tables & db", &opts["sqlite-db-drop"], + "sqlite-db-recreate", "--sqlite-db-recreate create db, create tables", &opts["sqlite-db-recreate"], + "sqlite-delete", "--sqlite-delete process sqlite output", &opts["sqlite-delete"], + "sqlite-insert", "--sqlite-insert process sqlite output", &opts["sqlite-insert"], + "sqlite-update", "--sqlite-update process sqlite output", &opts["sqlite-update"], + "text", "--text process text output", &opts["text"], + "txt", "--txt process text output", &opts["text"], + "verbose|v", "--verbose output to terminal", &opts["verbose"], + "very-verbose", "--very-verbose output to terminal", &opts["very-verbose"], + "xhtml", "--xhtml process xhtml output", &opts["xhtml"], + "section-toc", "--section-toc process table of contents (default)", &opts["section_toc"], + "section-body", "--section-body process document body (default)", &opts["section_body"], + "section-endnotes", "--section-endnotes process document endnotes (default)", &opts["section_endnotes"], + "section-glossary", "--section-glossary process document glossary (default)", &opts["section_glossary"], + "section-biblio", "--section-biblio process document biblio (default)", &opts["section_biblio"], + "section-bookindex", "--section-bookindex process document bookindex (default)", &opts["section_bookindex"], + "section-blurb", "--section-blurb process document blurb (default)", &opts["section_blurb"], + "backmatter", "--section-backmatter process document backmatter (default)", &opts["backmatter"], + "skip-output", "--skip-output", &opts["skip-output"], + "theme-dark", "--theme-dark alternative dark theme", &opts["theme-dark"], + "theme-light", "--theme-light default light theme", &opts["theme-light"], + "workon", "--workon (reserved for some matters under development & testing)", &opts["workon"], + "cgi-sqlite-search-filename", "--cgi-sqlite-search-filename=[filename]", &settings["cgi-sqlite-search-filename"], + "config", "--config=/path/to/config/file/including/filename", &settings["config"], + "output", "--output=/path/to/output/dir specify where to place output", &settings["output"], + "sqlite-db-filename", "--sqlite-db-filename=[filename].sql.db", &settings["sqlite-db-filename"], + "lang", "--lang=[lang code e.g. =en or =en,es]", &settings["lang"], ); if (helpInfo.helpWanted) { defaultGetoptPrinter("Some information about the program.", helpInfo.options); @@ -249,6 +255,9 @@ string program_name = "spine"; @trusted bool assertions() { return opts["assertions"]; } + @trusted bool cgi_search_form_codegen() { + return opts["cgi-search-form-codegen"]; + } @trusted bool concordance() { return opts["concordance"]; } @@ -275,8 +284,11 @@ string program_name = "spine"; @trusted bool epub() { return opts["epub"]; } - @trusted bool harvest_link() { - return (opts["harvest-link"]) ? true : false; + @trusted bool html_harvest_link() { + return (opts["html-link-harvest"]) ? true : false; + } + @trusted bool html_search_link() { + return (opts["html-link-search"]) ? true : false; } @trusted bool harvest() { return (opts["harvest"] || opts["harvest-authors"] || opts["harvest-topics"]) ? true : false; @@ -414,7 +426,13 @@ string program_name = "spine"; return settings["output"]; } auto sqlite_filename() { - return settings["sqlite-filename"]; + return settings["sqlite-db-filename"]; + } + auto cgi_sqlite_search_filename() { + return settings["cgi-sqlite-search-filename"]; + } + auto cgi_sqlite_search_filename_d() { + return (settings["cgi-sqlite-search-filename"].translate(['-' : "_"]) ~ ".d"); } @trusted bool parallelise() { bool _is; @@ -719,7 +737,7 @@ string program_name = "spine"; ) { writeln("step0 commence → (without processing files)"); } - outputHubOp!()(_env, _opt_action); + outputHubOp!()(_env, _opt_action, _make_and_meta_struct); if ((_opt_action.debug_do) || (_opt_action.very_verbose) ) { diff --git a/util/d/cgi/search/README b/util/d/cgi/search/README new file mode 100644 index 0000000..eb8fcde --- /dev/null +++ b/util/d/cgi/search/README @@ -0,0 +1,11 @@ +change db name to match name of db you create +cv.db_selected = "spine.search.sql.db"; + +~dr/bin/spine-ldc -v --sqlite-db-create --sqlite-db-filename="spine.search.db" --cgi-sqlite-search-filename="spine-search" --output=/var/www ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +~dr/bin/spine-ldc -v --sqlite-update --sqlite-db-filename="spine.search.db" --output=/var/www ~grotto/repo/git.repo/code/project-spine/doc-reform-markup/markup_samples/markup/pod/* + +cd util/d/cgi/search/src +dub --force --compiler=ldc2 && sudo cp -v cgi-bin/spine-search /usr/lib/cgi-bin/. + +http://localhost/cgi-bin/spine-search? diff --git a/util/d/cgi/search/dub.sdl b/util/d/cgi/search/dub.sdl new file mode 100644 index 0000000..c1c775c --- /dev/null +++ b/util/d/cgi/search/dub.sdl @@ -0,0 +1,14 @@ +name "spine-search" +description "A minimal D application." +authors "ralph" +copyright "Copyright © 2020, ralph" +license "GPL-3.0+" +dependency "d2sqlite3" version="~>0.18.3" +targetType "executable" +targetPath "./cgi-bin" +mainSourceFile "src/spine_cgi_sqlite_search.d" +configuration "default" { + targetType "executable" + targetName "spine-search" + postGenerateCommands "/usr/bin/notify-send -t 0 'D executable ready' 'spine cgi sqlite search d'" +} diff --git a/util/d/cgi/search/dub.selections.json b/util/d/cgi/search/dub.selections.json new file mode 100644 index 0000000..e6e1b26 --- /dev/null +++ b/util/d/cgi/search/dub.selections.json @@ -0,0 +1,7 @@ +{ + "fileVersion": 1, + "versions": { + "d2sqlite3": "0.18.3", + "dcgi": "0.1.0" + } +} diff --git a/util/d/cgi/search/localhostsqlitespine.search.sql.db b/util/d/cgi/search/localhostsqlitespine.search.sql.db new file mode 100644 index 0000000..e69de29 diff --git a/util/d/cgi/search/src/spine_cgi_sqlite_search.d b/util/d/cgi/search/src/spine_cgi_sqlite_search.d new file mode 100644 index 0000000..1460643 --- /dev/null +++ b/util/d/cgi/search/src/spine_cgi_sqlite_search.d @@ -0,0 +1,913 @@ +/+ dub.sdl + name "spine search" + description "spine cgi search" ++/ +import std.format; +import std.range; +import std.regex; +import arsd.cgi; +import d2sqlite3; +import std.process : environment; +void cgi_function_intro(Cgi cgi) { + string header; + string table; + string form; + struct Config { + string http_request_type; + string http_host; + // string server_name; + string doc_root; + string cgi_root; + string cgi_script; + string data_path_html; + string db_path; + string query_string; + string http_url; + string request_method; + } + auto conf = Config(); + conf.http_request_type = environment.get("REQUEST_SCHEME", "http"); + conf.http_host = environment.get("HTTP_HOST", "localhost"); + // conf.server_name = environment.get("SERVER_NAME", "localhost"); + conf.doc_root = environment.get("DOCUMENT_ROOT", "/var/www/html"); + conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", "/usr/lib/cgi-bin/"); + // conf.cgi_script = environment.get("SCRIPT_NAME", "/cgi-bin/spine-search"); + conf.query_string = environment.get("QUERY_STRING", ""); + conf.http_url = environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string); + conf.db_path = "/var/www/html/sqlite/"; // conf.http_host ~ "/sqlite/"; + conf.request_method = environment.get("REQUEST_METHOD", "POST"); + struct CGI_val { + string db_selected = ""; + string sql_match_limit = ""; // radio: ( 1000 | 2500 ) + string sql_match_offset = ""; + string search_text = ""; + string results_type = ""; // index + bool checked_echo = false; + bool checked_stats = false; + bool checked_url = false; + bool checked_searched = false; + bool checked_tip = false; + bool checked_sql = false; + } + auto cv = CGI_val(); + cv.db_selected = "spine.search.db"; // config, set db name + auto text_fields() { + string canned_query_str = environment.get("QUERY_STRING", ""); + if ("query_string" in cgi.post) { + canned_query_str = environment.get("QUERY_STRING", ""); + } + string[string] canned_query; + if (conf.request_method == "POST") { + } else if (conf.request_method == "GET") { + foreach (pair_str; canned_query_str.split("&")) { + // cgi.write(pair_str ~ "
"); + string[] pair = pair_str.split("="); + canned_query[pair[0]] = pair[1]; + } + // foreach (field, content; canned_query) { + // cgi.write(field ~ ": " ~ content ~ "
"); + // } + } + static struct Rgx { + // static canned_query = ctRegex!(`\A(?P.+)\Z`, "m"); + static search_text_area = ctRegex!(`\A(?P.+)\Z`, "m"); + // static fulltext = ctRegex!(`\A(?P.+)\Z`, "m"); + static line = ctRegex!(`^(?P.+?)(?: ~|$)`, "m"); + static text = ctRegex!(`(?:^|\s~\s*)text:\s+(?P.+?)(?: ~|$)`, "m"); + static author = ctRegex!(`(?:^|\s~\s*)author:\s+(?P.+)$`, "m"); + static title = ctRegex!(`(?:^|\s~\s*)title:\s+(?P.+)$`, "m"); + static uid = ctRegex!(`(?:^|\s~\s*)uid:\s+(?P.+)$`, "m"); + static fn = ctRegex!(`(?:^|\s~\s*)fn:\s+(?P.+)$`, "m"); + static keywords = ctRegex!(`(?:^|\s~\s*)keywords:\s+(?P.+)$`, "m"); + static topic_register = ctRegex!(`(?:^|\s~\s*)topic_register:\s+(?P.+)$`, "m"); + static subject = ctRegex!(`(?:^|\s~\s*)subject:\s+(?P.+)$`, "m"); + static description = ctRegex!(`(?:^|\s~\s*)description:\s+(?P.+)$`, "m"); + static publisher = ctRegex!(`(?:^|\s~\s*)publisher:\s+(?P.+)$`, "m"); + static editor = ctRegex!(`(?:^|\s~\s*)editor:\s+(?P.+)$`, "m"); + static contributor = ctRegex!(`(?:^|\s~\s*)contributor:\s+(?P.+)$`, "m"); + 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"); + static coverage = ctRegex!(`(?:^|\s~\s*)coverage:\s+(?P.+)$`, "m"); + static rights = ctRegex!(`(?:^|\s~\s*)rights:\s+(?P.+)$`, "m"); + static comment = ctRegex!(`(?:^|\s~\s*)comment:\s+(?P.+)$`, "m"); + // static abstract_ = ctRegex!(`(?:^|\s~\s*)abstract:\s+(?P.+)$`, "m"); + static src_filename_base = ctRegex!(`^src_filename_base:\s+(?P.+)$`, "m"); + } + struct searchFields { + string canned_query = ""; // GET canned_query == cq + string search_text_area = ""; // POST search_text_area == tsa + string text = ""; // text == txt + string author = ""; // author == au + string title = ""; // title == ti + string uid = ""; // uid == uid + string fn = ""; // fn == fn + string keywords = ""; // keywords == kw + string topic_register = ""; // topic_register == tr + string subject = ""; // subject == su + string description = ""; // description == de + string publisher = ""; // publisher == pb + string editor = ""; // editor == ed + 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 + string coverage = ""; // coverage == cv + string rights = ""; // rights == rgt + string comment = ""; // comment == cmt + // string abstract = ""; + string src_filename_base = ""; // src_filename_base == bfn + string results_type = ""; // results_type == rt radio + string sql_match_limit = ""; // sql_match_limit == sml radio + string sql_match_offset = ""; // sql_match_offset == smo + string stats = ""; // stats == sts checked + string echo = ""; // echo == ec checked + string url = ""; // url == url checked + string searched = ""; // searched == se checked + string sql = ""; // sql == sql checked + } + auto rgx = Rgx(); + auto got = searchFields(); + if (environment.get("REQUEST_METHOD", "POST") == "POST") { + if ("sf" in cgi.post) { + got.search_text_area = cgi.post["sf"]; + if (auto m = got.search_text_area.matchFirst(rgx.text)) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } else if (auto m = got.search_text_area.matchFirst(rgx.line)) { + if ( + !(m["matched"].matchFirst(rgx.author)) + && !(m["matched"].matchFirst(rgx.title)) + ) { + got.text = m["matched"]; + got.canned_query ~= "sf=" ~ m["matched"]; + } + } + if (auto m = got.search_text_area.matchFirst(rgx.author)) { + got.author = m["matched"]; + got.canned_query ~= "&au=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.title)) { + got.title = m["matched"]; + got.canned_query ~= "&ti=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.uid)) { + got.uid = m["matched"]; + got.canned_query ~= "&uid=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.fn)) { + got.fn = m["matched"]; + got.canned_query ~= "&fn=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.keywords)) { + got.keywords = m["matched"]; + got.canned_query ~= "&kw=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.topic_register)) { + got.topic_register = m["matched"]; + got.canned_query ~= "&tr=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.subject)) { + got.subject = m["matched"]; + got.canned_query ~= "&su=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.description)) { + got.description = m["matched"]; + got.canned_query ~= "&de=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.publisher)) { + got.publisher = m["matched"]; + got.canned_query ~= "&pb=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.editor)) { + got.editor = m["matched"]; + got.canned_query ~= "&ed=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.contributor)) { + got.contributor = m["matched"]; + got.canned_query ~= "&ct=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.date)) { + got.date = m["matched"]; + got.canned_query ~= "&dt=" ~ m["matched"]; + } + // if (auto m = got.search_text_area.matchFirst(rgx.results_type)) { + // got.results_type = m["matched"]; + // got.canned_query ~= "&rt=" ~ m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.format)) { + 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"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.language)) { + got.language = m["matched"]; + got.canned_query ~= "&lng=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.relation)) { + got.relation = m["matched"]; + got.canned_query ~= "&rl=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.coverage)) { + got.coverage = m["matched"]; + got.canned_query ~= "&cv=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.rights)) { + got.rights = m["matched"]; + got.canned_query ~= "&rgt=" ~ m["matched"]; + } + if (auto m = got.search_text_area.matchFirst(rgx.comment)) { + got.comment = m["matched"]; + got.canned_query ~= "&cmt=" ~ m["matched"]; + } + // if (auto m = search_text_area.matchFirst(rgx.abstract)) { + // got.abstract = m["matched"]; + // } + if (auto m = got.search_text_area.matchFirst(rgx.src_filename_base)) { + got.src_filename_base = m["matched"]; + got.canned_query ~= "&bfn=" ~ m["matched"]; + } + } + if ("fn" in cgi.post) { + got.fn = cgi.post["fn"]; + got.canned_query ~= "&fn=" ~ cgi.post["fn"]; + } + if ("rt" in cgi.post) { + got.results_type = cgi.post["rt"]; + got.canned_query ~= "&rt=" ~ cgi.post["rt"]; + } + if ("sts" in cgi.post) { + got.stats = cgi.post["sts"]; + got.canned_query ~= "&sts=" ~ cgi.post["sts"]; + } + if ("ec" in cgi.post) { + got.echo = cgi.post["ec"]; + got.canned_query ~= "&ec=" ~ cgi.post["ec"]; + } + if ("url" in cgi.post) { + got.url = cgi.post["url"]; + got.canned_query ~= "&url=" ~ cgi.post["url"]; + } + if ("se" in cgi.post) { + got.searched = cgi.post["se"]; + got.canned_query ~= "&se=" ~ cgi.post["se"]; + } + if ("sql" in cgi.post) { + got.sql = cgi.post["sql"]; + got.canned_query ~= "&sql=" ~ cgi.post["sql"]; + } + if ("sml" in cgi.post) { + got.sql_match_limit = cgi.post["sml"]; + got.canned_query ~= "&sml=" ~ cgi.post["sml"]; + } + if ("smo" in cgi.post) { + got.sql_match_offset = "0"; // cgi.post["smo"]; + got.canned_query ~= "&smo=0"; // ~ cgi.post["smo"]; + } + got.canned_query = got.canned_query.strip.split(" ").join("%20"); + conf.query_string = got.canned_query; + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); + } else if (environment.get("REQUEST_METHOD", "POST") == "GET") { + got.canned_query = environment.get("QUERY_STRING", ""); + // cgi.write("f.canned_query: " ~ got.canned_query ~ "
"); + got.search_text_area = ""; + if ("sf" in canned_query && !(canned_query["sf"]).empty) { + got.text = canned_query["sf"].split("%20").join(" "); + got.search_text_area ~= "text: " ~ got.text ~ "\n"; + } + if ("au" in canned_query && !(canned_query["au"]).empty) { + got.author = canned_query["au"].split("%20").join(" "); + got.search_text_area ~= "author: " ~ got.author ~ "\n"; + } + if ("ti" in canned_query && !(canned_query["ti"]).empty) { + got.title = canned_query["ti"].split("%20").join(" "); + got.search_text_area ~= "title: " ~ got.title ~ "\n"; + } + if ("uid" in canned_query && !(canned_query["uid"]).empty) { + got.uid = canned_query["uid"].split("%20").join(" "); + got.search_text_area ~= "uid: " ~ got.uid ~ "\n"; + } + if ("fn" in canned_query && !(canned_query["fn"]).empty) { + got.fn = canned_query["fn"].split("%20").join(" "); + got.search_text_area ~= "fn: " ~ got.fn ~ "\n"; + } + if ("kw" in canned_query && !(canned_query["kw"]).empty) { + got.keywords = canned_query["kw"].split("%20").join(" "); + got.search_text_area ~= "keywords: " ~ got.keywords ~ "\n"; + } + if ("tr" in canned_query && !(canned_query["tr"]).empty) { + got.topic_register = canned_query["tr"].split("%20").join(" "); + got.search_text_area ~= "topic_register: " ~ got.topic_register ~ "\n"; + } + if ("su" in canned_query && !(canned_query["su"]).empty) { + got.subject = canned_query["su"].split("%20").join(" "); + got.search_text_area ~= "subject: " ~ got.subject ~ "\n"; + } + if ("de" in canned_query && !(canned_query["de"]).empty) { + got.description = canned_query["de"].split("%20").join(" "); + got.search_text_area ~= "description: " ~ got.description ~ "\n"; + } + if ("pb" in canned_query && !(canned_query["pb"]).empty) { + got.publisher = canned_query["pb"].split("%20").join(" "); + got.search_text_area ~= "publisher: " ~ got.publisher ~ "\n"; + } + if ("ed" in canned_query && !(canned_query["ed"]).empty) { + got.editor = canned_query["ed"].split("%20").join(" "); + got.search_text_area ~= "editor: " ~ got.editor ~ "\n"; + } + if ("ct" in canned_query && !(canned_query["ct"]).empty) { + got.contributor = canned_query["ct"].split("%20").join(" "); + got.search_text_area ~= "contributor: " ~ got.contributor ~ "\n"; + } + if ("dt" in canned_query && !(canned_query["dt"]).empty) { + got.date = canned_query["dt"].split("%20").join(" "); + got.search_text_area ~= "date: " ~ got.date ~ "\n"; + } + if ("rt" in canned_query && !(canned_query["rt"]).empty) { + got.results_type = canned_query["rt"].split("%20").join(" "); + // got.search_text_area ~= "results_type: " ~ got.results_type ~ "\n"; + } + if ("fmt" in canned_query && !(canned_query["fmt"]).empty) { + 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"; + } + if ("lng" in canned_query && !(canned_query["lng"]).empty) { + got.language = canned_query["lng"].split("%20").join(" "); + got.search_text_area ~= "language: " ~ got.language ~ "\n"; + } + if ("rl" in canned_query && !(canned_query["rl"]).empty) { + got.relation = canned_query["rl"].split("%20").join(" "); + got.search_text_area ~= "relation: " ~ got.relation ~ "\n"; + } + if ("cv" in canned_query && !(canned_query["cv"]).empty) { + got.coverage = canned_query["cv"].split("%20").join(" "); + got.search_text_area ~= "coverage: " ~ got.coverage ~ "\n"; + } + if ("rgt" in canned_query && !(canned_query["rgt"]).empty) { + got.rights = canned_query["rgt"].split("%20").join(" "); + got.search_text_area ~= "rights: " ~ got.rights ~ "\n"; + } + if ("cmt" in canned_query && !(canned_query["cmt"]).empty) { + got.comment = canned_query["cmt"].split("%20").join(" "); + got.search_text_area ~= "comment: " ~ got.comment ~ "\n"; + } + // if ("abstract" in canned_query && !(canned_query["abstract"]).empty) { + // got.abstract = canned_query["abstract"]; + // } + if ("bfn" in canned_query && !(canned_query["bfn"]).empty) { // search_field + got.src_filename_base = canned_query["bfn"].split("%20").join(" "); + got.search_text_area ~= "src_filename_base: " ~ got.src_filename_base ~ "\n"; + } + if ("sml" in canned_query && !(canned_query["sml"]).empty) { + got.sql_match_limit = canned_query["sml"].split("%20").join(" "); + // got.search_text_area ~= "sql_match_limit: " ~ got.sql_match_limit ~ "\n"; + } + // cgi.write("f.search_text_area: " ~ got.search_text_area ~ "
"); + } + return got; + } + auto tf = text_fields; // + struct SQL_select { + string the_body = ""; + string the_range = ""; + } + auto sql_select = SQL_select(); + 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(); + string _previous_next = ""; + int _current_offset_value = 0; + string _set_offset_next = ""; + string _set_offset_previous = ""; + string _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; + _url_next = _url.replace(rgx.track_offset, _set_offset_next); + if (_current_offset_value < cv.sql_match_limit.to!int) { + _url_previous = ""; + } else { + _url_previous = ""; + _set_offset_previous = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int - cv.sql_match_limit.to!int).to!string; + _url_previous = _url.replace(rgx.track_offset, _set_offset_previous); + } + } else {// _current_offset_value = 0; + _url_next = _url ~= "&smo=" ~ cv.sql_match_limit.to!string; + } + if (_url_previous.empty) { + arrow_previous = ""; + } else { + arrow_previous = + "" + ~ "" + ~ "<< prev" + ~ " || "; + } + arrow_next = + "" + ~ "" + ~ "next >>" + ~ ""; + _previous_next = "
" ~ arrow_previous ~ arrow_next; + return _previous_next; + } + { + header = format(q"┃ + + + + + + SiSU spine search form (sample) + + + + + + + +┃", + conf.http_host, + ); + } + { + table = format(q"┃ + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+ ┃"); + } + { + string post_value(string field_name, string type="box", string set="on") { + string val = ""; + switch (type) { + case "field": + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? cgi.post[field_name] + : (field_name in cgi.get) + ? cgi.get[field_name] + : ""); + val = tf.search_text_area; + break; + case "box": // generic for checkbox or radio; checkbox set == "on" radio set == "name set" + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "off"); + break; + case "radio": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + case "checkbox": // used generic bo + val = ((field_name in cgi.post && !(cgi.post[field_name]).empty) + ? (cgi.post[field_name] == set ? "checked" : "off") + : (field_name in cgi.get) + ? (cgi.get[field_name] == set ? "checked" : "off") + : "checked"); + break; + default: + } + return val; + } + string the_can(string fv) { + string show_the_can = post_value("url"); + string _the_can = ""; + if (show_the_can == "checked") { + tf = text_fields; + string method_get_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ environment.get("QUERY_STRING", ""); + string method_post_url_construct = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ tf.canned_query; + // assert(method_get_url == environment.get("HTTP_REFERER", conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?" ~ conf.query_string)); + if (conf.request_method == "POST") { + _the_can = + "" + ~ "POST: " + ~ "" + ~ method_post_url_construct + ~ "" + ~ "
"; + } else if (conf.request_method == "GET") { + _the_can = + "" + ~ "GET:  " + ~ "" + ~ method_get_url + ~ ""; + } + conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ tf.canned_query; + } + return _the_can; + } + string provide_tip() { + string searched_tip = post_value("se"); + string tip = ""; + if (searched_tip == "checked") { + string search_field = post_value("sf", "field"); + tf = text_fields; + tip = format(q"┃ + +database: %s; selected view: index +search string: %s %s %s %s %s %s
+%s %s %s %s %s %s +
+┃", + cv.db_selected, + (tf.text.empty ? "" : "\"text: " ~ tf.text ~ "; "), + (tf.title.empty ? "" : "\"title: " ~ tf.title ~ "; "), + (tf.author.empty ? "" : "\"author: " ~ tf.author ~ "; "), + (tf.date.empty ? "" : "\"date " ~ tf.date ~ "; "), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + (tf.text.empty ? "" : "text: " ~ tf.text ~ "
"), + (tf.title.empty ? "" : "title: " ~ tf.title ~ "
"), + (tf.author.empty ? "" : "author: " ~ tf.author ~ "
"), + (tf.date.empty ? "" : "date: " ~ tf.date ~ "
"), + (tf.uid.empty ? "" : "\"uid: " ~ tf.uid ~ "; "), + (tf.fn.empty ? "" : "\"fn: " ~ tf.fn ~ "; "), + ); + } + return tip; + } + form = format(q"┃ +
+ + +
+ + + %s + %s + %s +
+ + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep; + match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement + +
+
+ + +
+┃", + "spine-search", + (post_value("ec") == "checked") ? post_value("sf", "field") : "", + provide_tip, + search_note, + the_can(post_value("sf", "field")), + cv.db_selected, + cv.db_selected, + post_value("rt", "box", "idx"), + post_value("rt", "box", "txt"), + post_value("sml", "box", "1000"), + post_value("sml", "box", "2500"), + post_value("ec"), + post_value("sts"), + post_value("url"), + post_value("se"), + post_value("tip"), + post_value("sql"), + ); + { + string set_value(string field_name, string default_val) { + string val; + if (field_name in cgi.post) { + val = cgi.post[field_name]; + } else if (field_name in cgi.get) { + val = cgi.get[field_name]; + } else { val = default_val; } + return val; + } + bool set_bool(string field_name) { + bool val; + if (field_name in cgi.post + && cgi.post[field_name] == "on") { + val = true; + } else if (field_name in cgi.get + && cgi.get[field_name] == "on") { + val = true; + } else { val = false; } + return val; + } + cv.db_selected = set_value("selected_db", "spine.search.db"); // selected_db == db + cv.sql_match_limit = set_value("sml", "1000"); + cv.sql_match_offset = set_value("smo", "0"); + cv.search_text = set_value("sf", "test"); // remove test + cv.results_type = set_value("rt", "idx"); + cv.checked_echo = set_bool("ec"); + cv.checked_stats = set_bool("sts"); + cv.checked_url = set_bool("url"); + cv.checked_searched = set_bool("se"); + cv.checked_tip = set_bool("tip"); + cv.checked_sql = set_bool("sql"); + tf = text_fields; + } + } + { + cgi.write(header); + cgi.write(table); + cgi.write(form); + // cgi.write(previous_next); + { // debug environment + // foreach (k, d; environment.toAA) { + // cgi.write(k ~ ": " ~ d ~ "
"); + // } + } + { // debug cgi info + // cgi.write("db_selected: " ~ cv.db_selected ~ "
\n"); + // cgi.write("search_text: " ~ cv.search_text ~ "
\n"); + // cgi.write("sql_match_limit: " ~ cv.sql_match_limit ~ ";\n"); + // cgi.write("sql_match_offset: " ~ cv.sql_match_offset ~ ";\n"); + // cgi.write("results_type: " ~ cv.results_type ~ "
\n"); + // cgi.write("cv.checked_echo: " ~ (cv.checked_echo ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_stats: " ~ (cv.checked_stats ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_url: " ~ (cv.checked_url ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_searched: " ~ (cv.checked_searched ? "checked" : "off") ~ ";
\n"); + // cgi.write("cv.checked_tip: " ~ (cv.checked_tip ? "checked" : "off") ~ "; \n"); + // cgi.write("cv.checked_sql: " ~ (cv.checked_sql ? "checked" : "off") ~ "
\n"); + } + } + auto db = Database(conf.db_path ~ cv.db_selected); + { + uint sql_match_offset_counter(T)(T cv) { + sql_match_offset_count += cv.sql_match_limit.to!uint; + return sql_match_offset_count; + } + void sql_search_query() { + string select_field_like(string db_field, string search_field) { + string where_ = ""; + if (!(search_field.empty)) { + string _sf = search_field.strip.split("%20").join(" "); + if (_sf.match(r" OR ")) { + _sf = _sf.split(" OR ").join("%' OR " ~ db_field ~ " LIKE '%"); + } + if (_sf.match(r" AND ")) { + _sf = _sf.split(" AND ").join("%' AND " ~ db_field ~ " LIKE '%"); + } + _sf = "( " ~ db_field ~ " LIKE\n '%" ~ _sf ~ "%' )"; + where_ ~= format(q"┃ + %s +┃", + _sf + ); + } + return where_; + } + string[] _fields; + _fields ~= select_field_like("doc_objects.clean", tf.text); + _fields ~= select_field_like("metadata_and_text.title", tf.title); + _fields ~= select_field_like("metadata_and_text.creator_author", tf.author); + _fields ~= select_field_like("metadata_and_text.uid", tf.uid); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.fn); + _fields ~= select_field_like("metadata_and_text.src_filename_base", tf.src_filename_base); + _fields ~= select_field_like("metadata_and_text.language_document_char", tf.language); + _fields ~= select_field_like("metadata_and_text.date_published", tf.date); + _fields ~= select_field_like("metadata_and_text.classify_keywords", tf.keywords); + _fields ~= select_field_like("metadata_and_text.classify_topic_register", tf.topic_register); + string[] fields; + foreach (f; _fields) { + if (!(f.empty)) { fields ~= f; } + } + string fields_str = ""; + fields_str ~= fields.join(" AND "); + sql_select.the_body ~= format(q"┃ +SELECT + metadata_and_text.uid, + metadata_and_text.title, + metadata_and_text.creator_author_last_first, + metadata_and_text.creator_author, + metadata_and_text.src_filename_base, + metadata_and_text.language_document_char, + metadata_and_text.date_published, + metadata_and_text.classify_keywords, + metadata_and_text.classify_topic_register, + doc_objects.body, + doc_objects.seg_name, + doc_objects.ocn, + metadata_and_text.uid +FROM + doc_objects, + metadata_and_text +WHERE ( + %s + ) +AND + doc_objects.uid_metadata_and_text = metadata_and_text.uid +ORDER BY + metadata_and_text.creator_author_last_first, + metadata_and_text.date_published DESC, + metadata_and_text.title, + metadata_and_text.language_document_char, + metadata_and_text.src_filename_base, + doc_objects.ocn +LIMIT %s OFFSET %s +;┃", + fields_str, + cv.sql_match_limit, + cv.sql_match_offset, + ); + (cv.checked_sql) + ? cgi.write(previous_next ~ "
" ~ sql_select.the_body.split("\n ").join(" ").split("\n").join("
") ~ "
\n") + : ""; + cgi.write(previous_next); + auto select_query_results = db.execute(sql_select.the_body).cached; + string _old_uid = ""; + if (!select_query_results.empty) { + foreach (row; select_query_results) { + if (row["uid"].as!string != _old_uid) { + _old_uid = row["uid"].as!string; + auto m = (row["date_published"].as!string).match(regex(r"^([0-9]{4})")); // breaks if row missing or no match? + cgi.write( + "
\"" + ~ row["title"].as!string ~ "\"" + ~ " (" + ~ m.hit + ~ ") " + ~ "[" + ~ row["language_document_char"].as!string + ~ "] " + ~ row["creator_author_last_first"].as!string + ~ ":
\n" + ); + } + if (cv.results_type == "txt") { + cgi.write( + "
" + ~ row["ocn"].as!string + ~ "" + ~ "
" + ~ row["body"].as!string + ); + } else { + cgi.write( + "" + ~ row["ocn"].as!string + ~ ", " + ); + } + } + cgi.write( previous_next); + } else { // offset_not_beyond_limit = false; + cgi.write("select_query_results empty

\n"); + } + } + sql_search_query; + } + { + db.close; + } + { + string tail = format(q"┃ + +┃"); + cgi.write(tail); + } +} +mixin GenericMain!cgi_function_intro; diff --git a/util/dr_tex.rb b/util/dr_tex.rb deleted file mode 100755 index 767742c..0000000 --- a/util/dr_tex.rb +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env ruby -require 'fileutils' -pwd = Dir.pwd -argv,texfiles_with_path,flags=[],[],[] -lngs = %{(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)} -Regexp.new(lngs, Regexp::IGNORECASE) -argv=$* -argv.sort.each{|y| (y =~/^--\S+$/i) ? (flags << y) : (texfiles_with_path << y) } -if flags.length==0 \ -|| flags.inspect =~/"--help"/ - cmd=(/([^\/]+)$/).match($0)[1] - puts < 0 - texfiles_with_path.each do |texfile_with_path| - if texfile_with_path =~/.+\.tex/ - #puts texfile_with_path - if FileTest.file?(texfile_with_path) - file_basename_with_path = texfile_with_path.sub(/\.tex$/,'') - file_basename = file_basename_with_path.sub(/.*?([^\/]+)$/,'\1') - _out_path = out_path - if file_basename =~ /\.#{lngs}$/ - lng = file_basename.match(/\.#{lngs}$/)[1] - puts file_basename - puts lng - puts _out_path - unless _out_path.match(/\/#{lng}\/pdf$/) - _out_path = "#{out_path}/#{lng}/pdf" - FileUtils::mkdir_p(_out_path) - end - end - texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex #{texfile_with_path}\n} - puts texpdf_cmd - 2.times { |i| system(texpdf_cmd) } - if (FileTest.file?(%{#{pwd}/#{file_basename}.pdf})) && (FileTest.directory?(_out_path)) - FileUtils::Verbose::mv(%{#{pwd}/#{file_basename}.pdf}, %{#{_out_path}/#{file_basename}.pdf}) - puts (%{#{_out_path}/#{file_basename}.pdf}) - else - puts "issue with pdf file or output directory" - puts "pdf file: #{pwd}/#{file_basename}.pdf}" - puts "output dir: #{_out_path}/" - end - suffix = ['log', 'out', 'toc', 'aux'] - suffix.each { |s| FileUtils::rm_f(%{#{pwd}/#{file_basename}.#{s}})} - end - end - end -end -Dir.chdir(pwd) -__END__ diff --git a/util/rb/cgi/search.cgi b/util/rb/cgi/search.cgi new file mode 100755 index 0000000..0fe8ea5 --- /dev/null +++ b/util/rb/cgi/search.cgi @@ -0,0 +1,937 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (sqlite) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2014, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end + begin + require 'cgi' + require 'fcgi' + require 'sqlite3' + rescue LoadError + puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)' + end + @stub_default='manual' + @image_src="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" + @hosturl_cgi="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" + @hosturl_files="http://#{ENV['HTTP_HOST']}" + @output_dir_structure_by='filetype' + @lingual='multi' + @db_name_prefix='SiSU.7a.' + @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP + @@offset=0 + @@canned_search_url=@base + @color_heading='#DDFFAA' + @color_match='#ffff48' + class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note='' if checked_searched !~/\S/ + the_can='' if checked_url !~/\S/ + search_field='' if checked_echo !~/\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip=if checked_tip =~/\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__;
' + else '' + end + end + def submission_form + search_form=<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+

+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end + end + class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:filename + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1=text_to_match('text:') + @fulltext=text_to_match('fulltxt:') + @topic_register=text_to_match('topic_register:') + @title=text_to_match('title:') # DublinCore 1 - title + @author=text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject=text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description=text_to_match('description:') # DublinCore 4 - description + @publisher=text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor=text_to_match('editor:') + @contributor=text_to_match('contributor:') # DublinCore 6 - contributor + @date=text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type=text_to_match('type:') # DublinCore 8 - type + @format=text_to_match('format:') # DublinCore 9 - format + @identifier=text_to_match('identifier:') # DublinCore 10 - identifier + @source=text_to_match('source:') # DublinCore 11 - source + @language=text_to_match('language:') # DublinCore 12 - language + @relation=text_to_match('relation:') # DublinCore 13 - relation + @coverage=text_to_match('coverage:') # DublinCore 14 - coverage + @rights=text_to_match('rights:') # DublinCore 15 - rights + @keywords=text_to_match('key(?:words?)?:') + @comment=text_to_match('comment:') + @abstract=text_to_match('abs(?:tract)?:') + @owner=text_to_match('owner:') + @date_created=text_to_match('date_created:') + @date_issued=text_to_match('date_issued:') + @date_modified=text_to_match('date_modified:') + @date_available=text_to_match('date_available:') + @date_valid=text_to_match('date_valid:') + @filename=text_to_match('filename:') + @text1=text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1=q['s1'] if q['s1']=~/\S/ + @fulltext=q['ft'] if q['ft']=~/\S/ + @keywords=q['key'] if q['key']=~/\S/ + @title=q['ti'] if q['ti']=~/\S/ + @author=q['au'] if q['au']=~/\S/ + @topic_register=q['tr'] if q['tr']=~/\S/ + @subject=q['sj'] if q['sj']=~/\S/ + @description=q['dsc'] if q['dsc']=~/\S/ + @publisher=q['pb'] if q['pb']=~/\S/ + @editor=q['cntr'] if q['cntr']=~/\S/ + @contributor=q['cntr'] if q['cntr']=~/\S/ + @date=q['dt'] if q['dt']=~/\S/ + @type=q['ty'] if q['ty']=~/\S/ + @identifier=q['id'] if q['id']=~/\S/ + @source=q['src'] if q['src']=~/\S/ + @language=q['lang'] if q['lang']=~/\S/ + @relation=q['rel'] if q['rel']=~/\S/ + @coverage=q['cov'] if q['cov']=~/\S/ + @rights=q['cr'] if q['cr']=~/\S/ + @comment=q['co'] if q['co']=~/\S/ + @abstract=q['ab'] if q['ab']=~/\S/ + @date_created=q['dtc'] if q['dtc']=~/\S/ + @date_issued=q['dti'] if q['dti']=~/\S/ + @date_modified=q['dtm'] if q['dtm']=~/\S/ + @date_available=q['dta'] if q['dta']=~/\S/ + @date_valid=q['dtv'] if q['dtv']=~/\S/ + @filename=if q['doc'] and q['search'] !~/search db/ then q['doc'] + elsif q['fns']=~/\S/ then q['fns'] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end + end + class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q=l,t,q + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=unescaped_search.gsub(/\s*(AND|OR)\s*/,"%' \) \\1 #{@l} LIKE \( '%"). + gsub(/(.+)/,"#{@l} LIKE \( '%\\1%' \)") + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end + end + class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.src_filename',search_for.filename,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||=@@limit + offset ||=@@offset + @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE #{@search_text} AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn} + @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;} + select=@sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.execute(sql_select_body) + end + end + def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 6.3.1 2014-10-19 (2014w41/7) +
+ + SiSU © Ralph Amissah + 1993, current 2014. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2014. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK + end + @tail=tail + @counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 + @counters_txt,@counters_endn,@sql_select_body='','','' + FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo='checked' if cgi['echo'] =~/\S/ + checked_stats='checked' if cgi['stats'] =~/\S/ + checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched='checked' if cgi['searched'] =~/\S/ + checked_tip='checked' if cgi['tip'] =~/\S/ + checked_case='checked' if cgi['casesense'] =~/\S/ + checked_sql='checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all='checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none='' + elsif cgi['checks'] =~/check_none/ + checked_none='checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~/check_selected/ + checked_selected='checked' + elsif cgi['checks'] =~/check_default/ + checked_default='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=case cgi['db'] + when /SiSU.7a.manual/ then '' + end + db_name='sisu_sqlite.db' + db_sqlite=case cgi['db'] + when /SiSU.7a.manual/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + else "/srv/complete.sisudoc.org/web/manual/#{db_name}" + end + @conn=SQLite3::Database.new(db_sqlite) + @conn.results_as_hash=true + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/ + ft='&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext=~/\S/ + key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/ + ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/ + au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/ + tr='&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register=~/\S/ + sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/ + dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/ + pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/ + edt='&edt=' + CGI.escape(@search_for.editor) if @search_for.editor=~/\S/ + cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/ + dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/ + ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/ + id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/ + src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/ + lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/ + rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/ + cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/ + cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/ + co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/ + ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/ + dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/ + dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/ + dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/ + dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ + dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ + fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'filename: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename=%{filename: #{green}#{@search_for.filename}

} if @search_for.filename =~/\S+/ + p_text=%{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~/\S+/ + p_fulltext=%{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~/\S+/ + p_title=%{title: #{green}#{@search_for.title}
} if @search_for.title =~/\S+/ + p_author=%{author: #{green}#{@search_for.author}
} if @search_for.author =~/\S+/ + p_editor=%{editor: #{green}#{@search_for.editor}
} if @search_for.editor=~/\S+/ + p_contributor=%{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~/\S+/ + p_date=%{date: #{green}#{@search_for.date}
} if @search_for.date =~/\S+/ + p_rights=%{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~/\S+/ + p_topic_register=%{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~/\S+/ + p_subject=%{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~/\S+/ + p_keywords=%{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~/\S+/ + p_identifier=%{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~/\S+/ + p_type=%{type: #{green}#{@search_for.type}
} if @search_for.type =~/\S+/ + p_format=%{format: #{green}#{@search_for.format}
} if @search_for.format =~/\S+/ + p_relation=%{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~/\S+/ + p_coverage=%{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~/\S+/ + p_description=%{description: #{green}#{@search_for.description}
} if @search_for.description =~/\S+/ + p_abstract=%{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~/\S+/ + p_comment=%{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~/\S+/ + p_publisher=%{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~/\S+/ + p_source=%{source: #{green}#{@search_for.source}
} if @search_for.source =~/\S+/ + p_language=%{language: #{green}#{@search_for.language}
} if @search_for.language =~/\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + oldtid=0 + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + #@body_main << '



Main Text:
' << sql_select_body + else + end + @hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg}.html" + : "#{path_html_seg(fn,ln)}/#{seg}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['tid'].to_i != oldtid.to_i + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + oldtid=c['tid'].to_i + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=[] + build=unescaped_search.scan(/\S+/).each do |g| + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') + : (search_regex << %{#{g.to_s}}) + end + search_regex=search_regex.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + oldtid = 0 + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header.force_encoding("UTF-8") + @counters_txt.force_encoding("UTF-8") + @counters_endn.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @body_main.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @tail.force_encoding("UTF-8")} #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+          s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end + end diff --git a/util/rb/cgi/search_ref.cgi b/util/rb/cgi/search_ref.cgi new file mode 100755 index 0000000..0fe8ea5 --- /dev/null +++ b/util/rb/cgi/search_ref.cgi @@ -0,0 +1,937 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (sqlite) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2014, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end + begin + require 'cgi' + require 'fcgi' + require 'sqlite3' + rescue LoadError + puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)' + end + @stub_default='manual' + @image_src="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" + @hosturl_cgi="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" + @hosturl_files="http://#{ENV['HTTP_HOST']}" + @output_dir_structure_by='filetype' + @lingual='multi' + @db_name_prefix='SiSU.7a.' + @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP + @@offset=0 + @@canned_search_url=@base + @color_heading='#DDFFAA' + @color_match='#ffff48' + class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note='' if checked_searched !~/\S/ + the_can='' if checked_url !~/\S/ + search_field='' if checked_echo !~/\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip=if checked_tip =~/\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__;
' + else '' + end + end + def submission_form + search_form=<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+
+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end + end + class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:filename + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1=text_to_match('text:') + @fulltext=text_to_match('fulltxt:') + @topic_register=text_to_match('topic_register:') + @title=text_to_match('title:') # DublinCore 1 - title + @author=text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject=text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description=text_to_match('description:') # DublinCore 4 - description + @publisher=text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor=text_to_match('editor:') + @contributor=text_to_match('contributor:') # DublinCore 6 - contributor + @date=text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type=text_to_match('type:') # DublinCore 8 - type + @format=text_to_match('format:') # DublinCore 9 - format + @identifier=text_to_match('identifier:') # DublinCore 10 - identifier + @source=text_to_match('source:') # DublinCore 11 - source + @language=text_to_match('language:') # DublinCore 12 - language + @relation=text_to_match('relation:') # DublinCore 13 - relation + @coverage=text_to_match('coverage:') # DublinCore 14 - coverage + @rights=text_to_match('rights:') # DublinCore 15 - rights + @keywords=text_to_match('key(?:words?)?:') + @comment=text_to_match('comment:') + @abstract=text_to_match('abs(?:tract)?:') + @owner=text_to_match('owner:') + @date_created=text_to_match('date_created:') + @date_issued=text_to_match('date_issued:') + @date_modified=text_to_match('date_modified:') + @date_available=text_to_match('date_available:') + @date_valid=text_to_match('date_valid:') + @filename=text_to_match('filename:') + @text1=text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1=q['s1'] if q['s1']=~/\S/ + @fulltext=q['ft'] if q['ft']=~/\S/ + @keywords=q['key'] if q['key']=~/\S/ + @title=q['ti'] if q['ti']=~/\S/ + @author=q['au'] if q['au']=~/\S/ + @topic_register=q['tr'] if q['tr']=~/\S/ + @subject=q['sj'] if q['sj']=~/\S/ + @description=q['dsc'] if q['dsc']=~/\S/ + @publisher=q['pb'] if q['pb']=~/\S/ + @editor=q['cntr'] if q['cntr']=~/\S/ + @contributor=q['cntr'] if q['cntr']=~/\S/ + @date=q['dt'] if q['dt']=~/\S/ + @type=q['ty'] if q['ty']=~/\S/ + @identifier=q['id'] if q['id']=~/\S/ + @source=q['src'] if q['src']=~/\S/ + @language=q['lang'] if q['lang']=~/\S/ + @relation=q['rel'] if q['rel']=~/\S/ + @coverage=q['cov'] if q['cov']=~/\S/ + @rights=q['cr'] if q['cr']=~/\S/ + @comment=q['co'] if q['co']=~/\S/ + @abstract=q['ab'] if q['ab']=~/\S/ + @date_created=q['dtc'] if q['dtc']=~/\S/ + @date_issued=q['dti'] if q['dti']=~/\S/ + @date_modified=q['dtm'] if q['dtm']=~/\S/ + @date_available=q['dta'] if q['dta']=~/\S/ + @date_valid=q['dtv'] if q['dtv']=~/\S/ + @filename=if q['doc'] and q['search'] !~/search db/ then q['doc'] + elsif q['fns']=~/\S/ then q['fns'] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end + end + class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q=l,t,q + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=unescaped_search.gsub(/\s*(AND|OR)\s*/,"%' \) \\1 #{@l} LIKE \( '%"). + gsub(/(.+)/,"#{@l} LIKE \( '%\\1%' \)") + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end + end + class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.src_filename',search_for.filename,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||=@@limit + offset ||=@@offset + @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE #{@search_text} AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn} + @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;} + select=@sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.execute(sql_select_body) + end + end + def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 6.3.1 2014-10-19 (2014w41/7) +
+ + SiSU © Ralph Amissah + 1993, current 2014. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2014. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK + end + @tail=tail + @counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 + @counters_txt,@counters_endn,@sql_select_body='','','' + FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo='checked' if cgi['echo'] =~/\S/ + checked_stats='checked' if cgi['stats'] =~/\S/ + checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched='checked' if cgi['searched'] =~/\S/ + checked_tip='checked' if cgi['tip'] =~/\S/ + checked_case='checked' if cgi['casesense'] =~/\S/ + checked_sql='checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all='checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none='' + elsif cgi['checks'] =~/check_none/ + checked_none='checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~/check_selected/ + checked_selected='checked' + elsif cgi['checks'] =~/check_default/ + checked_default='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=case cgi['db'] + when /SiSU.7a.manual/ then '' + end + db_name='sisu_sqlite.db' + db_sqlite=case cgi['db'] + when /SiSU.7a.manual/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + else "/srv/complete.sisudoc.org/web/manual/#{db_name}" + end + @conn=SQLite3::Database.new(db_sqlite) + @conn.results_as_hash=true + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/ + ft='&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext=~/\S/ + key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/ + ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/ + au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/ + tr='&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register=~/\S/ + sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/ + dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/ + pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/ + edt='&edt=' + CGI.escape(@search_for.editor) if @search_for.editor=~/\S/ + cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/ + dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/ + ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/ + id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/ + src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/ + lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/ + rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/ + cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/ + cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/ + co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/ + ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/ + dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/ + dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/ + dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/ + dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ + dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ + fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'filename: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename=%{filename: #{green}#{@search_for.filename}

} if @search_for.filename =~/\S+/ + p_text=%{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~/\S+/ + p_fulltext=%{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~/\S+/ + p_title=%{title: #{green}#{@search_for.title}
} if @search_for.title =~/\S+/ + p_author=%{author: #{green}#{@search_for.author}
} if @search_for.author =~/\S+/ + p_editor=%{editor: #{green}#{@search_for.editor}
} if @search_for.editor=~/\S+/ + p_contributor=%{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~/\S+/ + p_date=%{date: #{green}#{@search_for.date}
} if @search_for.date =~/\S+/ + p_rights=%{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~/\S+/ + p_topic_register=%{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~/\S+/ + p_subject=%{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~/\S+/ + p_keywords=%{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~/\S+/ + p_identifier=%{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~/\S+/ + p_type=%{type: #{green}#{@search_for.type}
} if @search_for.type =~/\S+/ + p_format=%{format: #{green}#{@search_for.format}
} if @search_for.format =~/\S+/ + p_relation=%{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~/\S+/ + p_coverage=%{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~/\S+/ + p_description=%{description: #{green}#{@search_for.description}
} if @search_for.description =~/\S+/ + p_abstract=%{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~/\S+/ + p_comment=%{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~/\S+/ + p_publisher=%{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~/\S+/ + p_source=%{source: #{green}#{@search_for.source}
} if @search_for.source =~/\S+/ + p_language=%{language: #{green}#{@search_for.language}
} if @search_for.language =~/\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + oldtid=0 + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + #@body_main << '



Main Text:
' << sql_select_body + else + end + @hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg}.html" + : "#{path_html_seg(fn,ln)}/#{seg}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['tid'].to_i != oldtid.to_i + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + oldtid=c['tid'].to_i + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=[] + build=unescaped_search.scan(/\S+/).each do |g| + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') + : (search_regex << %{#{g.to_s}}) + end + search_regex=search_regex.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + oldtid = 0 + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header.force_encoding("UTF-8") + @counters_txt.force_encoding("UTF-8") + @counters_endn.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @body_main.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @tail.force_encoding("UTF-8")} #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+          s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end + end diff --git a/util/rb/cgi/sisu_7a_sqlite.cgi b/util/rb/cgi/sisu_7a_sqlite.cgi new file mode 100755 index 0000000..0fe8ea5 --- /dev/null +++ b/util/rb/cgi/sisu_7a_sqlite.cgi @@ -0,0 +1,937 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (sqlite) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2014, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end + begin + require 'cgi' + require 'fcgi' + require 'sqlite3' + rescue LoadError + puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)' + end + @stub_default='manual' + @image_src="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" + @hosturl_cgi="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" + @hosturl_files="http://#{ENV['HTTP_HOST']}" + @output_dir_structure_by='filetype' + @lingual='multi' + @db_name_prefix='SiSU.7a.' + @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP + @@offset=0 + @@canned_search_url=@base + @color_heading='#DDFFAA' + @color_match='#ffff48' + class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note='' if checked_searched !~/\S/ + the_can='' if checked_url !~/\S/ + search_field='' if checked_echo !~/\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip=if checked_tip =~/\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__;
' + else '' + end + end + def submission_form + search_form=<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+
+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end + end + class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:filename + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1=text_to_match('text:') + @fulltext=text_to_match('fulltxt:') + @topic_register=text_to_match('topic_register:') + @title=text_to_match('title:') # DublinCore 1 - title + @author=text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject=text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description=text_to_match('description:') # DublinCore 4 - description + @publisher=text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor=text_to_match('editor:') + @contributor=text_to_match('contributor:') # DublinCore 6 - contributor + @date=text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type=text_to_match('type:') # DublinCore 8 - type + @format=text_to_match('format:') # DublinCore 9 - format + @identifier=text_to_match('identifier:') # DublinCore 10 - identifier + @source=text_to_match('source:') # DublinCore 11 - source + @language=text_to_match('language:') # DublinCore 12 - language + @relation=text_to_match('relation:') # DublinCore 13 - relation + @coverage=text_to_match('coverage:') # DublinCore 14 - coverage + @rights=text_to_match('rights:') # DublinCore 15 - rights + @keywords=text_to_match('key(?:words?)?:') + @comment=text_to_match('comment:') + @abstract=text_to_match('abs(?:tract)?:') + @owner=text_to_match('owner:') + @date_created=text_to_match('date_created:') + @date_issued=text_to_match('date_issued:') + @date_modified=text_to_match('date_modified:') + @date_available=text_to_match('date_available:') + @date_valid=text_to_match('date_valid:') + @filename=text_to_match('filename:') + @text1=text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1=q['s1'] if q['s1']=~/\S/ + @fulltext=q['ft'] if q['ft']=~/\S/ + @keywords=q['key'] if q['key']=~/\S/ + @title=q['ti'] if q['ti']=~/\S/ + @author=q['au'] if q['au']=~/\S/ + @topic_register=q['tr'] if q['tr']=~/\S/ + @subject=q['sj'] if q['sj']=~/\S/ + @description=q['dsc'] if q['dsc']=~/\S/ + @publisher=q['pb'] if q['pb']=~/\S/ + @editor=q['cntr'] if q['cntr']=~/\S/ + @contributor=q['cntr'] if q['cntr']=~/\S/ + @date=q['dt'] if q['dt']=~/\S/ + @type=q['ty'] if q['ty']=~/\S/ + @identifier=q['id'] if q['id']=~/\S/ + @source=q['src'] if q['src']=~/\S/ + @language=q['lang'] if q['lang']=~/\S/ + @relation=q['rel'] if q['rel']=~/\S/ + @coverage=q['cov'] if q['cov']=~/\S/ + @rights=q['cr'] if q['cr']=~/\S/ + @comment=q['co'] if q['co']=~/\S/ + @abstract=q['ab'] if q['ab']=~/\S/ + @date_created=q['dtc'] if q['dtc']=~/\S/ + @date_issued=q['dti'] if q['dti']=~/\S/ + @date_modified=q['dtm'] if q['dtm']=~/\S/ + @date_available=q['dta'] if q['dta']=~/\S/ + @date_valid=q['dtv'] if q['dtv']=~/\S/ + @filename=if q['doc'] and q['search'] !~/search db/ then q['doc'] + elsif q['fns']=~/\S/ then q['fns'] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end + end + class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q=l,t,q + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=unescaped_search.gsub(/\s*(AND|OR)\s*/,"%' \) \\1 #{@l} LIKE \( '%"). + gsub(/(.+)/,"#{@l} LIKE \( '%\\1%' \)") + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end + end + class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.src_filename',search_for.filename,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||=@@limit + offset ||=@@offset + @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE #{@search_text} AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn} + @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;} + select=@sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.execute(sql_select_body) + end + end + def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 6.3.1 2014-10-19 (2014w41/7) +
+ + SiSU © Ralph Amissah + 1993, current 2014. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2014. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK + end + @tail=tail + @counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 + @counters_txt,@counters_endn,@sql_select_body='','','' + FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo='checked' if cgi['echo'] =~/\S/ + checked_stats='checked' if cgi['stats'] =~/\S/ + checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched='checked' if cgi['searched'] =~/\S/ + checked_tip='checked' if cgi['tip'] =~/\S/ + checked_case='checked' if cgi['casesense'] =~/\S/ + checked_sql='checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all='checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none='' + elsif cgi['checks'] =~/check_none/ + checked_none='checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~/check_selected/ + checked_selected='checked' + elsif cgi['checks'] =~/check_default/ + checked_default='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=case cgi['db'] + when /SiSU.7a.manual/ then '' + end + db_name='sisu_sqlite.db' + db_sqlite=case cgi['db'] + when /SiSU.7a.manual/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + else "/srv/complete.sisudoc.org/web/manual/#{db_name}" + end + @conn=SQLite3::Database.new(db_sqlite) + @conn.results_as_hash=true + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/ + ft='&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext=~/\S/ + key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/ + ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/ + au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/ + tr='&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register=~/\S/ + sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/ + dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/ + pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/ + edt='&edt=' + CGI.escape(@search_for.editor) if @search_for.editor=~/\S/ + cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/ + dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/ + ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/ + id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/ + src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/ + lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/ + rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/ + cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/ + cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/ + co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/ + ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/ + dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/ + dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/ + dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/ + dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ + dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ + fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'filename: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename=%{filename: #{green}#{@search_for.filename}

} if @search_for.filename =~/\S+/ + p_text=%{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~/\S+/ + p_fulltext=%{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~/\S+/ + p_title=%{title: #{green}#{@search_for.title}
} if @search_for.title =~/\S+/ + p_author=%{author: #{green}#{@search_for.author}
} if @search_for.author =~/\S+/ + p_editor=%{editor: #{green}#{@search_for.editor}
} if @search_for.editor=~/\S+/ + p_contributor=%{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~/\S+/ + p_date=%{date: #{green}#{@search_for.date}
} if @search_for.date =~/\S+/ + p_rights=%{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~/\S+/ + p_topic_register=%{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~/\S+/ + p_subject=%{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~/\S+/ + p_keywords=%{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~/\S+/ + p_identifier=%{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~/\S+/ + p_type=%{type: #{green}#{@search_for.type}
} if @search_for.type =~/\S+/ + p_format=%{format: #{green}#{@search_for.format}
} if @search_for.format =~/\S+/ + p_relation=%{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~/\S+/ + p_coverage=%{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~/\S+/ + p_description=%{description: #{green}#{@search_for.description}
} if @search_for.description =~/\S+/ + p_abstract=%{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~/\S+/ + p_comment=%{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~/\S+/ + p_publisher=%{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~/\S+/ + p_source=%{source: #{green}#{@search_for.source}
} if @search_for.source =~/\S+/ + p_language=%{language: #{green}#{@search_for.language}
} if @search_for.language =~/\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + oldtid=0 + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + #@body_main << '



Main Text:
' << sql_select_body + else + end + @hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg}.html" + : "#{path_html_seg(fn,ln)}/#{seg}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['tid'].to_i != oldtid.to_i + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + oldtid=c['tid'].to_i + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=[] + build=unescaped_search.scan(/\S+/).each do |g| + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') + : (search_regex << %{#{g.to_s}}) + end + search_regex=search_regex.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + oldtid = 0 + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header.force_encoding("UTF-8") + @counters_txt.force_encoding("UTF-8") + @counters_endn.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @body_main.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @tail.force_encoding("UTF-8")} #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+          s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end + end diff --git a/util/rb/cgi/sisu_lng.cgi b/util/rb/cgi/sisu_lng.cgi new file mode 100755 index 0000000..5e07a16 --- /dev/null +++ b/util/rb/cgi/sisu_lng.cgi @@ -0,0 +1,935 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (pgsql) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2015, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end + begin + require 'cgi' + require 'fcgi' + require 'pg' + rescue LoadError + puts 'cgi, fcgi or pg NOT FOUND (LoadError)' + end + @stub_default='samples_by_language' + @image_src="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" + @hosturl_cgi="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" + @hosturl_files="http://#{ENV['HTTP_HOST']}" + @output_dir_structure_by='language' + @lingual='multi' + @port='5432' + @db_name_prefix='SiSU.7a.' + @user='www-data' # check user name for access to pg database: e.g. www-data or 'ralph' + @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP + @@offset=0 + @@canned_search_url=@base + @color_heading='#DDFFAA' + @color_match='#ffff48' + class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note='' if checked_searched !~/\S/ + the_can='' if checked_url !~/\S/ + search_field='' if checked_echo !~/\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip=if checked_tip =~/\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__;
' + else '' + end + end + def submission_form + search_form=<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+
+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep + case sensitive +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end + end + class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:filename + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1=text_to_match('text:') + @fulltext=text_to_match('fulltxt:') + @topic_register=text_to_match('topic_register:') + @title=text_to_match('title:') # DublinCore 1 - title + @author=text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject=text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description=text_to_match('description:') # DublinCore 4 - description + @publisher=text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor=text_to_match('editor:') + @contributor=text_to_match('contributor:') # DublinCore 6 - contributor + @date=text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type=text_to_match('type:') # DublinCore 8 - type + @format=text_to_match('format:') # DublinCore 9 - format + @identifier=text_to_match('identifier:') # DublinCore 10 - identifier + @source=text_to_match('source:') # DublinCore 11 - source + @language=text_to_match('language:') # DublinCore 12 - language + @relation=text_to_match('relation:') # DublinCore 13 - relation + @coverage=text_to_match('coverage:') # DublinCore 14 - coverage + @rights=text_to_match('rights:') # DublinCore 15 - rights + @keywords=text_to_match('key(?:words?)?:') + @comment=text_to_match('comment:') + @abstract=text_to_match('abs(?:tract)?:') + @owner=text_to_match('owner:') + @date_created=text_to_match('date_created:') + @date_issued=text_to_match('date_issued:') + @date_modified=text_to_match('date_modified:') + @date_available=text_to_match('date_available:') + @date_valid=text_to_match('date_valid:') + @filename=text_to_match('filename:') + @text1=text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1=q['s1'] if q['s1']=~/\S/ + @fulltext=q['ft'] if q['ft']=~/\S/ + @keywords=q['key'] if q['key']=~/\S/ + @title=q['ti'] if q['ti']=~/\S/ + @author=q['au'] if q['au']=~/\S/ + @topic_register=q['tr'] if q['tr']=~/\S/ + @subject=q['sj'] if q['sj']=~/\S/ + @description=q['dsc'] if q['dsc']=~/\S/ + @publisher=q['pb'] if q['pb']=~/\S/ + @editor=q['cntr'] if q['cntr']=~/\S/ + @contributor=q['cntr'] if q['cntr']=~/\S/ + @date=q['dt'] if q['dt']=~/\S/ + @type=q['ty'] if q['ty']=~/\S/ + @identifier=q['id'] if q['id']=~/\S/ + @source=q['src'] if q['src']=~/\S/ + @language=q['lang'] if q['lang']=~/\S/ + @relation=q['rel'] if q['rel']=~/\S/ + @coverage=q['cov'] if q['cov']=~/\S/ + @rights=q['cr'] if q['cr']=~/\S/ + @comment=q['co'] if q['co']=~/\S/ + @abstract=q['ab'] if q['ab']=~/\S/ + @date_created=q['dtc'] if q['dtc']=~/\S/ + @date_issued=q['dti'] if q['dti']=~/\S/ + @date_modified=q['dtm'] if q['dtm']=~/\S/ + @date_available=q['dta'] if q['dta']=~/\S/ + @date_valid=q['dtv'] if q['dtv']=~/\S/ + @filename=if q['doc'] and q['search'] !~/search db/ then q['doc'] + elsif q['fns']=~/\S/ then q['fns'] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end + end + class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q,@c=l,t,q,cse + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=if @c + unescaped_search.gsub(/\s*(AND|OR)\s*/,"' \) \\1 #{@l}~\( '"). + gsub(/(.+)/,"#{@l}~\( '\\1' \)") + else + unescaped_search.gsub(/\s*(AND|OR)\s*/,"' \) \\1 #{@l}~*\( '"). + gsub(/(.+)/,"#{@l}~*\( '\\1' \)") + end + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end + end + class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.src_filename',search_for.filename,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean~[*]?\(\s*'[^']+'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean~[*]?\(\s*'[^']+'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||=@@limit + offset ||=@@offset + @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE (#{@search_text}) AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn} + @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;} + select=@sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.exec(sql_select_body) + end + end + def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 7.1.2 2015-05-18 (2015w20/1) +
+ + SiSU © Ralph Amissah + 1993, current 2015. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2015. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK + end + @tail=tail + @counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 + @counters_txt,@counters_endn,@sql_select_body='','','' + FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo='checked' if cgi['echo'] =~/\S/ + checked_stats='checked' if cgi['stats'] =~/\S/ + checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched='checked' if cgi['searched'] =~/\S/ + checked_tip='checked' if cgi['tip'] =~/\S/ + checked_case='checked' if cgi['casesense'] =~/\S/ + checked_sql='checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all='checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none='' + elsif cgi['checks'] =~/check_none/ + checked_none='checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~/check_selected/ + checked_selected='checked' + elsif cgi['checks'] =~/check_default/ + checked_default='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=%{} + @conn=PG::Connection.open(dbname: @db, port: @port, user: @user) + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/ + ft='&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext=~/\S/ + key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/ + ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/ + au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/ + tr='&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register=~/\S/ + sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/ + dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/ + pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/ + edt='&edt=' + CGI.escape(@search_for.editor) if @search_for.editor=~/\S/ + cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/ + dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/ + ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/ + id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/ + src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/ + lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/ + rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/ + cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/ + cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/ + co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/ + ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/ + dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/ + dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/ + dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/ + dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ + dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ + fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'filename: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename=%{filename: #{green}#{@search_for.filename}

} if @search_for.filename =~/\S+/ + p_text=%{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~/\S+/ + p_fulltext=%{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~/\S+/ + p_title=%{title: #{green}#{@search_for.title}
} if @search_for.title =~/\S+/ + p_author=%{author: #{green}#{@search_for.author}
} if @search_for.author =~/\S+/ + p_editor=%{editor: #{green}#{@search_for.editor}
} if @search_for.editor=~/\S+/ + p_contributor=%{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~/\S+/ + p_date=%{date: #{green}#{@search_for.date}
} if @search_for.date =~/\S+/ + p_rights=%{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~/\S+/ + p_topic_register=%{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~/\S+/ + p_subject=%{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~/\S+/ + p_keywords=%{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~/\S+/ + p_identifier=%{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~/\S+/ + p_type=%{type: #{green}#{@search_for.type}
} if @search_for.type =~/\S+/ + p_format=%{format: #{green}#{@search_for.format}
} if @search_for.format =~/\S+/ + p_relation=%{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~/\S+/ + p_coverage=%{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~/\S+/ + p_description=%{description: #{green}#{@search_for.description}
} if @search_for.description =~/\S+/ + p_abstract=%{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~/\S+/ + p_comment=%{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~/\S+/ + p_publisher=%{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~/\S+/ + p_source=%{source: #{green}#{@search_for.source}
} if @search_for.source =~/\S+/ + p_language=%{language: #{green}#{@search_for.language}
} if @search_for.language =~/\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + oldtid=0 + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + else + end + @hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg}.html" + : "#{path_html_seg(fn,ln)}/#{seg}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['tid'].to_i != oldtid.to_i + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + oldtid=c['tid'].to_i + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=unescaped_search.scan(/\S+/).each.map do |g| + (g.to_s =~/(AND|OR)/) \ + ? ('|') + : (%{#{g.to_s}}) + end.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + oldtid = 0 + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header.force_encoding("UTF-8") + @counters_txt.force_encoding("UTF-8") + @counters_endn.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @body_main.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @tail.force_encoding("UTF-8")} #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+          s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end + end diff --git a/util/rb/cgi/sisu_search_pg.cgi b/util/rb/cgi/sisu_search_pg.cgi new file mode 100755 index 0000000..5e07a16 --- /dev/null +++ b/util/rb/cgi/sisu_search_pg.cgi @@ -0,0 +1,935 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (pgsql) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2015, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end + begin + require 'cgi' + require 'fcgi' + require 'pg' + rescue LoadError + puts 'cgi, fcgi or pg NOT FOUND (LoadError)' + end + @stub_default='samples_by_language' + @image_src="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" + @hosturl_cgi="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" + @hosturl_files="http://#{ENV['HTTP_HOST']}" + @output_dir_structure_by='language' + @lingual='multi' + @port='5432' + @db_name_prefix='SiSU.7a.' + @user='www-data' # check user name for access to pg database: e.g. www-data or 'ralph' + @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP + @@offset=0 + @@canned_search_url=@base + @color_heading='#DDFFAA' + @color_match='#ffff48' + class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note='' if checked_searched !~/\S/ + the_can='' if checked_url !~/\S/ + search_field='' if checked_echo !~/\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip=if checked_tip =~/\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__;
' + else '' + end + end + def submission_form + search_form=<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+
+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep + case sensitive +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end + end + class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:filename + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1=text_to_match('text:') + @fulltext=text_to_match('fulltxt:') + @topic_register=text_to_match('topic_register:') + @title=text_to_match('title:') # DublinCore 1 - title + @author=text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject=text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description=text_to_match('description:') # DublinCore 4 - description + @publisher=text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor=text_to_match('editor:') + @contributor=text_to_match('contributor:') # DublinCore 6 - contributor + @date=text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type=text_to_match('type:') # DublinCore 8 - type + @format=text_to_match('format:') # DublinCore 9 - format + @identifier=text_to_match('identifier:') # DublinCore 10 - identifier + @source=text_to_match('source:') # DublinCore 11 - source + @language=text_to_match('language:') # DublinCore 12 - language + @relation=text_to_match('relation:') # DublinCore 13 - relation + @coverage=text_to_match('coverage:') # DublinCore 14 - coverage + @rights=text_to_match('rights:') # DublinCore 15 - rights + @keywords=text_to_match('key(?:words?)?:') + @comment=text_to_match('comment:') + @abstract=text_to_match('abs(?:tract)?:') + @owner=text_to_match('owner:') + @date_created=text_to_match('date_created:') + @date_issued=text_to_match('date_issued:') + @date_modified=text_to_match('date_modified:') + @date_available=text_to_match('date_available:') + @date_valid=text_to_match('date_valid:') + @filename=text_to_match('filename:') + @text1=text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1=q['s1'] if q['s1']=~/\S/ + @fulltext=q['ft'] if q['ft']=~/\S/ + @keywords=q['key'] if q['key']=~/\S/ + @title=q['ti'] if q['ti']=~/\S/ + @author=q['au'] if q['au']=~/\S/ + @topic_register=q['tr'] if q['tr']=~/\S/ + @subject=q['sj'] if q['sj']=~/\S/ + @description=q['dsc'] if q['dsc']=~/\S/ + @publisher=q['pb'] if q['pb']=~/\S/ + @editor=q['cntr'] if q['cntr']=~/\S/ + @contributor=q['cntr'] if q['cntr']=~/\S/ + @date=q['dt'] if q['dt']=~/\S/ + @type=q['ty'] if q['ty']=~/\S/ + @identifier=q['id'] if q['id']=~/\S/ + @source=q['src'] if q['src']=~/\S/ + @language=q['lang'] if q['lang']=~/\S/ + @relation=q['rel'] if q['rel']=~/\S/ + @coverage=q['cov'] if q['cov']=~/\S/ + @rights=q['cr'] if q['cr']=~/\S/ + @comment=q['co'] if q['co']=~/\S/ + @abstract=q['ab'] if q['ab']=~/\S/ + @date_created=q['dtc'] if q['dtc']=~/\S/ + @date_issued=q['dti'] if q['dti']=~/\S/ + @date_modified=q['dtm'] if q['dtm']=~/\S/ + @date_available=q['dta'] if q['dta']=~/\S/ + @date_valid=q['dtv'] if q['dtv']=~/\S/ + @filename=if q['doc'] and q['search'] !~/search db/ then q['doc'] + elsif q['fns']=~/\S/ then q['fns'] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end + end + class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q,@c=l,t,q,cse + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=if @c + unescaped_search.gsub(/\s*(AND|OR)\s*/,"' \) \\1 #{@l}~\( '"). + gsub(/(.+)/,"#{@l}~\( '\\1' \)") + else + unescaped_search.gsub(/\s*(AND|OR)\s*/,"' \) \\1 #{@l}~*\( '"). + gsub(/(.+)/,"#{@l}~*\( '\\1' \)") + end + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end + end + class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.src_filename',search_for.filename,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean~[*]?\(\s*'[^']+'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean~[*]?\(\s*'[^']+'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||=@@limit + offset ||=@@offset + @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE (#{@search_text}) AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn} + @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;} + select=@sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.exec(sql_select_body) + end + end + def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 7.1.2 2015-05-18 (2015w20/1) +
+ + SiSU © Ralph Amissah + 1993, current 2015. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2015. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK + end + @tail=tail + @counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 + @counters_txt,@counters_endn,@sql_select_body='','','' + FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo='checked' if cgi['echo'] =~/\S/ + checked_stats='checked' if cgi['stats'] =~/\S/ + checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched='checked' if cgi['searched'] =~/\S/ + checked_tip='checked' if cgi['tip'] =~/\S/ + checked_case='checked' if cgi['casesense'] =~/\S/ + checked_sql='checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all='checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none='' + elsif cgi['checks'] =~/check_none/ + checked_none='checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~/check_selected/ + checked_selected='checked' + elsif cgi['checks'] =~/check_default/ + checked_default='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=%{} + @conn=PG::Connection.open(dbname: @db, port: @port, user: @user) + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/ + ft='&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext=~/\S/ + key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/ + ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/ + au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/ + tr='&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register=~/\S/ + sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/ + dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/ + pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/ + edt='&edt=' + CGI.escape(@search_for.editor) if @search_for.editor=~/\S/ + cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/ + dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/ + ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/ + id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/ + src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/ + lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/ + rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/ + cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/ + cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/ + co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/ + ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/ + dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/ + dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/ + dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/ + dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ + dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ + fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'filename: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename=%{filename: #{green}#{@search_for.filename}

} if @search_for.filename =~/\S+/ + p_text=%{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~/\S+/ + p_fulltext=%{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~/\S+/ + p_title=%{title: #{green}#{@search_for.title}
} if @search_for.title =~/\S+/ + p_author=%{author: #{green}#{@search_for.author}
} if @search_for.author =~/\S+/ + p_editor=%{editor: #{green}#{@search_for.editor}
} if @search_for.editor=~/\S+/ + p_contributor=%{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~/\S+/ + p_date=%{date: #{green}#{@search_for.date}
} if @search_for.date =~/\S+/ + p_rights=%{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~/\S+/ + p_topic_register=%{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~/\S+/ + p_subject=%{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~/\S+/ + p_keywords=%{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~/\S+/ + p_identifier=%{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~/\S+/ + p_type=%{type: #{green}#{@search_for.type}
} if @search_for.type =~/\S+/ + p_format=%{format: #{green}#{@search_for.format}
} if @search_for.format =~/\S+/ + p_relation=%{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~/\S+/ + p_coverage=%{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~/\S+/ + p_description=%{description: #{green}#{@search_for.description}
} if @search_for.description =~/\S+/ + p_abstract=%{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~/\S+/ + p_comment=%{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~/\S+/ + p_publisher=%{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~/\S+/ + p_source=%{source: #{green}#{@search_for.source}
} if @search_for.source =~/\S+/ + p_language=%{language: #{green}#{@search_for.language}
} if @search_for.language =~/\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + oldtid=0 + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + else + end + @hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg}.html" + : "#{path_html_seg(fn,ln)}/#{seg}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['tid'].to_i != oldtid.to_i + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + oldtid=c['tid'].to_i + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=unescaped_search.scan(/\S+/).each.map do |g| + (g.to_s =~/(AND|OR)/) \ + ? ('|') + : (%{#{g.to_s}}) + end.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + oldtid = 0 + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header.force_encoding("UTF-8") + @counters_txt.force_encoding("UTF-8") + @counters_endn.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @body_main.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @tail.force_encoding("UTF-8")} #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+          s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end + end diff --git a/util/rb/cgi/sisu_search_sqlite.cgi b/util/rb/cgi/sisu_search_sqlite.cgi new file mode 100755 index 0000000..0fe8ea5 --- /dev/null +++ b/util/rb/cgi/sisu_search_sqlite.cgi @@ -0,0 +1,937 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (sqlite) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2014, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end + begin + require 'cgi' + require 'fcgi' + require 'sqlite3' + rescue LoadError + puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)' + end + @stub_default='manual' + @image_src="http://#{ENV['HTTP_HOST']}/_sisu/image_sys" + @hosturl_cgi="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" + @hosturl_files="http://#{ENV['HTTP_HOST']}" + @output_dir_structure_by='filetype' + @lingual='multi' + @db_name_prefix='SiSU.7a.' + @base="http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP + @@offset=0 + @@canned_search_url=@base + @color_heading='#DDFFAA' + @color_match='#ffff48' + class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note='' if checked_searched !~/\S/ + the_can='' if checked_url !~/\S/ + search_field='' if checked_echo !~/\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip=if checked_tip =~/\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__;
' + else '' + end + end + def submission_form + search_form=<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+
+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end + end + class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:filename + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1=text_to_match('text:') + @fulltext=text_to_match('fulltxt:') + @topic_register=text_to_match('topic_register:') + @title=text_to_match('title:') # DublinCore 1 - title + @author=text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject=text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description=text_to_match('description:') # DublinCore 4 - description + @publisher=text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor=text_to_match('editor:') + @contributor=text_to_match('contributor:') # DublinCore 6 - contributor + @date=text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type=text_to_match('type:') # DublinCore 8 - type + @format=text_to_match('format:') # DublinCore 9 - format + @identifier=text_to_match('identifier:') # DublinCore 10 - identifier + @source=text_to_match('source:') # DublinCore 11 - source + @language=text_to_match('language:') # DublinCore 12 - language + @relation=text_to_match('relation:') # DublinCore 13 - relation + @coverage=text_to_match('coverage:') # DublinCore 14 - coverage + @rights=text_to_match('rights:') # DublinCore 15 - rights + @keywords=text_to_match('key(?:words?)?:') + @comment=text_to_match('comment:') + @abstract=text_to_match('abs(?:tract)?:') + @owner=text_to_match('owner:') + @date_created=text_to_match('date_created:') + @date_issued=text_to_match('date_issued:') + @date_modified=text_to_match('date_modified:') + @date_available=text_to_match('date_available:') + @date_valid=text_to_match('date_valid:') + @filename=text_to_match('filename:') + @text1=text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1=q['s1'] if q['s1']=~/\S/ + @fulltext=q['ft'] if q['ft']=~/\S/ + @keywords=q['key'] if q['key']=~/\S/ + @title=q['ti'] if q['ti']=~/\S/ + @author=q['au'] if q['au']=~/\S/ + @topic_register=q['tr'] if q['tr']=~/\S/ + @subject=q['sj'] if q['sj']=~/\S/ + @description=q['dsc'] if q['dsc']=~/\S/ + @publisher=q['pb'] if q['pb']=~/\S/ + @editor=q['cntr'] if q['cntr']=~/\S/ + @contributor=q['cntr'] if q['cntr']=~/\S/ + @date=q['dt'] if q['dt']=~/\S/ + @type=q['ty'] if q['ty']=~/\S/ + @identifier=q['id'] if q['id']=~/\S/ + @source=q['src'] if q['src']=~/\S/ + @language=q['lang'] if q['lang']=~/\S/ + @relation=q['rel'] if q['rel']=~/\S/ + @coverage=q['cov'] if q['cov']=~/\S/ + @rights=q['cr'] if q['cr']=~/\S/ + @comment=q['co'] if q['co']=~/\S/ + @abstract=q['ab'] if q['ab']=~/\S/ + @date_created=q['dtc'] if q['dtc']=~/\S/ + @date_issued=q['dti'] if q['dti']=~/\S/ + @date_modified=q['dtm'] if q['dtm']=~/\S/ + @date_available=q['dta'] if q['dta']=~/\S/ + @date_valid=q['dtv'] if q['dtv']=~/\S/ + @filename=if q['doc'] and q['search'] !~/search db/ then q['doc'] + elsif q['fns']=~/\S/ then q['fns'] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end + end + class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q=l,t,q + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=unescaped_search.gsub(/\s*(AND|OR)\s*/,"%' \) \\1 #{@l} LIKE \( '%"). + gsub(/(.+)/,"#{@l} LIKE \( '%\\1%' \)") + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end + end + class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st=DBI_SearchString.new('metadata_and_text.src_filename',search_for.filename,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||=@@limit + offset ||=@@offset + @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE #{@search_text} AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn} + @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;} + select=@sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.execute(sql_select_body) + end + end + def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 6.3.1 2014-10-19 (2014w41/7) +
+ + SiSU © Ralph Amissah + 1993, current 2014. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2014. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK + end + @tail=tail + @counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 + @counters_txt,@counters_endn,@sql_select_body='','','' + FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo='checked' if cgi['echo'] =~/\S/ + checked_stats='checked' if cgi['stats'] =~/\S/ + checked_url='checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched='checked' if cgi['searched'] =~/\S/ + checked_tip='checked' if cgi['tip'] =~/\S/ + checked_case='checked' if cgi['casesense'] =~/\S/ + checked_sql='checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~/check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all='checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none='' + elsif cgi['checks'] =~/check_none/ + checked_none='checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~/check_selected/ + checked_selected='checked' + elsif cgi['checks'] =~/check_default/ + checked_default='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=case cgi['db'] + when /SiSU.7a.manual/ then '' + end + db_name='sisu_sqlite.db' + db_sqlite=case cgi['db'] + when /SiSU.7a.manual/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + else "/srv/complete.sisudoc.org/web/manual/#{db_name}" + end + @conn=SQLite3::Database.new(db_sqlite) + @conn.results_as_hash=true + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1='s1=' + CGI.escape(@search_for.text1) if @search_for.text1=~/\S/ + ft='&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext=~/\S/ + key='key=' + CGI.escape(@search_for.keywords) if @search_for.keywords=~/\S/ + ti='&ti=' + CGI.escape(@search_for.title) if @search_for.title=~/\S/ + au='&au=' + CGI.escape(@search_for.author) if @search_for.author=~/\S/ + tr='&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register=~/\S/ + sj='&sj=' + CGI.escape(@search_for.subject) if @search_for.subject=~/\S/ + dsc='&dsc=' + CGI.escape(@search_for.description) if @search_for.description=~/\S/ + pb='&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher=~/\S/ + edt='&edt=' + CGI.escape(@search_for.editor) if @search_for.editor=~/\S/ + cntr='&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor=~/\S/ + dt='&dt=' + CGI.escape(@search_for.date) if @search_for.date=~/\S/ + ty='&ty=' + CGI.escape(@search_for.type) if @search_for.type=~/\S/ + id='&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier=~/\S/ + src='&src=' + CGI.escape(@search_for.source) if @search_for.source=~/\S/ + lang='&lang=' + CGI.escape(@search_for.language) if @search_for.language=~/\S/ + rel='&rel=' + CGI.escape(@search_for.relation) if @search_for.relation=~/\S/ + cov='&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage=~/\S/ + cr='&cr=' + CGI.escape(@search_for.rights) if @search_for.rights=~/\S/ + co='&co=' + CGI.escape(@search_for.comment) if @search_for.comment=~/\S/ + ab='&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract=~/\S/ + dtc='&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created=~/\S/ + dti='&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued=~/\S/ + dtm='&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified=~/\S/ + dta='&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available=~/\S/ + dtv='&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid=~/\S/ + fns='&fns=' + CGI.escape(@search_for.filename) if @search_for.filename=~/\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'filename: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename=%{filename: #{green}#{@search_for.filename}

} if @search_for.filename =~/\S+/ + p_text=%{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~/\S+/ + p_fulltext=%{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~/\S+/ + p_title=%{title: #{green}#{@search_for.title}
} if @search_for.title =~/\S+/ + p_author=%{author: #{green}#{@search_for.author}
} if @search_for.author =~/\S+/ + p_editor=%{editor: #{green}#{@search_for.editor}
} if @search_for.editor=~/\S+/ + p_contributor=%{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~/\S+/ + p_date=%{date: #{green}#{@search_for.date}
} if @search_for.date =~/\S+/ + p_rights=%{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~/\S+/ + p_topic_register=%{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~/\S+/ + p_subject=%{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~/\S+/ + p_keywords=%{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~/\S+/ + p_identifier=%{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~/\S+/ + p_type=%{type: #{green}#{@search_for.type}
} if @search_for.type =~/\S+/ + p_format=%{format: #{green}#{@search_for.format}
} if @search_for.format =~/\S+/ + p_relation=%{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~/\S+/ + p_coverage=%{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~/\S+/ + p_description=%{description: #{green}#{@search_for.description}
} if @search_for.description =~/\S+/ + p_abstract=%{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~/\S+/ + p_comment=%{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~/\S+/ + p_publisher=%{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~/\S+/ + p_source=%{source: #{green}#{@search_for.source}
} if @search_for.source =~/\S+/ + p_language=%{language: #{green}#{@search_for.language}
} if @search_for.language =~/\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header=Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + oldtid=0 + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + #@body_main << '



Main Text:
' << sql_select_body + else + end + @hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg}.html" + : "#{path_html_seg(fn,ln)}/#{seg}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['tid'].to_i != oldtid.to_i + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title=%{toc html #{ti} [#{c['language_document_char']}] by #{c['creator_author']} manifest #{can_txt_srch}
} if file_suffix=~/s/ #hmm watch file_suffix + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + oldtid=c['tid'].to_i + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=[] + build=unescaped_search.scan(/\S+/).each do |g| + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') + : (search_regex << %{#{g.to_s}}) + end + search_regex=search_regex.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + oldtid = 0 + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{@header.force_encoding("UTF-8") + @counters_txt.force_encoding("UTF-8") + @counters_endn.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @body_main.force_encoding("UTF-8") + canned.force_encoding("UTF-8") + @tail.force_encoding("UTF-8")} #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+          s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end + end diff --git a/util/rb/cgi/spine.search.cgi b/util/rb/cgi/spine.search.cgi new file mode 100755 index 0000000..cfe9d73 --- /dev/null +++ b/util/rb/cgi/spine.search.cgi @@ -0,0 +1,958 @@ +#!/usr/bin/env ruby +=begin + * Name: SiSU information Structuring Universe + * Author: Ralph Amissah + * http://www.jus.uio.no/sisu + * http://www.jus.uio.no/sisu/SiSU/download + + * Description: generates naive cgi search form for search of sisu database (sqlite) + * Name: SiSU generated sample cgi search form + + * Description: generated sample cgi search form for SiSU + (SiSU is a framework for document structuring, publishing and search) + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2014, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Ralph Amissah + + + +=end +begin + require 'cgi' + require 'fcgi' + require 'sqlite3' +rescue LoadError + puts 'cgi, fcgi or sqlite3 NOT FOUND (LoadError)' +end +@stub_default = 'search' +@image_src = "http://#{ENV['HTTP_HOST']}/image_sys" +@hosturl_cgi = "http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}" +@hosturl_files = "http://#{ENV['HTTP_HOST']}" +@output_dir_structure_by = 'language' +@lingual = 'multi' +@db_name_prefix = 'spine.' +@base = "http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}#{ENV['SCRIPT_NAME']}" +#Common TOP +@@offset = 0 +@@canned_search_url = @base +@color_heading = '#DDFFAA' +@color_match = '#ffff48' +class Form + def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='') + search_note = '' if checked_searched !~ /\S/ + the_can = '' if checked_url !~ /\S/ + search_field = '' if checked_echo !~ /\S/ + @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can + @tip = if checked_tip =~ /\S/ + 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; src_filename_base:__;
' + else '' + end + end + def submission_form + search_form =<<-WOK + + + + + <meta charset="utf-8"> + <meta name="sourcefile" content="SiSU._sst" /> + SiSU search form (sample): SiSU information Structuring Universe + + + + + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +
+
+ + +
+ + + #{@tip} + #{@search_note} + #{@the_can} +
+ + + + + to search: select which database to search (drop-down menu below); enter your search query (in the form above); and click on the search button (below) +
+ + + index + text / grep +
+ match limit: + 1,000 + 2,500 +
+ echo query + result stats + search url + searched + available fields + sql statement +
+ checks: + default + selected + all + none +
+ + +
+ WOK + end +end +class SearchRequest #% search_for + attr_accessor :text1,:fulltext,:keywords,:title,:author,:topic_register,:subject,:description,:publisher,:editor,:contributor,:date,:type,:format,:identifier,:source,:language,:relation,:coverage,:rights,:comment,:abstract,:owner,:date_created,:date_issued,:date_modified,:date_available,:date_valid,:src_filename_base + def initialize(search_field='',q='') + @search_field,@q=search_field,q + @text1=@fulltext=@keywords=@title=@author=@topic_register=@subject=@description=@publisher=@editor=@contributor=@date=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@comment=@abstract=@owner=@date_created=@date_issued=@date_modified=@date_available=@date_valid=@filename='' + if @search_field=~/\S/ + @text1 = text_to_match('text:') + @fulltext = text_to_match('fulltxt:') + @topic_register = text_to_match('topic_register:') + @title = text_to_match('title:') # DublinCore 1 - title + @author = text_to_match('(?:author|creator)s?:') # DublinCore 2 - creator/author + @subject = text_to_match('subj(?:ect)?:') # DublinCore 3 - subject + @description = text_to_match('description:') # DublinCore 4 - description + @publisher = text_to_match('pub(?:lisher)?:') # DublinCore 5 - publisher + @editor = text_to_match('editor:') + @contributor = text_to_match('contributor:') # DublinCore 6 - contributor + @date = text_to_match('date:') # DublinCore 7 - date dd-mm-yy + @type = text_to_match('type:') # DublinCore 8 - type + @format = text_to_match('format:') # DublinCore 9 - format + @identifier = text_to_match('identifier:') # DublinCore 10 - identifier + @source = text_to_match('source:') # DublinCore 11 - source + @language = text_to_match('language:') # DublinCore 12 - language + @relation = text_to_match('relation:') # DublinCore 13 - relation + @coverage = text_to_match('coverage:') # DublinCore 14 - coverage + @rights = text_to_match('rights:') # DublinCore 15 - rights + @keywords = text_to_match('key(?:words?)?:') + @comment = text_to_match('comment:') + @abstract = text_to_match('abs(?:tract)?:') + @owner = text_to_match('owner:') + @date_created = text_to_match('date_created:') + @date_issued = text_to_match('date_issued:') + @date_modified = text_to_match('date_modified:') + @date_available = text_to_match('date_available:') + @date_valid = text_to_match('date_valid:') + @filename = text_to_match('src_filename_base:') + @text1 = text_to_match unless @keywords or @author or @title or @text1 or @fulltext or @comment or @abstract or @rights or @subject or @publisher or @date or @filename or @topic_register + else + @text1 = q['s1'] if q['s1'] =~ /\S/ + @fulltext = q['ft'] if q['ft'] =~ /\S/ + @keywords = q['key'] if q['key'] =~ /\S/ + @title = q['ti'] if q['ti'] =~ /\S/ + @author = q['au'] if q['au'] =~ /\S/ + @topic_register = q['tr'] if q['tr'] =~ /\S/ + @subject = q['sj'] if q['sj'] =~ /\S/ + @description = q['dsc'] if q['dsc'] =~ /\S/ + @publisher = q['pb'] if q['pb'] =~ /\S/ + @editor = q['cntr'] if q['cntr'] =~ /\S/ + @contributor = q['cntr'] if q['cntr'] =~ /\S/ + @date = q['dt'] if q['dt'] =~ /\S/ + @type = q['ty'] if q['ty'] =~ /\S/ + @identifier = q['id'] if q['id'] =~ /\S/ + @source = q['src'] if q['src'] =~ /\S/ + @language = q['lang'] if q['lang'] =~ /\S/ + @relation = q['rel'] if q['rel'] =~ /\S/ + @coverage = q['cov'] if q['cov'] =~ /\S/ + @rights = q['cr'] if q['cr'] =~ /\S/ + @comment = q['co'] if q['co'] =~ /\S/ + @abstract = q['ab'] if q['ab'] =~ /\S/ + @date_created = q['dtc'] if q['dtc'] =~ /\S/ + @date_issued = q['dti'] if q['dti'] =~ /\S/ + @date_modified = q['dtm'] if q['dtm'] =~ /\S/ + @date_available = q['dta'] if q['dta'] =~ /\S/ + @date_valid = q['dtv'] if q['dtv'] =~ /\S/ + @filename = if q['doc'] and q['search'] !~ /search db/ then q['doc'] + elsif q['fns'] =~ /\S/ then q['fns'] + end + @@limit = q['ltd'] if q['ltd'] =~ /\d+/ # 1000 + @@offset = q['off'] if q['off'] =~ /\d+/ # 0 + end + end + def text_to_match(identifier='') + m={ + string: /#{identifier}\s*(.+?)/, + string: /#{identifier}\s*(.+?)(?:;|\n|\r|$)/, + word: /#{identifier}[\s(]*(\S+)/ + } + search_string=if @search_field =~m[:word] + search_string=if @search_field =~m[:braces] then m[:braces].match(@search_field)[1] + elsif @search_field =~m[:string] then m[:string].match(@search_field)[1] + else + str=m[:word].match(@search_field)[1] + str=str.gsub(/[()]/,'') + str + end + search_string=search_string.strip.gsub(/\s+/,'+') + #else + # "__" + end + end +end +class DBI_SearchString + def initialize(l,t,q,cse=false) + @l,@t,@q=l,t,q + end + def string + search={ search: [], flag: false } + if @t =~/\S+/ or @q =~/\S+/ + if @t =~/\S+/ then unescaped_search=CGI.unescape(@t) + elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q) + end + search_construct=[] + unescaped_search=unescaped_search.gsub(/\s*(AND|OR)\s*/,"%' \) \\1 #{@l} LIKE \( '%"). + gsub(/(.+)/,"#{@l} LIKE \( '%\\1%' \)") + search_construct << unescaped_search + search_construct=search_construct.join(' ') + search[:search] << search_construct + search[:flag]=true + search + end + search + end +end +class DBI_SearchStatement + attr_reader :text_search_flag,:sql_select_body_format,:sql_offset,:sql_limit + def initialize(conn,search_for,q,c) + @conn=conn + @text_search_flag=false + @sql_statement={ body: '', endnotes: '', range: '' } + #@offset||=@@offset + #@offset+=@@limit + search={ text: [], endnotes: [] } + cse=(c =~/\S/) ? true : false + st=DBI_SearchString.new('doc_objects.clean',search_for.text1,q['s1'],cse).string + se=DBI_SearchString.new('endnotes.clean',search_for.text1,q['s1'],cse).string + @text_search_flag=st[:flag] + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.fulltext',search_for.fulltext,q['ft'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.title',search_for.title,q['ti'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.creator_author',search_for.author,q['au'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.classify_topic_register',search_for.topic_register,q['tr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.classify_subject',search_for.subject,q['sj'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.classify_keywords',search_for.keywords,q['key'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_description',search_for.description,q['dsc'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.publisher',search_for.publisher,q['pb'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.creator_editor',search_for.editor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.creator_contributor',search_for.contributor,q['cntr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.date_published',search_for.date,q['dt'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_type',search_for.type,q['ty'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.original_source',search_for.source,q['src'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.language_document_char',search_for.language,q['lang'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_relation',search_for.relation,q['rel'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_coverage',search_for.coverage,q['cov'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.rights_all',search_for.rights,q['cr'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_comment',search_for.comment,q['co'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.notes_abstract',search_for.abstract,q['ab'],cse).string + if st[:flag] + search[:text] << st[:search] + end + st = DBI_SearchString.new('metadata_and_text.src_filename_base',search_for.src_filename_base,q['fns'],cse).string + if st[:flag] + search[:text] << st[:search] + end + @@limit=q['ltd'] if q['ltd']=~/\d+/ # 1000 + @@offset=q['off'] if q['off']=~/\d+/ # 0 + @search_text='' + @search_text=search[:text].flatten.join(' AND ') + @search_text=@search_text.gsub(/(doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean\s+LIKE\s+\(\s*'%[^']+%'\s*\))+)/,'(\1)') + end + def sql_offset + @@offset + end + def sql_match_limit + @@limit + end + def sql_canned_search + @offset_next=sql_offset.to_i + sql_match_limit.to_i + @offset_previous=sql_offset.to_i - sql_match_limit.to_i + def current + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + sql_offset.to_s + end + def next + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_next.to_s + end + def previous + @offset_previous >= 0 \ + ? (@@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + @offset_previous.to_s) + : '' + end + def start + @@canned_search_url.to_s + '<d=' + sql_match_limit.to_s + '&off=' + 0.to_s + end + self + end + def pre_next(beyond_limit,img) + can=sql_canned_search + page=(sql_offset.to_i + sql_match_limit.to_i)/sql_match_limit.to_i + if beyond_limit + if page.to_s =~ /^1$/ + %{
+ pg. #{page.to_s} + +  >> + +
} + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} + +  >> + +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} + +  >> + +
} + end + else + if page.to_s =~ /^1$/ then '' + elsif page.to_s =~ /^2$/ + %{
+ + <<  + + pg. #{page.to_s} +
} + else + %{
+ + |<  + + + <<  + + pg. #{page.to_s} +
} + end + end + end + def sql_select_body + limit ||= @@limit + offset ||= @@offset + @sql_statement[:body] = %{ + SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename_base, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg_name, doc_objects.ocn, metadata_and_text.uid + FROM doc_objects, metadata_and_text + WHERE #{@search_text} AND doc_objects.uid_metadata_and_text = metadata_and_text.uid + ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename_base, doc_objects.ocn + } + @sql_statement[:range] = %{LIMIT #{limit} OFFSET #{offset} ;} + select = @sql_statement[:body] + ' ' + @sql_statement[:range] + select + end + def sql_select_body_format + %{#{sql_select_body}} + end + def contents + @conn.execute(sql_select_body) + end +end +def tail + <<-'WOK' +


+ + + + + + +
+ + +
+
+ SiSU + +
+ git + +
+
+ +

+ Generated by + SiSU 6.3.1 2014-10-19 (2014w41/7) +
+ + SiSU © Ralph Amissah + 1993, current 2014. + All Rights Reserved. +
+ SiSU is software for document structuring, publishing and search, +
+ + www.jus.uio.no/sisu + + and + + www.sisudoc.org + + sources + + git.sisudoc.org + +
+ w3 since October 3 1993 + + ralph@amissah.com + +
+ mailing list subscription + + http://lists.sisudoc.org/listinfo/sisu + +
+ + sisu@lists.sisudoc.org + +

+
+

+ SiSU using: +
Standard SiSU markup syntax, +
Standard SiSU meta-markup syntax, and the +
Standard SiSU object citation numbering and system, (object/text identifying/locating system) +
+ © Ralph Amissah 1997, current 2014. + All Rights Reserved. +

+
+

+ + .: + +

+
+

+ SiSU is released under + GPL v3 + or later, + + http://www.gnu.org/licenses/gpl.html + +

+
+

+ SiSU, developed using + + Ruby + + on + + Debian/Gnu/Linux + + software infrastructure, + with the usual GPL (or OSS) suspects. +

+
+ + + WOK +end +@tail=tail +@counter_txt_doc,@counter_txt_ocn,@counter_endn_doc,@counter_endn_ocn=0,0,0,0 +@counters_txt,@counters_endn,@sql_select_body='','','' +FCGI.each_cgi do |cgi| + begin # all code goes in begin section + @search={ text: [], endnotes: [] } + q=CGI.new + @db=if cgi['db'] =~ /#{@db_name_prefix}(\S+)/ + @stub=$1 + cgi['db'] + else + @stub=@stub_default + @db_name_prefix + @stub + end + checked_url,checked_stats,checked_searched,checked_tip,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,selected_db='','','','','','','','','' + result_type=(cgi['view']=~/text/) \ + ? result_type={ index: '', text: 'checked'} + : result_type={ index: 'checked', text: ''} + @@limit=if cgi['sql_match_limit'].to_s=~/2500/ + checked_sql_limit={ l1000: '', l2500: 'checked'} + '2500' + else + checked_sql_limit={ l1000: 'checked', l2500: ''} + '1000' + end + checked_echo = 'checked' if cgi['echo'] =~/\S/ + checked_stats = 'checked' if cgi['stats'] =~/\S/ + checked_url = 'checked' if cgi['url'] =~/\S/ or cgi['u'].to_i==1 + checked_searched = 'checked' if cgi['searched'] =~/\S/ + checked_tip = 'checked' if cgi['tip'] =~/\S/ + checked_case = 'checked' if cgi['casesense'] =~/\S/ + checked_sql = 'checked' if cgi['sql'] =~/\S/ + if cgi['checks'] =~ /check_all/ or cgi['check_all'] =~/\S/ or cgi['a'].to_i==1 + checked_all = 'checked' + checked_echo=checked_stats=checked_url=checked_searched=checked_tip=checked_sql='checked' + checked_none ='' + elsif cgi['checks'] =~ /check_none/ + checked_none = 'checked' + checked_all=checked_url=checked_stats=checked_searched=checked_tip=checked_echo=checked_sql='' + elsif cgi['checks'] =~ /check_selected/ + checked_selected = 'checked' + elsif cgi['checks'] =~ /check_default/ + checked_default = 'checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + else + checked_selected='checked' + checked_echo=checked_stats=checked_url='checked' + checked_searched=checked_tip=checked_case=checked_sql='' + end + selected_db=case cgi['db'] + when /spine.sqlite/ then '' + end + db_name='spine.search.sql.db' + #db_name='spine.sqlite.db' + #db_name='sisu_sqlite.db' + db_sqlite=case cgi['db'] + when /spine.sqlite/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + else "/var/www/sqlite/#{db_name}" + end + #when /spine.sqlite/ then "/srv/complete.sisudoc.org/web/manual/#{db_name}" + #else "/srv/complete.sisudoc.org/web/manual/#{db_name}" + #end + #@conn=SQLite3::Database.new(db_sqlite) + @conn=SQLite3::Database.new("/var/www/sqlite/spine.search.sql.db") + #@conn=SQLite3::Database.new("/var/www/spine.sqlite.db") + @conn.results_as_hash=true + search_field=cgi['find'] if cgi['find'] # =~/\S+/ + @search_for=SearchRequest.new(search_field,q) #.analyze #% search_for + #% searches + #Canned_search.new(@base,@search_for.text1,cgi) + if @search_for.text1=~/\S+/ or @search_for.fulltext=~/\S+/ or @search_for.author=~/\S+/ or @search_for.topic_register=~/\S+/ #and search_field =~/\S/ + s1 = 's1=' + CGI.escape(@search_for.text1) if @search_for.text1 =~ /\S/ + ft = '&ft=' + CGI.escape(@search_for.fulltext) if @search_for.fulltext =~ /\S/ + key = 'key=' + CGI.escape(@search_for.keywords) if @search_for.keywords =~ /\S/ + ti = '&ti=' + CGI.escape(@search_for.title) if @search_for.title =~ /\S/ + au = '&au=' + CGI.escape(@search_for.author) if @search_for.author =~ /\S/ + tr = '&tr=' + CGI.escape(@search_for.topic_register) if @search_for.topic_register =~ /\S/ + sj = '&sj=' + CGI.escape(@search_for.subject) if @search_for.subject =~ /\S/ + dsc = '&dsc=' + CGI.escape(@search_for.description) if @search_for.description =~ /\S/ + pb = '&pb=' + CGI.escape(@search_for.publisher) if @search_for.publisher =~ /\S/ + edt = '&edt=' + CGI.escape(@search_for.editor) if @search_for.editor =~ /\S/ + cntr = '&cntr=' + CGI.escape(@search_for.contributor) if @search_for.contributor =~ /\S/ + dt = '&dt=' + CGI.escape(@search_for.date) if @search_for.date =~ /\S/ + ty = '&ty=' + CGI.escape(@search_for.type) if @search_for.type =~ /\S/ + id = '&id=' + CGI.escape(@search_for.identifier) if @search_for.identifier =~ /\S/ + src = '&src=' + CGI.escape(@search_for.source) if @search_for.source =~ /\S/ + lang = '&lang=' + CGI.escape(@search_for.language) if @search_for.language =~ /\S/ + rel = '&rel=' + CGI.escape(@search_for.relation) if @search_for.relation =~ /\S/ + cov = '&cov=' + CGI.escape(@search_for.coverage) if @search_for.coverage =~ /\S/ + cr = '&cr=' + CGI.escape(@search_for.rights) if @search_for.rights =~ /\S/ + co = '&co=' + CGI.escape(@search_for.comment) if @search_for.comment =~ /\S/ + ab = '&ab=' + CGI.escape(@search_for.abstract) if @search_for.abstract =~ /\S/ + dtc = '&dtc=' + CGI.escape(@search_for.date_created) if @search_for.date_created =~ /\S/ + dti = '&dti=' + CGI.escape(@search_for.date_issued) if @search_for.date_issued =~ /\S/ + dtm = '&dtm=' + CGI.escape(@search_for.date_modified) if @search_for.date_modified =~ /\S/ + dta = '&dta=' + CGI.escape(@search_for.date_available) if @search_for.date_available =~ /\S/ + dtv = '&dtv=' + CGI.escape(@search_for.date_valid) if @search_for.date_valid =~ /\S/ + fns = '&fns=' + CGI.escape(@search_for.src_filename_base) if @search_for.src_filename_base =~ /\S/ + @@canned_search_url=(checked_all =~/checked/) \ + ? "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}&a=1" + : "#{@base}?#{s1}#{ft}#{key}#{ti}#{au}#{tr}#{sj}#{dsc}#{pb}#{edt}#{cntr}#{dt}#{ty}#{id}#{src}#{lang}#{rel}#{cov}#{cr}#{co}#{ab}#{dtc}#{dti}#{dtm}#{dta}#{dtv}#{fns}&db=#{cgi['db']}&view=#{cgi['view']}" + mod=ft=~/\S+/ ? (ft.gsub(/ft/,'s1')) : s1 + @canned_base_url="#{@base}?#{mod}&db=#{cgi['db']}" + if checked_case=~/\S/ + @search[:text][1]=%{doc_objects.clean~'#{@search_for.text1}'} #s1 + else + @search[:text][1]=%{doc_objects.clean~*'#{@search_for.text1}'} #s1 + end + canned_note='search url:' + else + @@canned_search_url="#{@base}?db=#{@db}&view=index" + canned_note='search url example:' + end + if search_field =~/\S+/ + analyze_format=search_field.gsub(/\s*\n/,'; ') + elsif checked_all =~/checked/ or checked_url =~/checked/ + canned_search=@@canned_search_url.scan(/(?:s1|ft|au|ti|fns|tr)=[^&]+/) + af=canned_search.join('; ') + af=af.gsub(/s1=/,'text: '). + gsub(/ft=/,'fulltxt: '). + gsub(/au=/,'author: '). + gsub(/ti=/,'title: '). + gsub(/fns=/,'src_filename_base: '). + gsub(/tr=/,'topic_register: '). + gsub(/%2B/,' ') + analyze_format=af + st=af.split(/\s*;\s*/) + search_field=st.join("\n") + end + green=%{} + canned_search_url_txt=CGI.escapeHTML(@@canned_search_url) + the_can=%{#{canned_note} #{canned_search_url_txt}
} + p_text=p_fulltext=p_keywords=p_title=p_author=p_topic_register=p_subject=p_description=p_publisher=p_editor=p_contributor=p_date=p_type=p_format=p_identifier=p_source=p_language=p_relation=p_coverage=p_rights=p_comment=p_abstract=p_filename='' + p_filename = %{src_filename_base: #{green}#{@search_for.src_filename_base}

} if @search_for.src_filename_base =~ /\S+/ + p_text = %{text: #{green}#{@search_for.text1}

} if @search_for.text1 =~ /\S+/ + p_fulltext = %{fulltxt: #{green}#{@search_for.fulltext}
} if @search_for.fulltext =~ /\S+/ + p_title = %{title: #{green}#{@search_for.title}
} if @search_for.title =~ /\S+/ + p_author = %{author: #{green}#{@search_for.author}
} if @search_for.author =~ /\S+/ + p_editor = %{editor: #{green}#{@search_for.editor}
} if @search_for.editor =~ /\S+/ + p_contributor = %{contributor: #{green}#{@search_for.contributor}
} if @search_for.contributor =~ /\S+/ + p_date = %{date: #{green}#{@search_for.date}
} if @search_for.date =~ /\S+/ + p_rights = %{rights: #{green}#{@search_for.rights}
} if @search_for.rights =~ /\S+/ + p_topic_register = %{topic_register: #{green}#{@search_for.topic_register}
} if @search_for.topic_register =~ /\S+/ + p_subject = %{subject: #{green}#{@search_for.subject}
} if @search_for.subject =~ /\S+/ + p_keywords = %{keywords: #{green}#{@search_for.keywords}
} if @search_for.keywords =~ /\S+/ + p_identifier = %{identifier: #{green}#{@search_for.identifier}
} if @search_for.identifier =~ /\S+/ + p_type = %{type: #{green}#{@search_for.type}
} if @search_for.type =~ /\S+/ + p_format = %{format: #{green}#{@search_for.format}
} if @search_for.format =~ /\S+/ + p_relation = %{relation: #{green}#{@search_for.relation}
} if @search_for.relation =~ /\S+/ + p_coverage = %{coverage: #{green}#{@search_for.coverage}
} if @search_for.coverage =~ /\S+/ + p_description = %{description: #{green}#{@search_for.description}
} if @search_for.description =~ /\S+/ + p_abstract = %{abstract: #{green}#{@search_for.abstract}
} if @search_for.abstract =~ /\S+/ + p_comment = %{comment: #{green}#{@search_for.comment}
} if @search_for.comment =~ /\S+/ + p_publisher = %{publisher: #{green}#{@search_for.publisher}
} if @search_for.publisher =~ /\S+/ + p_source = %{source: #{green}#{@search_for.source}
} if @search_for.source =~ /\S+/ + p_language = %{language: #{green}#{@search_for.language}
} if @search_for.language =~ /\S+/ + search_note=<<-WOK + + database: #{green}#{@db}; selected view: #{green}#{cgi['view']} + search string: "#{green}#{analyze_format}"
+ #{p_text} #{p_fulltext} #{p_keywords} #{p_title} #{p_author} #{p_topic_register} #{p_subject} #{p_description} #{p_publisher} #{p_editor} #{p_contributor} #{p_date} #{p_type} #{p_format} #{p_identifier} #{p_source} #{p_language} #{p_relation} #{p_coverage} #{p_rights} #{p_comment} #{p_abstract} #{p_filename} + + WOK + #eg = %{canned search e.g.:
#{url}
find: #{analyze}
database: #{database}} + #% dbi_canning + @header = Form.new(@base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can).submission_form #% form + unless q['s1'] =~/\S/ or q['au'] =~/\S/ or @search[:text][1] =~/\S/ + print "Content-type: text/html\n\n" + puts (@header+@tail) + else #% searches + s1=(@search_for.text1 =~/\S/) \ + ? @search_for.text1 + : 'Unavailable' + if checked_case=~/\S/ + @search[:text]<<%{doc_objects.clean~'#{CGI.unescape(s1)}'} + else + @search[:text]<<%{doc_objects.clean~*'#{CGI.unescape(s1)}'} + end + #% dbi_request + dbi_statement=DBI_SearchStatement.new(@conn,@search_for,q,checked_case) + @text_search_flag=false + @text_search_flag=dbi_statement.text_search_flag + s_contents=dbi_statement.contents + @body_main='' + @search_regx=nil + olduid="" + if @text_search_flag + if checked_sql =~/\S/ + sql_select_body=dbi_statement.sql_select_body_format + else sql_select_body='' + end + @body_main << sql_select_body + #@body_main << '



Main Text:
' << sql_select_body + else + end + @hostpath = "#{@hosturl_files}" + #@hostpath="#{@hosturl_files}/#{@stub}" + def path_manifest(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{@hostpath}/#{fn}/sisu_manifest.html" + : "#{@hostpath}/#{fn}/sisu_manifest.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/manifest/#{fn}.html" + : "#{@hostpath}/manifest/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/manifest/#{fn}.html" + end + end + def path_html_seg(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + "#{@hostpath}/#{fn}" + when 'filetype' + "#{@hostpath}/html/#{fn}" + else + "#{@hostpath}/#{ln}/html/#{fn}" + end + end + def path_toc(fn,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/toc.html" + : "#{path_html_seg(fn,ln)}/toc.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/toc.html" + end + end + def path_filename(fn,seg_name,ln=nil) + if @output_dir_structure_by =='filename' \ + or @output_dir_structure_by =='filetype' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/#{seg_name}.html" + : "#{path_html_seg(fn,ln)}/#{seg_name}.#{ln}.html" + else + "#{path_html_seg(fn,ln)}/#{seg_name}.html" + end + end + def path_html_doc(fn,ln=nil) + case @output_dir_structure_by + when 'filename' + @lingual =='mono' \ + ? "#{path_html_seg(fn,ln)}/scroll.html" + : "#{path_html_seg(fn,ln)}/scroll.#{ln}.html" + when 'filetype' + @lingual =='mono' \ + ? "#{@hostpath}/html/#{fn}.html" + : "#{@hostpath}/html/#{fn}.#{ln}.html" + else + "#{@hostpath}/#{ln}/html/#{fn}.html" + end + end + #% text_objects_body + s_contents.each do |c| #% text body + location=c['src_filename_base'][/(.+?)\.(?:ssm\.sst|sst)$/,1] + file_suffix=c['src_filename_base'][/.+?\.(ssm\.sst|sst)$/,1] + lang=if location =~ /\S+?~(\S\S\S?)$/ + l=location[/\S+?~(\S\S\S?)$/,1] + location=location.gsub(/(\S+?)~\S\S\S?/,'\1') + l=".#{l}" + else '' + end + #% metadata_found_body + if c['uid'] != olduid + ti=c['title'] + can_txt_srch=(cgi['view']=~/index/) \ + ? %{search } + : %{search } + title = %{ #{ti} [#{c['language_document_char']}] by #{c['creator_author']} #{can_txt_srch}
} + title=@text_search_flag \ + ? '

'+title + : '
'+title + @counter_txt_doc+=1 + olduid=c['uid'] + else title='' + end + if @text_search_flag + if cgi['view']=~/text/ \ + or (cgi['view']!~/index/ and cgi['search'] !~/search db/) #% txt body + text=if c['suffix'] !~/1/ #seg + if @search_for.text1 =~/\S+/ \ + or q['s1'] =~/\S+/ #% only this branch is working !! + unescaped_search=if @search_for.text1 =~/\S+/ + CGI.unescape(@search_for.text1) + elsif q['s1'] =~/\S+/ + CGI.unescape(q['s1']) + else nil + end + @search_regx=if unescaped_search #check + search_regex=[] + build=unescaped_search.scan(/\S+/).each do |g| + (g.to_s =~/(AND|OR)/) \ + ? (search_regex << '|') + : (search_regex << %{#{g.to_s}}) + end + search_regex=search_regex.join(' ') + search_regex=search_regex.gsub(/\s*\|\s*/,'|') + Regexp.new(search_regex, Regexp::IGNORECASE) + else nil + end + else nil + end + matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) \ + ? (c['body'].gsub(/(<\s]+#{@search_regx}[^>]+?>|#{@search_regx})/mi,%{\\1})) + : c['body'] + %{

ocn #{c['ocn']}:

#{matched_para}} + elsif c['suffix'] =~/1/ #doc + %{#{title}

ocn #{c['ocn']}:#{c['body']}} + end + @counter_txt_ocn+=1 + output=title+text + else #elsif cgi['view']=~/index/ #% idx body + if c['suffix'] !~/1/ #seg + index=%{#{c['ocn']}, } if @text_search_flag + elsif c['suffix'] =~/1/ #doc #FIX + index=%{#{c['ocn']}, } + end + if c['seg_name'] =~/\S+/ + if @text_search_flag + @counter_txt_ocn+=1 + output=title+index + end + else + @counter_txt_ocn+=1 + output=c['suffix'] !~/1/ \ + ? title+index + : %{#{title}#{c['ocn'].sort}, } + end + end + else output=title + end + @counters_txt=if @counter_txt_doc > 0 + if checked_stats =~/\S/ + @@lt_t=(@counter_txt_ocn==dbi_statement.sql_match_limit.to_i) ? true : false + start=(@@offset.to_i+1).to_s + range=(@@offset.to_i+@counter_txt_ocn.to_i).to_s + %{


Found #{@counter_txt_ocn} times in the main body of #{@counter_txt_doc} documents [ matches #{start} to #{range} ]
} + else '' + end + else '' + end + @body_main << output #+ details + end + olduid = "" + offset=dbi_statement.sql_offset.to_s + limit=dbi_statement.sql_match_limit.to_s + @@lt_t ||=false; @@lt_e ||=false + canned=(@@lt_t or @@lt_e) \ + ? dbi_statement.pre_next(true,@image_src).to_s + : dbi_statement.pre_next(false,@image_src).to_s + limit=dbi_statement.sql_match_limit.to_s + cgi.out{ + @header.force_encoding("UTF-8") \ + + @counters_txt.force_encoding("UTF-8") \ + + @counters_endn.force_encoding("UTF-8") \ + + canned.force_encoding("UTF-8") \ + + @body_main.force_encoding("UTF-8") \ + + canned.force_encoding("UTF-8") \ + + @tail.force_encoding("UTF-8") + } #% print cgi_output_header+counters+body + end + rescue Exception => e + s='
' + CGI::escapeHTML(e.backtrace.reverse.join("\n"))
+    s << CGI::escapeHTML(e.message) + '
' + cgi.out{s} + next + ensure # eg. disconnect from server + @conn.disconnect if @conn + end +end diff --git a/util/rb/tex/dr_tex.rb b/util/rb/tex/dr_tex.rb new file mode 100755 index 0000000..767742c --- /dev/null +++ b/util/rb/tex/dr_tex.rb @@ -0,0 +1,70 @@ +#!/usr/bin/env ruby +require 'fileutils' +pwd = Dir.pwd +argv,texfiles_with_path,flags=[],[],[] +lngs = %{(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)} +Regexp.new(lngs, Regexp::IGNORECASE) +argv=$* +argv.sort.each{|y| (y =~/^--\S+$/i) ? (flags << y) : (texfiles_with_path << y) } +if flags.length==0 \ +|| flags.inspect =~/"--help"/ + cmd=(/([^\/]+)$/).match($0)[1] + puts < 0 + texfiles_with_path.each do |texfile_with_path| + if texfile_with_path =~/.+\.tex/ + #puts texfile_with_path + if FileTest.file?(texfile_with_path) + file_basename_with_path = texfile_with_path.sub(/\.tex$/,'') + file_basename = file_basename_with_path.sub(/.*?([^\/]+)$/,'\1') + _out_path = out_path + if file_basename =~ /\.#{lngs}$/ + lng = file_basename.match(/\.#{lngs}$/)[1] + puts file_basename + puts lng + puts _out_path + unless _out_path.match(/\/#{lng}\/pdf$/) + _out_path = "#{out_path}/#{lng}/pdf" + FileUtils::mkdir_p(_out_path) + end + end + texpdf_cmd = %{xetex -interaction=batchmode -fmt=xelatex #{texfile_with_path}\n} + puts texpdf_cmd + 2.times { |i| system(texpdf_cmd) } + if (FileTest.file?(%{#{pwd}/#{file_basename}.pdf})) && (FileTest.directory?(_out_path)) + FileUtils::Verbose::mv(%{#{pwd}/#{file_basename}.pdf}, %{#{_out_path}/#{file_basename}.pdf}) + puts (%{#{_out_path}/#{file_basename}.pdf}) + else + puts "issue with pdf file or output directory" + puts "pdf file: #{pwd}/#{file_basename}.pdf}" + puts "output dir: #{_out_path}/" + end + suffix = ['log', 'out', 'toc', 'aux'] + suffix.each { |s| FileUtils::rm_f(%{#{pwd}/#{file_basename}.#{s}})} + end + end + end +end +Dir.chdir(pwd) +__END__ diff --git a/views/version.txt b/views/version.txt index a432643..05cfccf 100644 --- a/views/version.txt +++ b/views/version.txt @@ -4,7 +4,7 @@ struct Version { int minor; int patch; } -enum _ver = Version(0, 9, 2); +enum _ver = Version(0, 10, 0); version (Posix) { version (DigitalMars) { } else version (LDC) { -- cgit v1.2.3