- /* consider terms after main term */
- for (i = 0; i < ord_no; i++)
- ptr[i] = before;
-
- *is_partial = 0;
- for (i = 0; i<after; i++)
- {
- int j, j0 = -1;
- const char *mterm = NULL;
- const char *tst;
- RSET rset = 0;
- int lo = i + pos-1; /* offset in result list */
-
- /* find: j0 is the first of the minimal values */
- for (j = 0; j < ord_no; j++)
- {
- if (ptr[j] < before+after && ptr[j] >= 0 &&
- (tst = scan_info_array[j].list[ptr[j]].term) &&
- (!mterm || strcmp (tst, mterm) < 0))
- {
- j0 = j;
- mterm = tst;
- }
- }
- if (j0 == -1)
- break; /* no value found, stop */
-
- /* get result set for first one , but only if it's within bounds */
- if (lo >= 0)
- {
- /* get result set for first term */
- zebra_term_untrans_iconv(zh, stream->mem, index_type,
- &glist[lo].term, mterm);
- rset = rset_trunc(zh, &scan_info_array[j0].list[ptr[j0]].isam_p, 1,
- glist[lo].term, strlen(glist[lo].term),
- NULL, 0, zapt->term->which, rset_nmem,
- kc, kc->scope, 0, index_type, 0 /* hits_limit */,
- 0 /* term_ref_id_str */);
- }
- ptr[j0]++; /* move index for this set .. */
- /* get result set for remaining scan terms */
- for (j = j0+1; j<ord_no; j++)
- {
- if (ptr[j] < before+after && ptr[j] >= 0 &&
- (tst = scan_info_array[j].list[ptr[j]].term) &&
- !strcmp (tst, mterm))
- {
- if (lo >= 0)
- {
- RSET rsets[2];
-
- rsets[0] = rset;
- rsets[1] =
- rset_trunc(
- zh, &scan_info_array[j].list[ptr[j]].isam_p, 1,
- glist[lo].term,
- strlen(glist[lo].term), NULL, 0,
- zapt->term->which,rset_nmem,
- kc, kc->scope, 0, index_type, 0 /* hits_limit */,
- 0 /* term_ref_id_str */ );
- rset = rset_create_or(rset_nmem, kc,
- kc->scope, 0 /* termid */,
- 2, rsets);
- }
- ptr[j]++;
- }
- }
- if (lo >= 0)
- {
- zint count;
- /* merge with limit_set if given */
- if (limit_set)
- {
- RSET rsets[2];
- rsets[0] = rset;
- rsets[1] = rset_dup(limit_set);
-
- rset = rset_create_and(rset_nmem, kc, kc->scope, 2, rsets);
- }
- /* count it */
- count_set(zh, rset, &count);
- glist[lo].occurrences = count;
- rset_delete(rset);
- }
- }
- if (i < after)
- {
- *num_entries -= (after-i);
- *is_partial = 1;
- if (*num_entries < 0)
- {
- (*kc->dec)(kc);
- nmem_destroy(rset_nmem);
- *num_entries = 0;
- return ZEBRA_OK;
- }
- }
- /* consider terms before main term */
- for (i = 0; i<ord_no; i++)
- ptr[i] = 0;
-
- for (i = 0; i<before; i++)
- {
- int j, j0 = -1;
- const char *mterm = NULL;
- const char *tst;
- RSET rset;
- int lo = before-1-i; /* offset in result list */
- zint count;
-
- for (j = 0; j <ord_no; j++)
- {
- if (ptr[j] < before && ptr[j] >= 0 &&
- (tst = scan_info_array[j].list[before-1-ptr[j]].term) &&
- (!mterm || strcmp (tst, mterm) > 0))
- {
- j0 = j;
- mterm = tst;
- }
- }
- if (j0 == -1)
- break;
-
- zebra_term_untrans_iconv(zh, stream->mem, index_type,
- &glist[lo].term, mterm);
-
- rset = rset_trunc
- (zh, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1,
- glist[lo].term, strlen(glist[lo].term),
- NULL, 0, zapt->term->which, rset_nmem,
- kc, kc->scope, 0, index_type, 0 /* hits_limit */,
- 0 /* term_ref_id_str */);
-
- ptr[j0]++;
-
- for (j = j0+1; j<ord_no; j++)
- {
- if (ptr[j] < before && ptr[j] >= 0 &&
- (tst = scan_info_array[j].list[before-1-ptr[j]].term) &&
- !strcmp (tst, mterm))
- {
- RSET rsets[2];
-
- rsets[0] = rset;
- rsets[1] = rset_trunc(
- zh,
- &scan_info_array[j].list[before-1-ptr[j]].isam_p, 1,
- glist[lo].term,
- strlen(glist[lo].term), NULL, 0,
- zapt->term->which, rset_nmem,
- kc, kc->scope, 0, index_type, 0 /* hits_limit */,
- 0 /* term_ref_id_str */);
- rset = rset_create_or(rset_nmem, kc,
- kc->scope, 0 /* termid */, 2, rsets);
-
- ptr[j]++;
- }
- }
- if (limit_set)
- {
- RSET rsets[2];
- rsets[0] = rset;
- rsets[1] = rset_dup(limit_set);
-
- rset = rset_create_and(rset_nmem, kc, kc->scope, 2, rsets);
- }
- count_set(zh, rset, &count);
- glist[lo].occurrences = count;
- rset_delete (rset);
- }