int startrecs;
int diagnostic;
int preferred;
+ struct suggestions *suggestions;
enum client_state state;
struct show_raw *show_raw;
ZOOM_resultset resultset;
char *id;
};
+struct suggestions {
+ NMEM nmem;
+ int num;
+ char **misspelled;
+ char **suggest;
+};
+
struct show_raw {
int active; // whether this request has been sent to the server
int position;
}
+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;
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"));
}
}
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;
return cl->diagnostic;
}
+const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf)
+{
+ int idx;
+ struct suggestions *suggestions = cl->suggestions;
+ if (!suggestions || suggestions->num == 0) {
+ return "";
+ }
+ for (idx = 0; idx < suggestions->num; idx++) {
+ wrbuf_printf(wrbuf, "<suggest term=\"%s\"", suggestions->suggest[idx]);
+ if (suggestions->misspelled[idx] && suggestions->misspelled[idx]) {
+ wrbuf_puts(wrbuf, suggestions->misspelled[idx]);
+ wrbuf_puts(wrbuf, "</suggest>\n");
+ }
+ else
+ wrbuf_puts(wrbuf, "/>\n");
+ }
+ return wrbuf_cstr(wrbuf);
+}
+
+
void client_set_database(struct client *cl, struct session_database *db)
{
cl->database = db;
}
+struct suggestions* client_suggestions_create(const char* suggestions_string) {
+ if (suggestions_string == 0)
+ return 0;
+ int i;
+ NMEM nmem = nmem_create();
+ struct suggestions *suggestions = nmem_malloc(nmem, sizeof(*suggestions));
+ suggestions->nmem = nmem;
+ suggestions->num = 0;
+ suggestions->misspelled = 0;
+ suggestions->suggest = 0;
+ 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_destroy(cl->suggestions->nmem);
+ cl->suggestions = 0;
+}
+
/*
* Local variables:
* c-basic-offset: 4