X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=util%2Fpquery.c;h=52862913eac49d8dd5514a41c7a7f787fae34097;hb=01dfe62210bac0f8fc1e566537ad99bbc378bd66;hp=e57b2a16e364681b1b589e2457a6fe3354167bef;hpb=7b57148e0984b3df36e031d866bfc461703160e3;p=yaz-moved-to-github.git diff --git a/util/pquery.c b/util/pquery.c index e57b2a1..5286291 100644 --- a/util/pquery.c +++ b/util/pquery.c @@ -1,10 +1,16 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1996, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: pquery.c,v $ - * Revision 1.9 1996-03-15 11:03:46 adam + * Revision 1.11 1996-11-11 13:15:29 adam + * Added proximity operator. + * + * Revision 1.10 1996/08/12 14:10:35 adam + * New function p_query_attset to define default attribute set. + * + * Revision 1.9 1996/03/15 11:03:46 adam * Attribute set can be set globally for a query with the @attrset * operator. The @attr operator has an optional attribute-set specifier * that sets the attribute set locally. @@ -44,6 +50,8 @@ #include +static oid_value p_query_dfset = VAL_NONE; + static const char *query_buf; static const char *query_lex_buf; static int query_lex_len; @@ -113,6 +121,8 @@ static int query_token (const char **qptr, const char **lex_buf, int *lex_len) return 's'; if (*lex_len == 8 && !memcmp (*lex_buf+1, "attrset", 7)) return 'r'; + if (*lex_len == 5 && !memcmp (*lex_buf+1, "prox", 4)) + return 'p'; } return 't'; } @@ -215,6 +225,57 @@ static Z_Operand *rpn_simple (ODR o, oid_proto proto, return zo; } +static Z_ProximityOperator *rpn_proximity (ODR o) +{ + Z_ProximityOperator *p = odr_malloc (o, sizeof(*p)); + + if (!lex ()) + return NULL; + if (*query_lex_buf == '1') + { + p->exclusion = odr_malloc (o, sizeof(*p->exclusion)); + *p->exclusion = 1; + } + else if (*query_lex_buf == '0') + { + p->exclusion = odr_malloc (o, sizeof(*p->exclusion)); + *p->exclusion = 0; + } + else + p->exclusion = NULL; + + if (!lex ()) + return NULL; + p->distance = odr_malloc (o, sizeof(*p->distance)); + *p->distance = atoi (query_lex_buf); + + if (!lex ()) + return NULL; + p->ordered = odr_malloc (o, sizeof(*p->ordered)); + *p->ordered = atoi (query_lex_buf); + + if (!lex ()) + return NULL; + p->relationType = odr_malloc (o, sizeof(*p->relationType)); + *p->relationType = atoi (query_lex_buf); + + if (!lex ()) + return NULL; + if (*query_lex_buf == 'k') + p->which = 0; + else if (*query_lex_buf == 'p') + p->which = 1; + else + p->which = atoi (query_lex_buf); + + if (!lex ()) + return NULL; + p->proximityUnitCode = odr_malloc (o, sizeof(*p->proximityUnitCode)); + *p->proximityUnitCode = atoi (query_lex_buf); + + return p; +} + static Z_Complex *rpn_complex (ODR o, oid_proto proto, int num_attr, int max_attr, int *attr_list, oid_value *attr_set) @@ -239,6 +300,12 @@ static Z_Complex *rpn_complex (ODR o, oid_proto proto, zo->which = Z_Operator_and_not; zo->u.and = ODR_NULLVAL; break; + case 'p': + zo->which = Z_Operator_prox; + zo->u.prox = rpn_proximity (o); + if (!zo->u.prox) + return NULL; + break; default: return NULL; } @@ -265,6 +332,7 @@ static Z_RPNStructure *rpn_structure (ODR o, oid_proto proto, case 'a': case 'o': case 'n': + case 'p': sz->which = Z_RPNStructure_complex; if (!(sz->u.complex = rpn_complex (o, proto, num_attr, max_attr, attr_list, attr_set))) @@ -332,6 +400,8 @@ Z_RPNQuery *p_query_rpn (ODR o, oid_proto proto, const char *qbuf) lex (); } if (topSet == VAL_NONE) + topSet = p_query_dfset; + if (topSet == VAL_NONE) topSet = VAL_BIB1; oset.proto = proto; oset.oclass = CLASS_ATTSET; @@ -368,6 +438,8 @@ Z_AttributesPlusTerm *p_query_scan (ODR o, oid_proto proto, lex (); } if (topSet == VAL_NONE) + topSet = p_query_dfset; + if (topSet == VAL_NONE) topSet = VAL_BIB1; oset.proto = proto; oset.oclass = CLASS_ATTSET; @@ -409,3 +481,9 @@ Z_AttributesPlusTerm *p_query_scan (ODR o, oid_proto proto, return rpn_term (o, proto, num_attr, attr_list, attr_set); } +int p_query_attset (const char *arg) +{ + p_query_dfset = oid_getvalbyname (arg); + return (p_query_dfset == VAL_NONE) ? -1 : 0; +} +