X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fclient.c;h=59e06cd1aa67bd274d50c91ca430585aa5d56dca;hb=7d103e1dcbb332af2b4dd725cd7689057eed0092;hp=97b830c7344da97308a783723bec5378bfcb75dc;hpb=3c4dc6d530646720e7bb03cb2c3977b9f4e74e01;p=pazpar2-moved-to-github.git diff --git a/src/client.c b/src/client.c index 97b830c..59e06cd 100644 --- a/src/client.c +++ b/src/client.c @@ -111,6 +111,7 @@ struct client { char *addinfo; // diagnostic info for most resent error Odr_int hits; int record_offset; + int filtered; // When using local:, this will count the number of filtered records. int maxrecs; int startrecs; int diagnostic; @@ -546,11 +547,10 @@ void client_search_response(struct client *cl) } else { - yaz_log(YLOG_DEBUG, "client_search_response: hits " - ODR_INT_PRINTF, cl->hits); client_report_facets(cl, resultset); cl->record_offset = cl->startrecs; cl->hits = ZOOM_resultset_size(resultset); + yaz_log(YLOG_DEBUG, "client_search_response: hits " ODR_INT_PRINTF, cl->hits); if (cl->suggestions) client_suggestions_destroy(cl); cl->suggestions = client_suggestions_create(ZOOM_resultset_option_get(resultset, "suggestions")); @@ -589,8 +589,7 @@ static void client_record_ingest(struct client *cl) else if (ZOOM_record_error(rec, &msg, &addinfo, 0)) { yaz_log(YLOG_WARN, "Record error %s (%s): %s (rec #%d)", - msg, addinfo, client_get_id(cl), - cl->record_offset); + msg, addinfo, client_get_id(cl), cl->record_offset); } else { @@ -609,8 +608,11 @@ static void client_record_ingest(struct client *cl) else { /* OK = 0, -1 = failure, -2 = Filtered */ - if (ingest_record(cl, xmlrec, cl->record_offset, nmem) == -1) + int rc = ingest_record(cl, xmlrec, cl->record_offset, nmem); + if (rc == -1) yaz_log(YLOG_WARN, "Failed to ingest from %s", client_get_id(cl)); + if (rc == -2) + cl->filtered += 1; } nmem_destroy(nmem); } @@ -663,6 +665,7 @@ void client_reingest(struct client *cl) { int i = cl->startrecs; int to = cl->record_offset; + cl->filtered = 0; cl->record_offset = i; for (; i < to; i++) @@ -753,8 +756,14 @@ void client_start_search(struct client *cl) const char *opt_sort = session_setting_oneval(sdb, PZ_SORT); const char *opt_preferred = session_setting_oneval(sdb, PZ_PREFERRED); const char *extra_args = session_setting_oneval(sdb, PZ_EXTRA_ARGS); - char maxrecs_str[24], startrecs_str[24]; + const char *opt_present_chunk = session_setting_oneval(sdb, PZ_PRESENT_CHUNK); ZOOM_query q; + char maxrecs_str[24], startrecs_str[24], present_chunk_str[24]; + int present_chunk = 20; // Default chunk size + if (opt_present_chunk && strcmp(opt_present_chunk,"")) { + present_chunk = atoi(opt_present_chunk); + yaz_log(YLOG_DEBUG, "Present chunk set to %d", present_chunk); + } assert(link); @@ -792,11 +801,16 @@ void client_start_search(struct client *cl) sprintf(maxrecs_str, "%d", cl->maxrecs); ZOOM_connection_option_set(link, "count", maxrecs_str); - if (cl->maxrecs > 20) - ZOOM_connection_option_set(link, "presentChunk", "20"); - else + /* A present_chunk less than 1 will disable chunking. */ + if (present_chunk > 0 && cl->maxrecs > present_chunk) { + sprintf(present_chunk_str, "%d", present_chunk); + ZOOM_connection_option_set(link, "presentChunk", present_chunk_str); + yaz_log(YLOG_DEBUG, "Present chunk set to %s", present_chunk_str); + } + else { ZOOM_connection_option_set(link, "presentChunk", maxrecs_str); - + yaz_log(YLOG_DEBUG, "Present chunk set to %s (maxrecs)", maxrecs_str); + } sprintf(startrecs_str, "%d", cl->startrecs); ZOOM_connection_option_set(link, "start", startrecs_str); @@ -876,6 +890,7 @@ struct client *client_create(const char *id) cl->session = 0; cl->hits = 0; cl->record_offset = 0; + cl->filtered = 0; cl->diagnostic = 0; cl->state = Client_Disconnected; cl->show_raw = 0; @@ -1077,7 +1092,7 @@ static int apply_limit(struct session_database *sdb, for (i = 0; (name = facet_limits_get(facet_limits, i, &value)); i++) { struct setting *s = 0; - + nmem_reset(nmem_tmp); for (s = sdb->settings[PZ_LIMITMAP]; s; s = s->next) { const char *p = strchr(s->name + 3, ':'); @@ -1133,7 +1148,6 @@ static int apply_limit(struct session_database *sdb, break; } } - nmem_reset(nmem_tmp); if (!s) { yaz_log(YLOG_WARN, "Target %s: limit %s used, but no limitmap defined", @@ -1313,11 +1327,26 @@ Odr_int client_get_hits(struct client *cl) return cl->hits; } +Odr_int client_get_approximation(struct client *cl) +{ + if (cl->record_offset > 0) { + Odr_int approx = ((10 * cl->hits * (cl->record_offset - cl->filtered)) / cl->record_offset + 5) /10; + yaz_log(YLOG_LOG, "%s: Approx: %lld * %d / %d = %lld ", client_get_id(cl), cl->hits, cl->record_offset - cl->filtered, cl->record_offset, approx); + return approx; + } + return cl->hits; +} + int client_get_num_records(struct client *cl) { return cl->record_offset; } +int client_get_num_records_filtered(struct client *cl) +{ + return cl->filtered; +} + void client_set_diagnostic(struct client *cl, int diagnostic, const char *addinfo) {