diff --git a/main.c b/main.c index 4cbdceb..0f6335f 100644 --- a/main.c +++ b/main.c @@ -295,18 +295,22 @@ sendbooks(struct kreq *r) kjson_obj_close(&req); db_book_full_free(b); } if (termz > 0) { - kjson_array_open(&req); const char **terms = kcalloc(termz, sizeof(char *)); initterms(r, terms); - Book **books = kcalloc(10, sizeof(Book)); - int c = db_books_search(r, 10, books, terms, termz, 0); - while (i < 10 && i < c) { + Book **books = kcalloc(per, sizeof(Book)); + int c = db_books_search(r, per, books, terms, termz, 0); + kjson_obj_open(&req); + kjson_putintp(&req, "count", c); + kjson_arrayp_open(&req, "books"); + while (i < per && i < c) { putbook(&req, books[i]); kjson_obj_close(&req); i++; } - // TODO free kjson_array_close(&req); + kjson_obj_close(&req); + free(books); + free(terms); } else { kjson_array_open(&req); BookAdv **books = kcalloc(per, sizeof(BookAdv)); diff --git a/search.html b/search.html index ac3dbf8..0e0d6d8 100644 --- a/search.html +++ b/search.html @@ -30,12 +30,13 @@