// Associates a set of clients with a session;
// Note: Session-databases represent databases with per-session
// setting overrides
-int select_targets(struct session *se, struct database_criterion *crit)
+static int select_targets(struct session *se, const char *filter)
{
while (se->clients)
client_destroy(se->clients);
- return session_grep_databases(se, crit, select_targets_callback);
+ return session_grep_databases(se, filter, select_targets_callback);
}
int session_active_clients(struct session *s)
return res;
}
-// parses crit1=val1,crit2=val2|val3,...
-static struct database_criterion *parse_filter(NMEM m, const char *buf)
-{
- struct database_criterion *res = 0;
- char **values;
- int num;
- int i;
-
- if (!buf || !*buf)
- return 0;
- nmem_strsplit(m, ",", buf, &values, &num);
- for (i = 0; i < num; i++)
- {
- char **subvalues;
- int subnum;
- int subi;
- struct database_criterion *new = nmem_malloc(m, sizeof(*new));
- char *eq;
- if ((eq = strchr(values[i], '=')))
- new->type = PAZPAR2_STRING_MATCH;
- else if ((eq = strchr(values[i], '~')))
- new->type = PAZPAR2_SUBSTRING_MATCH;
- else
- {
- yaz_log(YLOG_WARN, "Missing equal-sign/tilde in filter");
- return 0;
- }
- *(eq++) = '\0';
- new->name = values[i];
- nmem_strsplit(m, "|", eq, &subvalues, &subnum);
- new->values = 0;
- for (subi = 0; subi < subnum; subi++)
- {
- struct database_criterion_value *newv
- = nmem_malloc(m, sizeof(*newv));
- newv->value = subvalues[subi];
- newv->next = new->values;
- new->values = newv;
- }
- new->next = res;
- res = new;
- }
- return res;
-}
enum pazpar2_error_code search(struct session *se,
const char *query,
int no_working = 0;
int no_failed = 0;
struct client *cl;
- struct database_criterion *criteria;
yaz_log(YLOG_DEBUG, "Search");
se->total_records = se->total_hits = se->total_merged = 0;
se->reclist = 0;
se->num_termlists = 0;
- criteria = parse_filter(se->nmem, filter);
- live_channels = select_targets(se, criteria);
+ live_channels = select_targets(se, filter);
if (live_channels)
{
se->reclist = reclist_create(se->nmem);
void session_init_databases(struct session *se)
{
se->databases = 0;
- predef_grep_databases(se, se->service, 0, session_init_databases_fun);
+ predef_grep_databases(se, se->service, session_init_databases_fun);
}
// Probably session_init_databases_fun should be refactored instead of
static struct session_database *load_session_database(struct session *se,
char *id)
{
- struct database *db = find_database(id, 0, se->service);
+ struct database *db = find_database(id, se->service);
resolve_database(db);
}
static struct record_metadata *record_metadata_init(
- NMEM nmem, char *value, enum conf_metadata_type type)
+ NMEM nmem, const char *value, enum conf_metadata_type type,
+ struct _xmlAttr *attr)
{
struct record_metadata *rec_md = record_metadata_create(nmem);
+ struct record_metadata_attr **attrp = &rec_md->attributes;
+
+ for (; attr; attr = attr->next)
+ {
+ if (attr->children && attr->children->content)
+ {
+ if (strcmp((const char *) attr->name, "type"))
+ { /* skip the "type" attribute.. Its value is already part of
+ the element in output (md-%s) and so repeating it here
+ is redundant */
+ *attrp = nmem_malloc(nmem, sizeof(**attrp));
+ (*attrp)->name =
+ nmem_strdup(nmem, (const char *) attr->name);
+ (*attrp)->value =
+ nmem_strdup(nmem, (const char *) attr->children->content);
+ attrp = &(*attrp)->next;
+ }
+ }
+ }
+ *attrp = 0;
+
if (type == Metadata_type_generic)
{
- char * p = value;
+ char *p = nmem_strdup(nmem, value);
+
p = normalize7bit_generic(p, " ,/.:([");
- rec_md->data.text.disp = nmem_strdup(nmem, p);
+ rec_md->data.text.disp = p;
rec_md->data.text.sort = 0;
}
else if (type == Metadata_type_year || type == Metadata_type_date)
pp2_relevance_token_t prt =
pp2_relevance_tokenize(
service->mergekey_pct,
- (const char *) value);
+ (const char *) value, 0);
wrbuf_puts(norm_wr, name);
wrbuf_puts(norm_wr, "=");
pp2_relevance_token_t prt =
pp2_relevance_tokenize(
service->mergekey_pct,
- (const char *) mergekey);
+ (const char *) mergekey, 0);
while ((norm_str = pp2_relevance_token_next(prt)))
{
}
// non-merged metadata
- rec_md = record_metadata_init(se->nmem, (char *) value,
- ser_md->type);
+ rec_md = record_metadata_init(se->nmem, (const char *) value,
+ ser_md->type, n->properties);
if (!rec_md)
{
yaz_log(YLOG_WARN, "bad metadata data '%s' for element '%s'",
*wheretoput = rec_md;
// merged metadata
- rec_md = record_metadata_init(se->nmem, (char *) value,
- ser_md->type);
+ rec_md = record_metadata_init(se->nmem, (const char *) value,
+ ser_md->type, 0);
wheretoput = &cluster->metadata[md_field_id];
// and polulate with data:
prt = pp2_relevance_tokenize(
service->sort_pct,
- rec_md->data.text.disp);
+ rec_md->data.text.disp, skip_article);
pp2_relevance_token_next(prt);
- sort_str = pp2_get_sort(prt, skip_article);
+ sort_str = pp2_get_sort(prt);
cluster->sortkeys[sk_field_id]->text.disp =
rec_md->data.text.disp;
// ranking of _all_ fields enabled ...
if (ser_md->rank)
relevance_countwords(se->relevance, cluster,
- (char *) value, ser_md->rank);
+ (char *) value, ser_md->rank,
+ ser_md->name);
// construct facets ...
if (ser_md->termlist)