diff options
| author | arf20 <aruizfernandez05@gmail.com> | 2025-12-01 22:40:25 +0100 |
|---|---|---|
| committer | arf20 <aruizfernandez05@gmail.com> | 2025-12-01 22:40:25 +0100 |
| commit | 262c4593ac6df668ed4d4d899c68a256fb237214 (patch) | |
| tree | 81ecfd72099fc4d7def7a80ba73a7d0d5998cffc | |
| parent | 058f3f3af1f3f15d2dacc04df8bc339301cf3a7c (diff) | |
| download | arfnet2-search-262c4593ac6df668ed4d4d899c68a256fb237214.tar.gz arfnet2-search-262c4593ac6df668ed4d4d899c68a256fb237214.zip | |
wip querying
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | index.c | 37 | ||||
| -rw-r--r-- | index.h | 4 | ||||
| -rw-r--r-- | index.htm.tmpl | 2 | ||||
| -rw-r--r-- | main.c | 36 | ||||
| -rwxr-xr-x | search | bin | 35488 -> 46312 bytes |
6 files changed, 69 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..06d845c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +search @@ -183,7 +183,7 @@ index_new(size_t icapacity, const char *dir, int examine) /* recurse */ map_t *child = NULL; if (de->d_type == DT_DIR) { - index_new(icapacity, path); + index_new(icapacity, path, examine); } map_insert(map, de->d_name, data, child); @@ -192,7 +192,7 @@ index_new(size_t icapacity, const char *dir, int examine) return map; } -int +void index_lookup_substr(map_t *index, const char *query, results_t *results) { @@ -200,12 +200,29 @@ index_lookup_substr(map_t *index, const char *query, if (!index->map[i].data) continue; - for (struct node_s *node = &index->map[i]; node->next; node = node->next) - if (strstr(node->data.name, query)) - results_insert(results, ) + for (struct node_s *node = &index->map[i]; node->next; node = node->next) { + if (strstr(node->data->name, query)) + results_insert(results, node->data); + if (node->child) + index_lookup_substr(node->child, query, results); + } } } +void +index_lookup_substr_nocase(map_t *index, const char *query, + results_t *results) +{ + +} + +void +index_lookup_regex(map_t *index, const char *query, + results_t *results) +{ + +} + results_t * index_lookup(map_t *index, lookup_type_t type, const char *query) { @@ -213,10 +230,18 @@ index_lookup(map_t *index, lookup_type_t type, const char *query) switch (type) { case LOOKUP_SUBSTR: - return index_lookup_substr(index, query, results); + index_lookup_substr(index, query, results); + break; + case LOOKUP_SUBSTR_NOCASE: + index_lookup_substr_nocase(index, query, results); + break; + case LOOKUP_REGEX: + index_lookup_regex(index, query, results); break; } + + return results; } void @@ -47,8 +47,8 @@ typedef struct { int index_init(); void index_deinit(); -index_t index_new(size_t icapacity, const char *root); -results_t index_lookup(index_t index, lookup_type_t type, const char *query); +index_t index_new(size_t icapacity, const char *root, int examine); +results_t *index_lookup(index_t index, lookup_type_t type, const char *query); void index_destroy(index_t index); #endif /* _INDEX_H */ diff --git a/index.htm.tmpl b/index.htm.tmpl index 03f228b..1443aa0 100644 --- a/index.htm.tmpl +++ b/index.htm.tmpl @@ -49,7 +49,7 @@ <h2 class="center">Search</h2> <p>Search all of the ARFNET content fast</p> <div class="box"> - <form class="form-inline" action="/" method="get"> + <form class="form-inline" action="/query" method="get"> <input class="input" type="text" name="query"> <button type="submit">Search</button> </form> @@ -39,6 +39,8 @@ static char *index_format_template = NULL; +static index_t g_index = NULL; + enum MHD_Result answer_to_connection( void *cls, struct MHD_Connection *connection, @@ -77,6 +79,25 @@ enum MHD_Result answer_to_connection( ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); } + else if (strcmp(method, "GET") == 0 && strcmp(url, "/query") == 0) { + snprintf(buff, BUFF_SIZE, + index_format_template); + + const char *query = MHD_lookup_connection_value(connection, + MHD_GET_ARGUMENT_KIND, "query"); + + results_t *results = index_lookup(g_index, LOOKUP_SUBSTR, query); + printf("results\n"); + for (size_t i = 0; i < results->size; i++) + printf("\t%s\n", results->results[i]->name); + + response = MHD_create_response_from_buffer(strlen(buff), (void*)buff, + MHD_RESPMEM_PERSISTENT); + + printf("%d\n", 200); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); + } else { response = MHD_create_response_from_buffer(0, (void*)NULL, 0); printf("%d\n", 418); @@ -124,9 +145,20 @@ int main() { if (index_init() < 0) return 1; - index_t index = index_new(INIT_MAP_CAPACITY, root); + time_t time_now = time(NULL); + struct tm *tm_now = gmtime(&time_now); + static char timestr[256]; + strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now); + + printf("[%s] [index] indexeding started...\n", timestr); + + g_index = index_new(INIT_MAP_CAPACITY, root, 0); + + time_now = time(NULL); + tm_now = gmtime(&time_now); + strftime(timestr, 256, "%Y-%m-%d %H:%M:%S", tm_now); - printf("[index] indexed\n"); + printf("[%s] [index] indexed finished\n", timestr); while (1) { sleep(1000); Binary files differ |
