diff options
| author | 2024-05-15 05:57:21 +0200 | |
|---|---|---|
| committer | 2024-05-15 05:57:21 +0200 | |
| commit | 34311714ce725da9fae9fea3b29a4988977c79bd (patch) | |
| tree | e834d3f2bdc6e3d54ab4dc0f101e0650e139f3f0 | |
| parent | content_search() also searches the instance timeline. (diff) | |
| download | snac2-34311714ce725da9fae9fea3b29a4988977c79bd.tar.gz snac2-34311714ce725da9fae9fea3b29a4988977c79bd.tar.xz snac2-34311714ce725da9fae9fea3b29a4988977c79bd.zip | |
User search can also be done by tag.
| -rw-r--r-- | html.c | 57 | ||||
| -rw-r--r-- | httpd.c | 2 |
2 files changed, 39 insertions, 20 deletions
| @@ -748,7 +748,7 @@ static xs_html *html_user_body(snac *user, int read_only) | |||
| 748 | xs_html_sctag("input", | 748 | xs_html_sctag("input", |
| 749 | xs_html_attr("type", "text"), | 749 | xs_html_attr("type", "text"), |
| 750 | xs_html_attr("name", "q"), | 750 | xs_html_attr("name", "q"), |
| 751 | xs_html_attr("title", L("Search posts by content (regular expression)")), | 751 | xs_html_attr("title", L("Search posts by content (regular expression) or #tag")), |
| 752 | xs_html_attr("placeholder", L("Content search"))))); | 752 | xs_html_attr("placeholder", L("Content search"))))); |
| 753 | } | 753 | } |
| 754 | 754 | ||
| @@ -2588,25 +2588,44 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2588 | char *q = xs_dict_get(q_vars, "q"); | 2588 | char *q = xs_dict_get(q_vars, "q"); |
| 2589 | 2589 | ||
| 2590 | if (q && *q) { | 2590 | if (q && *q) { |
| 2591 | /** search by content **/ | 2591 | if (*q == '#') { |
| 2592 | int to = 0; | 2592 | /** search by tag **/ |
| 2593 | int msecs = atoi(xs_dict_get_def(q_vars, "msecs", "0")); | 2593 | xs *tl = tag_search(q, skip, show + 1); |
| 2594 | xs *tl = content_search(&snac, q, 1, skip, show, msecs, &to); | 2594 | int more = 0; |
| 2595 | xs *title = NULL; | 2595 | if (xs_list_len(tl) >= show + 1) { |
| 2596 | xs *page = xs_fmt("/admin?q=%s&msecs=%d", q, msecs + 10); | 2596 | /* drop the last one */ |
| 2597 | int tl_len = xs_list_len(tl); | 2597 | tl = xs_list_del(tl, -1); |
| 2598 | 2598 | more = 1; | |
| 2599 | if (tl_len) | 2599 | } |
| 2600 | title = xs_fmt(L("Search results for '%s'"), q); | ||
| 2601 | else | ||
| 2602 | if (skip) | ||
| 2603 | title = xs_fmt(L("No more matches for '%s'"), q); | ||
| 2604 | else | ||
| 2605 | title = xs_fmt(L("Nothing found for '%s'"), q); | ||
| 2606 | 2600 | ||
| 2607 | *body = html_timeline(&snac, tl, 0, skip, tl_len, to || tl_len == show, title, page, 0); | 2601 | xs *page = xs_fmt("/admin?q=%%23%s", q + 1); |
| 2608 | *b_size = strlen(*body); | 2602 | xs *title = xs_fmt(L("Search results for tag %s"), q); |
| 2609 | status = 200; | 2603 | |
| 2604 | *body = html_timeline(&snac, tl, 0, skip, show, more, title, page, 0); | ||
| 2605 | *b_size = strlen(*body); | ||
| 2606 | status = 200; | ||
| 2607 | } | ||
| 2608 | else { | ||
| 2609 | /** search by content **/ | ||
| 2610 | int to = 0; | ||
| 2611 | int msecs = atoi(xs_dict_get_def(q_vars, "msecs", "0")); | ||
| 2612 | xs *tl = content_search(&snac, q, 1, skip, show, msecs, &to); | ||
| 2613 | xs *title = NULL; | ||
| 2614 | xs *page = xs_fmt("/admin?q=%s&msecs=%d", q, msecs + 10); | ||
| 2615 | int tl_len = xs_list_len(tl); | ||
| 2616 | |||
| 2617 | if (tl_len) | ||
| 2618 | title = xs_fmt(L("Search results for '%s'"), q); | ||
| 2619 | else | ||
| 2620 | if (skip) | ||
| 2621 | title = xs_fmt(L("No more matches for '%s'"), q); | ||
| 2622 | else | ||
| 2623 | title = xs_fmt(L("Nothing found for '%s'"), q); | ||
| 2624 | |||
| 2625 | *body = html_timeline(&snac, tl, 0, skip, tl_len, to || tl_len == show, title, page, 0); | ||
| 2626 | *b_size = strlen(*body); | ||
| 2627 | status = 200; | ||
| 2628 | } | ||
| 2610 | } | 2629 | } |
| 2611 | else { | 2630 | else { |
| 2612 | double t = history_mtime(&snac, "timeline.html_"); | 2631 | double t = history_mtime(&snac, "timeline.html_"); |
| @@ -202,7 +202,7 @@ int server_get_handler(xs_dict *req, const char *q_path, | |||
| 202 | } | 202 | } |
| 203 | else { | 203 | else { |
| 204 | xs *page = xs_fmt("?t=%s", t); | 204 | xs *page = xs_fmt("?t=%s", t); |
| 205 | xs *title = xs_fmt(L("Search results for #%s"), t); | 205 | xs *title = xs_fmt(L("Search results for tag #%s"), t); |
| 206 | *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0); | 206 | *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0); |
| 207 | } | 207 | } |
| 208 | } | 208 | } |