X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fclient.c;h=8751137e3e12f20ee08ebb1a32530e0c36928f1f;hb=275d917ce676df4f41fa9fe097154fc5528615a2;hp=39190c0098616c18277b2953239304d6fc4951ef;hpb=e07a5d5dfcf5be4cc9eb3ab91a60866ff0aee09c;p=pazpar2-moved-to-github.git diff --git a/src/client.c b/src/client.c index 39190c0..8751137 100644 --- a/src/client.c +++ b/src/client.c @@ -114,6 +114,7 @@ struct client { int startrecs; int diagnostic; int preferred; + struct suggestions *suggestions; enum client_state state; struct show_raw *show_raw; ZOOM_resultset resultset; @@ -122,6 +123,14 @@ struct client { char *id; }; +struct suggestions { + NMEM nmem; + int num; + char **misspelled; + char **suggest; + char *passthrough; +}; + struct show_raw { int active; // whether this request has been sent to the server int position; @@ -153,6 +162,11 @@ enum client_state client_get_state(struct client *cl) return cl->state; } +void client_set_state_nb(struct client *cl, enum client_state st) +{ + cl->state = st; +} + void client_set_state(struct client *cl, enum client_state st) { int was_active = 0; @@ -170,6 +184,8 @@ void client_set_state(struct client *cl, enum client_state st) client_get_id(cl), no_active); if (no_active == 0) { session_alert_watch(cl->session, SESSION_WATCH_SHOW); + session_alert_watch(cl->session, SESSION_WATCH_BYTARGET); + session_alert_watch(cl->session, SESSION_WATCH_TERMLIST); session_alert_watch(cl->session, SESSION_WATCH_SHOW_PREF); } } @@ -502,6 +518,9 @@ void client_check_preferred_watch(struct client *cl) } +struct suggestions* client_suggestions_create(const char* suggestions_string); +static void client_suggestions_destroy(struct client *cl); + void client_search_response(struct client *cl) { struct connection *co = cl->connection; @@ -524,6 +543,9 @@ void client_search_response(struct client *cl) client_report_facets(cl, resultset); cl->record_offset = cl->startrecs; cl->hits = ZOOM_resultset_size(resultset); + if (cl->suggestions) + client_suggestions_destroy(cl); + cl->suggestions = client_suggestions_create(ZOOM_resultset_option_get(resultset, "suggestions")); } } @@ -534,6 +556,8 @@ void client_got_records(struct client *cl) { client_unlock(cl); session_alert_watch(se, SESSION_WATCH_SHOW); + session_alert_watch(se, SESSION_WATCH_BYTARGET); + session_alert_watch(se, SESSION_WATCH_TERMLIST); session_alert_watch(se, SESSION_WATCH_RECORD); client_lock(cl); } @@ -785,6 +809,7 @@ struct client *client_create(const char *id) cl->state = Client_Disconnected; cl->show_raw = 0; cl->resultset = 0; + cl->suggestions = 0; cl->mutex = 0; pazpar2_mutex_create(&cl->mutex, "client"); cl->preferred = 0; @@ -1165,6 +1190,37 @@ int client_get_diagnostic(struct client *cl) return cl->diagnostic; } +const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf) +{ + /* int idx; */ + struct suggestions *suggestions = cl->suggestions; + + if (!suggestions) { + //yaz_log(YLOG_DEBUG, "No suggestions found"); + return ""; + } + if (suggestions->passthrough) { + yaz_log(YLOG_DEBUG, "Passthrough Suggestions: \n%s\n", suggestions->passthrough); + return suggestions->passthrough; + } + if (suggestions->num == 0) { + return ""; + } + /* + for (idx = 0; idx < suggestions->num; idx++) { + wrbuf_printf(wrbuf, "suggest[idx]); + if (suggestions->misspelled[idx] && suggestions->misspelled[idx]) { + wrbuf_puts(wrbuf, suggestions->misspelled[idx]); + wrbuf_puts(wrbuf, "\n"); + } + else + wrbuf_puts(wrbuf, "/>\n"); + } + */ + return wrbuf_cstr(wrbuf); +} + + void client_set_database(struct client *cl, struct session_database *db) { cl->database = db; @@ -1196,6 +1252,47 @@ void client_set_preferred(struct client *cl, int v) } +struct suggestions* client_suggestions_create(const char* suggestions_string) +{ + int i; + NMEM nmem; + struct suggestions *suggestions; + if (suggestions_string == 0) + return 0; + nmem = nmem_create(); + suggestions = nmem_malloc(nmem, sizeof(*suggestions)); + yaz_log(YLOG_DEBUG, "client target suggestions: %s", suggestions_string); + + suggestions->nmem = nmem; + suggestions->num = 0; + suggestions->misspelled = 0; + suggestions->suggest = 0; + suggestions->passthrough = nmem_strdup_null(nmem, suggestions_string); + + if (suggestions_string) + nmem_strsplit_escape2(suggestions->nmem, "\n", suggestions_string, &suggestions->suggest, + &suggestions->num, 1, '\\', 0); + /* Set up misspelled array */ + suggestions->misspelled = (char **) nmem_malloc(nmem, suggestions->num * sizeof(**suggestions->misspelled)); + /* replace = with \0 .. for each item */ + for (i = 0; i < suggestions->num; i++) + { + char *cp = strchr(suggestions->suggest[i], '='); + if (cp) { + *cp = '\0'; + suggestions->misspelled[i] = cp+1; + } + } + return suggestions; +} + +static void client_suggestions_destroy(struct client *cl) +{ + NMEM nmem = cl->suggestions->nmem; + cl->suggestions = 0; + nmem_destroy(nmem); +} + /* * Local variables: * c-basic-offset: 4