aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/out_cgi_search_sqlite.org
diff options
context:
space:
mode:
Diffstat (limited to 'org/out_cgi_search_sqlite.org')
-rw-r--r--org/out_cgi_search_sqlite.org56
1 files changed, 50 insertions, 6 deletions
diff --git a/org/out_cgi_search_sqlite.org b/org/out_cgi_search_sqlite.org
index 04d0c47..58375bf 100644
--- a/org/out_cgi_search_sqlite.org
+++ b/org/out_cgi_search_sqlite.org
@@ -156,18 +156,23 @@ mixin GenericMain!cgi_function_intro;
// Handle error
}
}
- { // cgi.d
+ { // get cgi.d
import std.net.curl, std.stdio;
+ char[] cgi_d;
try {
- auto cgi_d = get("https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d");
+ cgi_d = get!HTTP("https://raw.githubusercontent.com/adamdruppe/arsd/master/cgi.d");
+ } catch (ErrnoException ex) {
+ // Handle error
+ // CurlCode perform(ThrowOnError throwOnError = Yes.throwOnError);
+ CurlCode perform(ThrowOnError throwOnError = No.throwOnError);
+ }
+ if (cgi_d && cgi_d.length > 0) {
try {
auto f = File(pth_sqlite_cgi.cgi_d_path_out, "w");
f.write(cgi_d);
} catch (ErrnoException ex) {
// Handle error
}
- } catch (ErrnoException ex) {
- // Handle error
}
}
}
@@ -1544,6 +1549,45 @@ auto db = Database(conf.db_path ~ cv.db_selected);
return sql_match_offset_count;
}
void sql_search_query() {
+ string highlight_text_matched(string _txt, string search_field) {
+ string _mark_open = "┤";
+ string _mark_close = "├";
+ string _span_yellow = "<span style=\"background-color: #ffff48\">";
+ string _span_red = "<span style=\"background-color: #ff48ff\">";
+ string _span_blue = "<span style=\"background-color: #48ffff\">";
+ string _span_close = "</span>";
+ string _sf_str = search_field.strip.split("%%20").join(" ").strip;
+ string[] _sf_arr = _sf_str.split(regex(r"\s+AND\s+|\s+OR\s+"));
+ auto rgx_url = regex(r"<a href=[^>]+?>");
+ foreach (_sf; _sf_arr) {
+ auto rgx_matched_text = regex(_sf, "i");
+ auto rgx_marked_pair = regex(r"┤(?P<keep>" ~ _sf ~ ")├", "i");
+ if (auto m = _txt.matchFirst(rgx_url)) {
+ _txt = replaceAll!(m =>
+ _mark_open
+ ~ m.captures[0]
+ ~ _mark_close
+ )(_txt, rgx_matched_text);
+ _txt = replaceAll!(m =>
+ replaceAll!(u =>
+ u["keep"]
+ )(m.hit, rgx_marked_pair)
+ )(_txt, rgx_url);
+ _txt = replaceAll!(m =>
+ _span_yellow
+ ~ m["keep"]
+ ~ _span_close
+ )(_txt, rgx_marked_pair);
+ } else {
+ _txt = replaceAll!(m =>
+ _span_yellow
+ ~ m.captures[0]
+ ~ _span_close
+ )(_txt, rgx_matched_text);
+ }
+ }
+ return _txt;
+ }
string select_field_like(string db_field, string search_field) {
string where_ = "";
if (!(search_field.empty)) {
@@ -1679,7 +1723,7 @@ LIMIT %%s OFFSET %%s
~ row["ocn"].as!string
~ "</a>"
~ "<br>"
- ~ row["body"].as!string
+ ~ highlight_text_matched(row["body"].as!string, tf.text)
);
} else {
cgi.write(
@@ -1691,7 +1735,7 @@ LIMIT %%s OFFSET %%s
~ row["ocn"].as!string
~ "</a>"
~ "<br>"
- ~ row["body"].as!string
+ ~ highlight_text_matched(row["body"].as!string, tf.text)
);
}
#+END_SRC