mirror of
https://git.bwaaa.monster/omnisearch
synced 2026-03-25 17:19:02 +02:00
Compare commits
2 Commits
8b7b8de06c
...
783a58d954
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
783a58d954 | ||
|
|
e9b01902d9 |
@@ -377,39 +377,6 @@ static char *build_search_href(const char *query, const char *engine_id,
|
|||||||
return href;
|
return href;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *build_result_sources(unsigned int source_mask, ScrapeJob *jobs,
|
|
||||||
int job_count) {
|
|
||||||
size_t needed = 1;
|
|
||||||
int source_count = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < job_count; i++) {
|
|
||||||
if (source_mask & (1u << i)) {
|
|
||||||
needed += strlen(jobs[i].engine->name);
|
|
||||||
if (source_count > 0)
|
|
||||||
needed += strlen(" · ");
|
|
||||||
source_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *sources = (char *)malloc(needed);
|
|
||||||
if (!sources)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
sources[0] = '\0';
|
|
||||||
source_count = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < job_count; i++) {
|
|
||||||
if (source_mask & (1u << i)) {
|
|
||||||
if (source_count > 0)
|
|
||||||
strcat(sources, " · ");
|
|
||||||
strcat(sources, jobs[i].engine->name);
|
|
||||||
source_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
int results_handler(UrlParams *params) {
|
int results_handler(UrlParams *params) {
|
||||||
TemplateContext ctx = new_context();
|
TemplateContext ctx = new_context();
|
||||||
char *raw_query = "";
|
char *raw_query = "";
|
||||||
@@ -674,17 +641,13 @@ int results_handler(UrlParams *params) {
|
|||||||
char ***results_matrix = (char ***)malloc(sizeof(char **) * total_results);
|
char ***results_matrix = (char ***)malloc(sizeof(char **) * total_results);
|
||||||
int *results_inner_counts = (int *)malloc(sizeof(int) * total_results);
|
int *results_inner_counts = (int *)malloc(sizeof(int) * total_results);
|
||||||
char **seen_urls = (char **)malloc(sizeof(char *) * total_results);
|
char **seen_urls = (char **)malloc(sizeof(char *) * total_results);
|
||||||
unsigned int *source_masks =
|
if (!results_matrix || !results_inner_counts || !seen_urls) {
|
||||||
(unsigned int *)calloc(total_results, sizeof(unsigned int));
|
|
||||||
if (!results_matrix || !results_inner_counts || !seen_urls || !source_masks) {
|
|
||||||
if (results_matrix)
|
if (results_matrix)
|
||||||
free(results_matrix);
|
free(results_matrix);
|
||||||
if (results_inner_counts)
|
if (results_inner_counts)
|
||||||
free(results_inner_counts);
|
free(results_inner_counts);
|
||||||
if (seen_urls)
|
if (seen_urls)
|
||||||
free(seen_urls);
|
free(seen_urls);
|
||||||
if (source_masks)
|
|
||||||
free(source_masks);
|
|
||||||
char *html = render_template("results.html", &ctx);
|
char *html = render_template("results.html", &ctx);
|
||||||
if (html) {
|
if (html) {
|
||||||
send_response(html);
|
send_response(html);
|
||||||
@@ -712,7 +675,6 @@ int results_handler(UrlParams *params) {
|
|||||||
for (int k = 0; k < unique_count; k++) {
|
for (int k = 0; k < unique_count; k++) {
|
||||||
if (strcmp(seen_urls[k], display_url) == 0) {
|
if (strcmp(seen_urls[k], display_url) == 0) {
|
||||||
is_duplicate = 1;
|
is_duplicate = 1;
|
||||||
source_masks[k] |= (1u << i);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -752,9 +714,8 @@ int results_handler(UrlParams *params) {
|
|||||||
all_results[i][j].snippet ? strdup(all_results[i][j].snippet)
|
all_results[i][j].snippet ? strdup(all_results[i][j].snippet)
|
||||||
: strdup("");
|
: strdup("");
|
||||||
results_matrix[unique_count][4] = strdup(base_url ? base_url : "");
|
results_matrix[unique_count][4] = strdup(base_url ? base_url : "");
|
||||||
results_matrix[unique_count][5] = NULL;
|
results_matrix[unique_count][5] = strdup("");
|
||||||
|
|
||||||
source_masks[unique_count] = (1u << i);
|
|
||||||
results_inner_counts[unique_count] = RESULT_FIELD_COUNT;
|
results_inner_counts[unique_count] = RESULT_FIELD_COUNT;
|
||||||
|
|
||||||
free(pretty_url);
|
free(pretty_url);
|
||||||
@@ -768,13 +729,6 @@ int results_handler(UrlParams *params) {
|
|||||||
free(all_results[i]);
|
free(all_results[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < unique_count; i++) {
|
|
||||||
results_matrix[i][5] =
|
|
||||||
build_result_sources(source_masks[i], jobs, enabled_engine_count);
|
|
||||||
if (!results_matrix[i][5])
|
|
||||||
results_matrix[i][5] = strdup("");
|
|
||||||
}
|
|
||||||
|
|
||||||
context_set_array_of_arrays(&ctx, "results", results_matrix, unique_count,
|
context_set_array_of_arrays(&ctx, "results", results_matrix, unique_count,
|
||||||
results_inner_counts);
|
results_inner_counts);
|
||||||
|
|
||||||
@@ -843,7 +797,6 @@ int results_handler(UrlParams *params) {
|
|||||||
free(seen_urls[i]);
|
free(seen_urls[i]);
|
||||||
}
|
}
|
||||||
free(seen_urls);
|
free(seen_urls);
|
||||||
free(source_masks);
|
|
||||||
free(results_matrix);
|
free(results_matrix);
|
||||||
free(results_inner_counts);
|
free(results_inner_counts);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ char *pretty_display_url(const char *input) {
|
|||||||
strncpy(temp, start, sizeof(temp) - 1);
|
strncpy(temp, start, sizeof(temp) - 1);
|
||||||
temp[sizeof(temp) - 1] = '\0';
|
temp[sizeof(temp) - 1] = '\0';
|
||||||
|
|
||||||
|
char *query = strchr(temp, '?');
|
||||||
|
if (query) {
|
||||||
|
*query = '\0';
|
||||||
|
input_len = strlen(temp);
|
||||||
|
}
|
||||||
|
|
||||||
if (input_len > 0 && temp[input_len - 1] == '/') {
|
if (input_len > 0 && temp[input_len - 1] == '/') {
|
||||||
temp[input_len - 1] = '\0';
|
temp[input_len - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,12 +294,7 @@ h1 span {
|
|||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
.result-sources {
|
|
||||||
color:var(--text-secondary);
|
|
||||||
display:block;
|
|
||||||
font-size:0.78rem;
|
|
||||||
margin-bottom:8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.result-favicon {
|
.result-favicon {
|
||||||
|
|||||||
@@ -73,8 +73,6 @@
|
|||||||
<span class="url">
|
<span class="url">
|
||||||
{{result[1]}}
|
{{result[1]}}
|
||||||
</span>
|
</span>
|
||||||
<span class="result-sources">
|
|
||||||
{{result[5]}}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{result[0]}}">
|
<a href="{{result[0]}}">
|
||||||
|
|||||||
Reference in New Issue
Block a user