}
}
sdb->map = normalize_cache_get(se->normalize_cache,
- se->service->server->config, s);
+ se->service, s);
if (!sdb->map)
return -1;
}
return res == 0;
}
-void search_sort(struct session *se, const char *field, int increasing)
+static const char *get_strategy_plus_sort(struct client *l, const char *field)
+{
+ struct session_database *sdb = client_get_database(l);
+ struct setting *s;
+
+ const char *strategy_plus_sort = 0;
+
+ for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next)
+ {
+ char *p = strchr(s->name + 3, ':');
+ if (!p)
+ {
+ yaz_log(YLOG_WARN, "Malformed sortmap name: %s", s->name);
+ continue;
+ }
+ p++;
+ if (!strcmp(p, field))
+ {
+ strategy_plus_sort = s->value;
+ break;
+ }
+ }
+ return strategy_plus_sort;
+}
+
+void session_sort(struct session *se, const char *field, int increasing)
{
struct session_sorted_results *sr;
struct client_list *l;
for (l = se->clients; l; l = l->next)
{
struct client *cl = l->client;
- struct session_database *sdb = client_get_database(cl);
- struct setting *s;
- const char *strategy_plus_sort = 0;
-
- for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next)
- {
- char *p = strchr(s->name + 3, ':');
- if (!p)
- {
- yaz_log(YLOG_WARN, "Malformed sortmap name: %s", s->name);
- continue;
- }
- p++;
- if (!strcmp(p, field))
- {
- strategy_plus_sort = s->value;
- break;
- }
- }
-
+ const char *strategy_plus_sort = get_strategy_plus_sort(cl, field);
if (strategy_plus_sort)
{
struct timeval tval;
se->service->z3950_session_timeout,
se->service->server->iochan_man,
&tval))
- {
- char **array;
- int num;
- nmem_strsplit(se->nmem, ":", strategy_plus_sort, &array, &num);
-
- if (num == 2)
- {
- const char *sort_spec = array[1];
- while (*sort_spec == ' ')
- sort_spec++;
- client_start_search(cl, array[0], sort_spec);
- }
- }
+ client_start_search(cl, strategy_plus_sort, increasing);
}
}
session_leave(se);
}
-enum pazpar2_error_code search(struct session *se,
- const char *query,
- const char *startrecs, const char *maxrecs,
- const char *filter,
- const char *limit,
- const char **addinfo)
+enum pazpar2_error_code session_search(struct session *se,
+ const char *query,
+ const char *startrecs,
+ const char *maxrecs,
+ const char *filter,
+ const char *limit,
+ const char **addinfo,
+ const char *sort_field, int increasing)
{
int live_channels = 0;
int no_working = 0;
/* reset list of sorted results and clear to relevance search */
se->sorted_results = nmem_malloc(se->nmem, sizeof(*se->sorted_results));
- se->sorted_results->field = nmem_strdup(se->nmem, "relevance");
- se->sorted_results->increasing = 0;
+ se->sorted_results->field = nmem_strdup(se->nmem, sort_field);
+ se->sorted_results->increasing = increasing;
se->sorted_results->next = 0;
live_channels = select_targets(se, filter);
for (l = se->clients; l; l = l->next)
{
struct client *cl = l->client;
+ const char *strategy_plus_sort = get_strategy_plus_sort(cl, sort_field);
if (maxrecs)
client_set_maxrecs(cl, atoi(maxrecs));
se->service->z3950_session_timeout,
se->service->server->iochan_man,
&tval))
- client_start_search(cl, 0, 0);
+ client_start_search(cl, strategy_plus_sort, increasing);
}
}
facet_limits_destroy(facet_limits);
return session;
}
+const char * client_get_suggestions_xml(struct client *cl, WRBUF wrbuf);
+
static struct hitsbytarget *hitsbytarget_nb(struct session *se,
int *count, NMEM nmem)
{
res[*count].connected = client_get_connection(cl) ? 1 : 0;
session_settings_dump(se, client_get_database(cl), w);
res[*count].settings_xml = nmem_strdup(nmem, wrbuf_cstr(w));
+ wrbuf_rewind(w);
+ wrbuf_puts(w, "");
+ res[*count].suggestions_xml = nmem_strdup(nmem, client_get_suggestions_xml(cl, w));
wrbuf_destroy(w);
(*count)++;
}
for (j = 0; j < num_names; j++)
{
const char *tname;
+
+ wrbuf_puts(c->wrbuf, "<list name=\"");
+ wrbuf_xmlputs(c->wrbuf, names[j]);
+ wrbuf_puts(c->wrbuf, "\">\n");
+
for (i = 0; i < se->num_termlists; i++)
{
tname = se->termlists[i].name;
if (p)
{
int i;
- wrbuf_puts(c->wrbuf, "<list name=\"");
- wrbuf_xmlputs(c->wrbuf, tname);
- wrbuf_puts(c->wrbuf, "\">\n");
for (i = 0; i < len && i < num; i++)
{
// prevent sending empty term elements
p[i]->frequency);
wrbuf_puts(c->wrbuf, "</term>\n");
}
- wrbuf_puts(c->wrbuf, "</list>\n");
}
}
}
tname = "xtargets";
if (num_names > 0 && !strcmp(names[j], tname))
{
- wrbuf_puts(c->wrbuf, "<list name=\"");
- wrbuf_xmlputs(c->wrbuf, tname);
- wrbuf_puts(c->wrbuf, "\">\n");
targets_termlist_nb(c->wrbuf, se, num, c->nmem);
- wrbuf_puts(c->wrbuf, "</list>\n");
}
+ wrbuf_puts(c->wrbuf, "</list>\n");
}
session_leave(se);
nmem_destroy(nmem_tmp);
/* generate unique key if none is not generated already or is empty */
if (wrbuf_len(norm_wr) == 0)
{
- wrbuf_printf(norm_wr, "%s-%d",
+ wrbuf_printf(norm_wr, "position: %s-%d",
client_get_id(cl), record_no);
}
+ else
+ {
+ const char *lead = "content: ";
+ wrbuf_insert(norm_wr, 0, lead, strlen(lead));
+ }
if (wrbuf_len(norm_wr) > 0)
mergekey_norm = nmem_strdup(nmem, wrbuf_cstr(norm_wr));
wrbuf_destroy(norm_wr);
xmlChar *value = 0;
struct session *se = client_get_session(cl);
struct conf_service *service = se->service;
+ int term_factor = 1;
+ struct record_cluster *cluster;
+ struct session_database *sdb = client_get_database(cl);
struct record *record = record_create(se->nmem,
service->num_metadata,
service->num_sortkeys, cl,
}
}
- struct record_cluster *cluster = reclist_insert(se->reclist,
- service,
- record,
- mergekey_norm,
- &se->total_merged);
+ cluster = reclist_insert(se->reclist, service, record,
+ mergekey_norm, &se->total_merged);
if (!cluster)
return -1;
- struct session_database *sdb = client_get_database(cl);
- int term_factor = 1;
- const char *use_term_factor_str =
- session_setting_oneval(sdb, PZ_TERMLIST_TERM_FACTOR);
- if (use_term_factor_str && use_term_factor_str[0] == '1')
{
- int maxrecs = client_get_maxrecs(cl);
- int hits = (int) client_get_hits(cl);
- term_factor = MAX(hits, maxrecs) / MAX(1, maxrecs);
- assert(term_factor >= 1);
- yaz_log(YLOG_DEBUG, "Using term factor: %d (%d / %d)", term_factor, MAX(hits, maxrecs), MAX(1, maxrecs));
+ const char *use_term_factor_str =
+ session_setting_oneval(sdb, PZ_TERMLIST_TERM_FACTOR);
+ if (use_term_factor_str && use_term_factor_str[0] == '1')
+ {
+ int maxrecs = client_get_maxrecs(cl);
+ int hits = (int) client_get_hits(cl);
+ term_factor = MAX(hits, maxrecs) / MAX(1, maxrecs);
+ assert(term_factor >= 1);
+ yaz_log(YLOG_DEBUG, "Using term factor: %d (%d / %d)", term_factor, MAX(hits, maxrecs), MAX(1, maxrecs));
+ }
}
if (global_parameters.dump_records)
// merged metadata
rec_md = record_metadata_init(se->nmem, (const char *) value,
ser_md->type, 0);
+ if (!rec_md)
+ continue;
+
wheretoput = &cluster->metadata[md_field_id];
// and polulate with data: