-/* $Id: zrpn.c,v 1.222 2006-07-03 10:43:43 adam Exp $
+/* $Id: zrpn.c,v 1.228 2006-09-08 14:40:53 adam Exp $
Copyright (C) 1995-2006
Index Data ApS
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
#include <stdio.h>
static int log_level_set = 0;
static int log_level_rpn = 0;
-
+#define TERMSET_DISABLE 1
static const char **rpn_char_map_handler(void *vp, const char **from, int len)
{
assert(*info == sizeof(*p->isam_p_buf));
memcpy(p->isam_p_buf + p->isam_p_indx, info+1, sizeof(*p->isam_p_buf));
-#if 1
if (p->termset)
{
const char *db;
resultSetAddTerm(p->zh, p->termset, name[len], db,
index_name, term_tmp);
}
-#endif
(p->isam_p_indx)++;
}
AttrType hits_limit_attr;
int term_ref_id_int;
- attr_init_APT(&hits_limit_attr, zapt, 9);
+ attr_init_APT(&hits_limit_attr, zapt, 11);
*hits_limit_value = attr_find(&hits_limit_attr, NULL);
attr_init_APT(&term_ref_id_attr, zapt, 10);
grep_info->zh = zh;
grep_info->reg_type = reg_type;
grep_info->termset = 0;
-
if (!zapt)
return ZEBRA_OK;
attr_init_APT(&termset, zapt, 8);
attr_find_ex(&termset, NULL, &termset_value_string);
if (termset_value_numeric != -1)
{
+#if TERMSET_DISABLE
+ zebra_setError(zh, YAZ_BIB1_UNSUPP_SEARCH, "termset");
+ return ZEBRA_FAIL;
+#else
char resname[32];
const char *termset_name = 0;
if (termset_value_numeric != -2)
zebra_setError(zh, YAZ_BIB1_ILLEGAL_RESULT_SET_NAME, termset_name);
return ZEBRA_FAIL;
}
+#endif
}
return ZEBRA_OK;
}
/**
\brief Create result set(s) for list of terms
\param zh Zebra Handle
+ \param zapt Attributes Plust Term (RPN leaf)
\param termz term as used in query but converted to UTF-8
\param attributeSet default attribute set
\param stream memory for result
\param xpath_use use attribute for X-Path (-1 for no X-path)
\param num_bases number of databases
\param basenames array of databases
- \param rset_mem memory for result sets
+ \param rset_nmem memory for result sets
\param result_sets output result set for each term in list (output)
- \param number number of output result sets
+ \param num_result_sets number of output result sets
\param kc rset key control to be used for created result sets
*/
static ZEBRA_RES term_list_trunc(ZebraHandle zh,
return ZEBRA_OK;
}
+static ZEBRA_RES rpn_search_APT_position(ZebraHandle zh,
+ Z_AttributesPlusTerm *zapt,
+ oid_value attributeSet,
+ int reg_type,
+ int num_bases, char **basenames,
+ NMEM rset_nmem,
+ RSET *rset,
+ struct rset_key_control *kc)
+{
+ RSET *f_set;
+ int base_no;
+ int position_value;
+ int num_sets = 0;
+ AttrType position;
+
+ attr_init_APT(&position, zapt, 3);
+ position_value = attr_find(&position, NULL);
+ switch(position_value)
+ {
+ case 3:
+ case -1:
+ return ZEBRA_OK;
+ case 1:
+ case 2:
+ break;
+ default:
+ zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_POSITION_ATTRIBUTE,
+ position_value);
+ return ZEBRA_FAIL;
+ }
+
+ if (!zebra_maps_is_first_in_field(zh->reg->zebra_maps, reg_type))
+ {
+ zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_POSITION_ATTRIBUTE,
+ position_value);
+ return ZEBRA_FAIL;
+ }
+
+ if (!zh->reg->isamb)
+ {
+ zebra_setError_zint(zh, YAZ_BIB1_UNSUPP_POSITION_ATTRIBUTE,
+ position_value);
+ return ZEBRA_FAIL;
+ }
+ f_set = xmalloc(sizeof(RSET) * num_bases);
+ for (base_no = 0; base_no < num_bases; base_no++)
+ {
+ int ord = -1;
+ char ord_buf[32];
+ char term_dict[100];
+ int ord_len;
+ char *val;
+ ISAM_P isam_p;
+
+ 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, reg_type, 0,
+ attributeSet, &ord) != ZEBRA_OK)
+ continue;
+
+ ord_len = key_SU_encode (ord, ord_buf);
+ memcpy(term_dict, ord_buf, ord_len);
+ strcpy(term_dict+ord_len, FIRST_IN_FIELD_STR);
+ val = dict_lookup(zh->reg->dict, term_dict);
+ if (!val)
+ continue;
+ assert(*val == sizeof(ISAM_P));
+ memcpy(&isam_p, val+1, sizeof(isam_p));
+
+ f_set[num_sets++] = rsisamb_create(rset_nmem, kc, kc->scope,
+ zh->reg->isamb, isam_p, 0);
+
+ }
+ if (num_sets)
+ {
+ *rset = rset_create_or(rset_nmem, kc, kc->scope,
+ 0 /* termid */, num_sets, f_set);
+ }
+ xfree(f_set);
+ return ZEBRA_OK;
+}
+
static ZEBRA_RES rpn_search_APT_phrase(ZebraHandle zh,
Z_AttributesPlusTerm *zapt,
const char *termz_org,
num_bases, basenames,
rset_nmem,
&result_sets, &num_result_sets, kc);
+
if (res != ZEBRA_OK)
return res;
+
+ if (num_result_sets > 0)
+ {
+ RSET first_set = 0;
+ res = rpn_search_APT_position(zh, zapt, attributeSet,
+ reg_type,
+ num_bases, basenames,
+ rset_nmem, &first_set,
+ kc);
+ if (res != ZEBRA_OK)
+ return res;
+ if (first_set)
+ {
+ RSET *nsets = nmem_malloc(stream,
+ sizeof(RSET) * (num_result_sets+1));
+ nsets[0] = first_set;
+ memcpy(nsets+1, result_sets, sizeof(RSET) * num_result_sets);
+ result_sets = nsets;
+ num_result_sets++;
+ }
+ }
if (num_result_sets == 0)
*rset = rset_create_null(rset_nmem, kc, 0);
else if (num_result_sets == 1)
else
idx = - pos - 1;
+ /* skip special terms.. of no interest */
+ if (name[len_prefix] < 4)
+ return 1;
+
if (idx < 0)
return 0;
scan_info->list[idx].term = (char *)
if (ord_no == 0)
{
*num_entries = 0;
- return ZEBRA_OK;
+ return ZEBRA_FAIL;
}
/* prepare dictionary scanning */
if (num < 1)