-/* $Id: zrpn.c,v 1.225 2006-07-31 12:26:56 adam Exp $
+/* $Id: zrpn.c,v 1.229 2006-09-08 18:24: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>
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 && !zh->reg->isamc)
+ {
+ 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));
+
+
+ if (zh->reg->isamb)
+ f_set[num_sets++] = rsisamb_create(rset_nmem, kc, kc->scope,
+ zh->reg->isamb, isam_p, 0);
+ else if (zh->reg->isamc)
+ f_set[num_sets++] = rsisamc_create(rset_nmem, kc, kc->scope,
+ zh->reg->isamc, 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)
{
RSET *result_sets = 0;
int num_result_sets = 0;
+ int i;
ZEBRA_RES res =
term_list_trunc(zh, zapt, termz_org, attributeSet,
stream, reg_type, complete_flag,
&result_sets, &num_result_sets, kc);
if (res != ZEBRA_OK)
return res;
+
+ for (i = 0; i<num_result_sets; i++)
+ {
+ 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)
+ {
+ for (i = 0; i<num_result_sets; i++)
+ rset_delete(result_sets[i]);
+ return res;
+ }
+
+ if (first_set)
+ {
+ RSET tmp_set[2];
+
+ tmp_set[0] = first_set;
+ tmp_set[1] = result_sets[i];
+
+ result_sets[i] = rset_create_prox(
+ rset_nmem, kc, kc->scope,
+ 2, tmp_set,
+ 1 /* ordered */, 0 /* exclusion */,
+ 3 /* relation */, 1 /* distance */);
+ }
+ }
if (num_result_sets == 0)
*rset = rset_create_null(rset_nmem, kc, 0);
else if (num_result_sets == 1)
{
RSET *result_sets = 0;
int num_result_sets = 0;
+ int i;
ZEBRA_RES res =
term_list_trunc(zh, zapt, termz_org, attributeSet,
stream, reg_type, complete_flag,
kc);
if (res != ZEBRA_OK)
return res;
+ for (i = 0; i<num_result_sets; i++)
+ {
+ 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)
+ {
+ for (i = 0; i<num_result_sets; i++)
+ rset_delete(result_sets[i]);
+ return res;
+ }
+
+ if (first_set)
+ {
+ RSET tmp_set[2];
+
+ tmp_set[0] = first_set;
+ tmp_set[1] = result_sets[i];
+
+ result_sets[i] = rset_create_prox(
+ rset_nmem, kc, kc->scope,
+ 2, tmp_set,
+ 1 /* ordered */, 0 /* exclusion */,
+ 3 /* relation */, 1 /* distance */);
+ }
+ }
+
+
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)