+ bases_ok++;
+ term_dict[prefix_len++] = ')';
+ term_dict[prefix_len++] = 1;
+ term_dict[prefix_len++] = reg_type;
+ yaz_log(YLOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]);
+ term_dict[prefix_len] = '\0';
+ if (!numeric_relation (zh, zapt, &termp, term_dict,
+ attributeSet, grep_info, &max_pos, reg_type,
+ term_dst))
+ return 0;
+ }
+ if (!bases_ok)
+ {
+ zh->errCode = errCode;
+ zh->errString = errString;
+ return -1;
+ }
+ *term_sub = termp;
+ yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
+ return 1;
+}
+
+static RSET rpn_search_APT_numeric (ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type, int xpath_use,
+ int num_bases, char **basenames,
+ NMEM rset_nmem)
+{
+ char term_dst[IT_MAX_WORD+1];
+ const char *termp = termz;
+ RSET rset[60]; /* FIXME - hard-coded magic number */
+ int r, rset_no = 0;
+ struct grep_info grep_info;
+
+ yaz_log(log_level_rpn, "APT_numeric t='%s'",termz);
+ if (grep_info_prepare (zh, zapt, &grep_info, reg_type, stream))
+ return 0;
+ while (1)
+ {
+ yaz_log(YLOG_DEBUG, "APT_numeric termp=%s", termp);
+ grep_info.isam_p_indx = 0;
+ r = numeric_term(zh, zapt, &termp, attributeSet, &grep_info,
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst, xpath_use,
+ stream);
+ if (r < 1)
+ break;
+ yaz_log(YLOG_DEBUG, "term: %s", term_dst);
+ rset[rset_no] = rset_trunc(zh, grep_info.isam_p_buf,
+ grep_info.isam_p_indx, term_dst,
+ strlen(term_dst), rank_type,
+ 0 /* preserve position */,
+ zapt->term->which, rset_nmem,
+ key_it_ctrl,key_it_ctrl->scope);
+ assert (rset[rset_no]);
+ if (++rset_no >= (int) (sizeof(rset)/sizeof(*rset)))
+ break;
+ }
+ grep_info_delete (&grep_info);
+ if (rset_no == 0)
+ return rsnull_create (rset_nmem,key_it_ctrl);
+ if (rset_no == 1)
+ return rset[0];
+ return rsmultiand_create(rset_nmem,key_it_ctrl,key_it_ctrl->scope,
+ rset_no, rset);
+}
+
+static RSET rpn_search_APT_local (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ const char *termz,
+ oid_value attributeSet,
+ NMEM stream,
+ const char *rank_type, NMEM rset_nmem)
+{
+ RSET result;
+ RSFD rsfd;
+ struct it_key key;
+ int sys;
+ result = rstemp_create( rset_nmem,key_it_ctrl,key_it_ctrl->scope,
+ res_get (zh->res, "setTmpDir"),0 );
+ rsfd = rset_open (result, RSETF_WRITE);
+
+ sys = atoi(termz);
+ if (sys <= 0)
+ sys = 1;
+ key.mem[0] = sys;
+ key.mem[1] = 1;
+ key.len = 2;
+ rset_write (rsfd, &key);
+ rset_close (rsfd);
+ return result;
+}
+
+static RSET rpn_sort_spec (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ oid_value attributeSet, NMEM stream,
+ Z_SortKeySpecList *sort_sequence,
+ const char *rank_type)
+{
+ int i;
+ int sort_relation_value;
+ AttrType sort_relation_type;
+ int use_value;
+ AttrType use_type;
+ Z_SortKeySpec *sks;
+ Z_SortKey *sk;
+ Z_AttributeElement *ae;
+ int oid[OID_SIZE];
+ oident oe;
+ char termz[20];
+
+ attr_init (&sort_relation_type, zapt, 7);
+ sort_relation_value = attr_find (&sort_relation_type, &attributeSet);
+
+ attr_init (&use_type, zapt, 1);
+ use_value = attr_find (&use_type, &attributeSet);
+
+ if (!sort_sequence->specs)
+ {
+ sort_sequence->num_specs = 10;
+ sort_sequence->specs = (Z_SortKeySpec **)
+ nmem_malloc(stream, sort_sequence->num_specs *
+ sizeof(*sort_sequence->specs));
+ for (i = 0; i<sort_sequence->num_specs; i++)
+ sort_sequence->specs[i] = 0;