+
+static ZEBRA_RES always_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+ oid_value attributeSet, NMEM stream,
+ struct grep_info *grep_info,
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames,
+ char *term_dst,
+ const char *xpath_use,
+ struct ord_list **ol)
+{
+ char term_dict[2*IT_MAX_WORD+4000];
+ int r, base_no;
+ struct rpn_char_map_info rcmi;
+
+ int bases_ok = 0; /* no of databases with OK attribute */
+
+ *ol = ord_list_create(stream);
+
+ rpn_char_map_prepare (zh->reg, reg_type, &rcmi);
+
+ for (base_no = 0; base_no < num_bases; base_no++)
+ {
+ int ord = -1;
+ int regex_range = 0;
+ int init_pos = 0;
+ int max_pos, prefix_len = 0;
+ char ord_buf[32];
+ int ord_len, i;
+
+ if (zebraExplain_curDatabase (zh->reg->zei, basenames[base_no]))
+ {
+ zebra_setError(zh, YAZ_BIB1_DATABASE_UNAVAILABLE,
+ basenames[base_no]);
+ return ZEBRA_FAIL;
+ }
+
+ if (zebra_apt_get_ord(zh, zapt, zinfo_index_category_alwaysmatches,
+ reg_type, xpath_use,
+ attributeSet, &ord) != ZEBRA_OK)
+ return ZEBRA_FAIL;
+ yaz_log(YLOG_LOG, "Got ordinal value: %d", ord);
+ *ol = ord_list_append(stream, *ol, ord);
+
+ if (prefix_len)
+ term_dict[prefix_len++] = '|';
+ else
+ term_dict[prefix_len++] = '(';
+
+ ord_len = key_SU_encode (ord, ord_buf);
+ for (i = 0; i<ord_len; i++)
+ {
+ term_dict[prefix_len++] = 1;
+ term_dict[prefix_len++] = ord_buf[i];
+ }
+ if (ord_len > init_pos)
+ init_pos = ord_len;
+
+ bases_ok++;
+
+ term_dict[prefix_len++] = ')';
+ term_dict[prefix_len] = '\0';
+
+ r = dict_lookup_grep(zh->reg->dict, term_dict, regex_range,
+ grep_info, &max_pos, init_pos,
+ grep_handle);
+ }
+ if (!bases_ok)
+ return ZEBRA_FAIL;
+ yaz_log(YLOG_LOG, "always_term: %d positions", grep_info->isam_p_indx);
+ return ZEBRA_OK;
+}
+
+static ZEBRA_RES rpn_search_APT_alwaysmatches(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ const char *termz_org,
+ oid_value attributeSet,
+ NMEM stream,
+ int reg_type, int complete_flag,
+ const char *rank_type,
+ const char *xpath_use,
+ int num_bases, char **basenames,
+ NMEM rset_nmem,
+ RSET *rset,
+ struct rset_key_control *kc)
+{
+ char term_dst[IT_MAX_WORD+1];
+ struct grep_info grep_info;
+ zint hits_limit_value;
+ const char *term_ref_id_str = 0;
+ ZEBRA_RES res;
+ struct ord_list *ol;
+
+ term_limits_APT(zh, zapt, &hits_limit_value, &term_ref_id_str,
+ stream);
+ if (grep_info_prepare(zh, zapt, &grep_info, reg_type) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+
+ grep_info.isam_p_indx = 0;
+
+ res = always_term(zh, zapt, attributeSet, stream, &grep_info,
+ reg_type, complete_flag, num_bases, basenames,
+ term_dst, xpath_use, &ol);
+ if (res == ZEBRA_OK)
+ {
+ *rset = rset_trunc(zh, grep_info.isam_p_buf,
+ grep_info.isam_p_indx, term_dst, strlen(term_dst),
+ rank_type, 1 /* preserve pos */,
+ zapt->term->which, rset_nmem,
+ kc, kc->scope, ol, reg_type, hits_limit_value,
+ term_ref_id_str);
+ if (!*rset)
+ res = ZEBRA_FAIL;
+ }
+ grep_info_delete (&grep_info);
+ return res;
+}
+