/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) 1995-2013 Index Data
* See the file LICENSE for details.
*/
/**
#include <assert.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
#include <yaz/rpn2solr.h>
#include <yaz/xmalloc.h>
#include <yaz/diagsrw.h>
};
-/* TODO Utility functions, evt. split out int separate file */
+/* TODO Utility functions, split out into separate file */
int solr_strcmp(const char *s1, const char *s2) {
return cql_strcmp(s1, s2);
}
}
-/* Utillity functions end */
+/* Utility functions end */
solr_transform_t solr_transform_create(void)
{
int ret = 0; /* 0=OK, != 0 FAIL */
int t;
t = yaz_tok_move(tp);
-
+
while (t == YAZ_TOK_STRING && ae_num < 20)
{
WRBUF type_str = wrbuf_alloc();
Z_AttributeElement *elem = 0;
const char *value_str = 0;
/* attset type=value OR type=value */
-
+
elem = (Z_AttributeElement *) nmem_malloc(ct->nmem, sizeof(*elem));
elem->attributeSet = 0;
ae[ae_num] = elem;
{
wrbuf_destroy(type_str);
if (set_str)
- wrbuf_destroy(set_str);
+ wrbuf_destroy(set_str);
break;
}
- if (t == YAZ_TOK_STRING)
- {
+ if (t == YAZ_TOK_STRING)
+ {
wrbuf_puts(ct->w, " ");
wrbuf_puts(ct->w, yaz_tok_parse_string(tp));
set_str = type_str;
-
+
elem->attributeSet =
yaz_string_to_oid_nmem(yaz_oid_std(), CLASS_ATTSET,
wrbuf_cstr(set_str), ct->nmem);
-
+
type_str = wrbuf_alloc();
wrbuf_puts(type_str, yaz_tok_parse_string(tp));
t = yaz_tok_move(tp);
{
wrbuf_destroy(type_str);
if (set_str)
- wrbuf_destroy(set_str);
+ wrbuf_destroy(set_str);
yaz_log(YLOG_WARN, "Expected numeric attribute type");
ret = -1;
break;
wrbuf_destroy(type_str);
if (set_str)
- wrbuf_destroy(set_str);
-
+ wrbuf_destroy(set_str);
+
if (t != '=')
{
yaz_log(YLOG_WARN, "Expected = after after attribute type");
break;
}
value_str = yaz_tok_parse_string(tp);
- if (isdigit(*value_str))
+ if (yaz_isdigit(*value_str))
{
elem->which = Z_AttributeValue_numeric;
elem->value.numeric =
(*pp)->attr_list.attributes = (Z_AttributeElement **)
nmem_malloc(ct->nmem,
ae_num * sizeof(Z_AttributeElement *));
- memcpy((*pp)->attr_list.attributes, ae,
+ memcpy((*pp)->attr_list.attributes, ae,
ae_num * sizeof(Z_AttributeElement *));
}
(*pp)->next = 0;
yaz_tok_parse_destroy(tp);
return r;
}
-
+
solr_transform_t solr_transform_open_FILE(FILE *f)
{
solr_transform_t ct = solr_transform_create();
z_AttributeElement(odr_a, &a, 0, 0);
z_AttributeElement(odr_b, &b, 0, 0);
-
+
buf_a = odr_getbuf(odr_a, &len_a, 0);
buf_b = odr_getbuf(odr_b, &len_b, 0);
}
if (j == attributes->num_attributes)
break; /* i was not found at all.. try next pattern */
-
+
}
if (i == e->attr_list.num_attributes)
return e->pattern + clen;
}
return 0;
}
-
+
static const char *solr_lookup_property(solr_transform_t ct,
const char *pat1, const char *pat2,
const char *pat3)
sprintf(pattern, "%.39s", pat1);
else
return 0;
-
+
for (e = ct->entry; e; e = e->next)
{
if (!solr_strcmp(e->pattern, pattern))
const char *res = 0;
const char *eval = val ? val : default_val;
const char *prefix = 0;
-
+
if (uri)
{
struct solr_prop_entry *e;
-
+
for (e = ct->entry; e; e = e->next)
if (!memcmp(e->pattern, "set.", 4) && e->value &&
!strcmp(e->value, uri))
void *client_data)
{
int exclusion = 0;
- int distance; /* to be filled in later depending on unit */
- int distance_defined = 0;
+ int distance = -1;
int ordered = 0;
int proxrel = 2; /* less than or equal */
int unit = 2; /* word */
if (!strcmp(name, "distance")) {
distance = strtol(term, (char**) 0, 0);
- distance_defined = 1;
if (!strcmp(relation, "="))
proxrel = 3;
else if (!strcmp(relation, ">"))
proxrel = 5;
else if (!strcmp(relation, "<"))
proxrel = 1;
- else if (!strcmp(relation, ">="))
+ else if (!strcmp(relation, ">="))
proxrel = 4;
else if (!strcmp(relation, "<="))
proxrel = 2;
else if (!strcmp(relation, "<>"))
proxrel = 6;
- else
+ else
{
ct->error = YAZ_SRW_UNSUPP_PROX_RELATION;
ct->addinfo = xstrdup(relation);
return 0;
}
- }
+ }
else if (!strcmp(name, "ordered"))
ordered = 1;
else if (!strcmp(name, "unordered"))
unit = 4;
else if (!strcmp(term, "element"))
unit = 8;
- else
+ else
{
ct->error = YAZ_SRW_UNSUPP_PROX_UNIT;
ct->addinfo = xstrdup(term);
return 0;
}
- }
- else
+ }
+ else
{
ct->error = YAZ_SRW_UNSUPP_BOOLEAN_MODIFIER;
ct->addinfo = xstrdup(name);
mods = mods->u.st.modifiers;
}
- if (!distance_defined)
+ if (distance == -1)
distance = (unit == 2) ? 1 : 0;
solr_pr_int(exclusion, pr, client_data);
* there's no mapping for it, that's fine: we just use a
* general pattern-matching attribute.
*/
- if (first_wc == term && second_wc == term + length-1
- && *first_wc == '*' && *second_wc == '*'
+ if (first_wc == term && second_wc == term + length-1
+ && *first_wc == '*' && *second_wc == '*'
&& solr_pr_attr(ct, "truncation", "both", 0, pr, client_data, 0))
{
term++;
(*pr)("@", client_data);
(*pr)(op, client_data);
(*pr)(" ", client_data);
- }
+ }
emit_term(ct, cn, ne->u.st.term, strlen(ne->u.st.term),
pr, client_data);
}
(*pr)(cn->u.boolean.value, client_data);
(*pr)(" ", client_data);
mods = cn->u.boolean.modifiers;
- if (!strcmp(cn->u.boolean.value, "prox"))
+ if (!strcmp(cn->u.boolean.value, "prox"))
{
if (!solr_pr_prox(ct, mods, pr, client_data))
return;
- }
+ }
else if (mods)
{
/* Boolean modifiers other than on proximity not supported */