- switch (zop->which)
- {
- case Z_Operator_and:
- r=rsmultiand_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope,
- 2, rsets);
- break;
- case Z_Operator_or:
- r=rsmultior_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope,
- 2, rsets);
- break;
- case Z_Operator_and_not:
- r = rsbool_create_not(rset_nmem,key_it_ctrl, key_it_ctrl->scope,
- rsets[0],rsets[1]);
- break;
- case Z_Operator_prox:
- if (zop->u.prox->which != Z_ProximityOperator_known)
- {
- zh->errCode = 132;
- return NULL;
- }
- if (*zop->u.prox->u.known != Z_ProxUnit_word)
- {
- char *val = (char *) nmem_malloc(stream, 16);
- zh->errCode = 132;
- zh->errString = val;
- sprintf (val, "%d", *zop->u.prox->u.known);
- return NULL;
- }
- else
- {
- /* new / old prox */
- r=rsprox_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
- 2, rsets,
- *zop->u.prox->ordered,
- (!zop->u.prox->exclusion ?
- 0 : *zop->u.prox->exclusion),
- *zop->u.prox->relationType,
- *zop->u.prox->distance );
- }
- break;
- default:
- zh->errCode = 110;
- return NULL;
- }
+ /* make a new list of result for all children */
+ *num_result_sets = num_result_sets_l + num_result_sets_r;
+ *result_sets = nmem_malloc(stream, *num_result_sets *
+ sizeof(**result_sets));
+ memcpy(*result_sets, result_sets_l,
+ num_result_sets_l * sizeof(**result_sets));
+ memcpy(*result_sets + num_result_sets_l, result_sets_r,
+ num_result_sets_r * sizeof(**result_sets));
+
+ if (!parent_op || parent_op->which != zop->which
+ || (zop->which != Z_Operator_and &&
+ zop->which != Z_Operator_or))
+ {
+ /* parent node different from this one (or non-present) */
+ /* we must combine result sets now */
+ RSET rset;
+ switch (zop->which)
+ {
+ case Z_Operator_and:
+ rset = rsmulti_and_create(rset_nmem, kc,
+ kc->scope,
+ *num_result_sets, *result_sets);
+ break;
+ case Z_Operator_or:
+ rset = rsmulti_or_create(rset_nmem, kc,
+ kc->scope,
+ *num_result_sets, *result_sets);
+ break;
+ case Z_Operator_and_not:
+ rset = rsbool_create_not(rset_nmem, kc,
+ kc->scope,
+ (*result_sets)[0],
+ (*result_sets)[1]);
+ break;
+ case Z_Operator_prox:
+ if (zop->u.prox->which != Z_ProximityOperator_known)
+ {
+ zh->errCode = YAZ_BIB1_UNSUPP_PROX_UNIT_CODE;
+ return ZEBRA_FAIL;
+ }
+ if (*zop->u.prox->u.known != Z_ProxUnit_word)
+ {
+ char *val = (char *) nmem_malloc(stream, 16);
+ zh->errCode = YAZ_BIB1_UNSUPP_PROX_UNIT_CODE;
+ zh->errString = val;
+ sprintf(val, "%d", *zop->u.prox->u.known);
+ return ZEBRA_FAIL;
+ }
+ else
+ {
+ rset = rsprox_create(rset_nmem, kc,
+ kc->scope,
+ *num_result_sets, *result_sets,
+ *zop->u.prox->ordered,
+ (!zop->u.prox->exclusion ?
+ 0 : *zop->u.prox->exclusion),
+ *zop->u.prox->relationType,
+ *zop->u.prox->distance );
+ }
+ break;
+ default:
+ zh->errCode = YAZ_BIB1_OPERATOR_UNSUPP;
+ return ZEBRA_FAIL;
+ }
+ *num_result_sets = 1;
+ *result_sets = nmem_malloc(stream, *num_result_sets *
+ sizeof(**result_sets));
+ (*result_sets)[0] = rset;
+ }