Directive s=pw sets structure to phrase if term includes blank(s).
[yaz-moved-to-github.git] / zutil / pquery.c
index a302244..92e45d4 100644 (file)
@@ -4,7 +4,23 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: pquery.c,v $
- * Revision 1.1  1999-06-08 10:10:16  adam
+ * Revision 1.6  2001-03-07 13:24:40  adam
+ * Member and_not in Z_Operator is kept for backwards compatibility.
+ * Added support for definition of CCL operators in field spec file.
+ *
+ * Revision 1.5  2001/02/21 13:46:54  adam
+ * C++ fixes.
+ *
+ * Revision 1.4  1999/12/21 16:25:20  adam
+ * Fixed handling of default/inherited attributes.
+ *
+ * Revision 1.3  1999/12/20 15:20:13  adam
+ * Implemented ccl_pquery to convert from CCL tree to prefix query.
+ *
+ * Revision 1.2  1999/11/30 13:47:12  adam
+ * Improved installation. Moved header files to include/yaz.
+ *
+ * Revision 1.1  1999/06/08 10:10:16  adam
  * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
  *
  * Revision 1.22  1999/04/20 09:56:49  adam
 #include <string.h>
 #include <stdlib.h>
 
-#include <proto.h>
-#include <oid.h>
-
-#include <pquery.h>
+#include <yaz/proto.h>
+#include <yaz/oid.h>
+#include <yaz/pquery.h>
 
 static oid_value p_query_dfset = VAL_NONE;
 
@@ -207,7 +222,7 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o,
         elements = (Z_AttributeElement**)odr_nullval();
     else
     {
-        int i;
+        int i, k = 0;
         int *attr_tmp;
 
         elements = (Z_AttributeElement**)
@@ -215,13 +230,19 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o,
 
         attr_tmp = (int *)odr_malloc (o, num_attr * 2 * sizeof(int));
         memcpy (attr_tmp, attr_list, num_attr * 2 * sizeof(int));
-        for (i = 0; i < num_attr; i++)
+        for (i = num_attr; --i >= 0; )
         {
-            elements[i] =
+            int j;
+            for (j = i+1; j<num_attr; j++)
+                if (attr_tmp[2*j] == attr_tmp[2*i])
+                    break;
+            if (j < num_attr)
+                continue;
+            elements[k] =
                 (Z_AttributeElement*)odr_malloc (o,sizeof(**elements));
-            elements[i]->attributeType = &attr_tmp[2*i];
+            elements[k]->attributeType = &attr_tmp[2*i];
             if (attr_set[i] == VAL_NONE)
-                elements[i]->attributeSet = 0;
+                elements[k]->attributeSet = 0;
             else
             {
                 oident attrid;
@@ -231,12 +252,14 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o,
                 attrid.oclass = CLASS_ATTSET;
                 attrid.value = attr_set[i];
                    
-                elements[i]->attributeSet =
+                elements[k]->attributeSet =
                    odr_oiddup (o, oid_ent_to_oid (&attrid, oid));
             }
-           elements[i]->which = Z_AttributeValue_numeric;
-           elements[i]->value.numeric = &attr_tmp[2*i+1];
+           elements[k]->which = Z_AttributeValue_numeric;
+           elements[k]->value.numeric = &attr_tmp[2*i+1];
+            k++;
         }
+        num_attr = k;
     }
 #ifdef ASN_COMPILED
     zapt->attributes = (Z_AttributeList *)
@@ -359,15 +382,15 @@ static Z_Complex *rpn_complex (struct lex_info *li, ODR o, oid_proto proto,
     {
     case 'a':
         zo->which = Z_Operator_and;
-        zo->u.and = odr_nullval();
+        zo->u.and_not = odr_nullval();
         break;
     case 'o':
         zo->which = Z_Operator_or;
-        zo->u.and = odr_nullval();
+        zo->u.and_not = odr_nullval();
         break;
     case 'n':
         zo->which = Z_Operator_and_not;
-        zo->u.and = odr_nullval();
+        zo->u.and_not = odr_nullval();
         break;
     case 'p':
         zo->which = Z_Operator_prox;
@@ -443,9 +466,9 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o,
             else
                 attr_set[num_attr] = VAL_NONE;
         }
-        attr_list[2*num_attr] = atoi (li->lex_buf);
-        attr_list[2*num_attr+1] = atoi (cp+1);
-        num_attr++;
+       attr_list[2*num_attr] = atoi(li->lex_buf); 
+       attr_list[2*num_attr+1] = atoi (cp+1);
+       num_attr++;
         lex (li);
         return
             rpn_structure (li, o, proto, num_attr, max_attr, attr_list,