2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.28 1995-10-13 12:26:43 adam
8 * Optimization of truncation.
10 * Revision 1.27 1995/10/12 17:07:22 adam
13 * Revision 1.26 1995/10/12 12:40:54 adam
14 * Bug fixes in rpn_prox.
16 * Revision 1.25 1995/10/10 13:59:24 adam
17 * Function rset_open changed its wflag parameter to general flags.
19 * Revision 1.24 1995/10/09 16:18:37 adam
20 * Function dict_lookup_grep got extra client data parameter.
22 * Revision 1.23 1995/10/06 16:33:37 adam
23 * Use attribute mappings.
25 * Revision 1.22 1995/10/06 15:07:39 adam
26 * Structure 'local-number' handled.
28 * Revision 1.21 1995/10/06 13:52:06 adam
29 * Bug fixes. Handler may abort further scanning.
31 * Revision 1.20 1995/10/06 11:06:33 adam
32 * Scan entries include 'occurrences' now.
34 * Revision 1.19 1995/10/06 10:43:56 adam
35 * Scan added. 'occurrences' in scan entries not set yet.
37 * Revision 1.18 1995/10/04 16:57:20 adam
38 * Key input and merge sort in one pass.
40 * Revision 1.17 1995/10/04 12:55:17 adam
41 * Bug fix in ranked search. Use=Any keys inserted.
43 * Revision 1.16 1995/10/02 16:24:40 adam
44 * Use attribute actually used in search requests.
46 * Revision 1.15 1995/10/02 15:18:52 adam
47 * New member in recRetrieveCtrl: diagnostic.
49 * Revision 1.14 1995/09/28 12:10:32 adam
50 * Bug fixes. Field prefix used in queries.
52 * Revision 1.13 1995/09/18 14:17:50 adam
55 * Revision 1.12 1995/09/15 14:45:21 adam
59 * Revision 1.11 1995/09/14 11:53:27 adam
60 * First work on regular expressions/truncations.
62 * Revision 1.10 1995/09/11 15:23:26 adam
63 * More work on relevance search.
65 * Revision 1.9 1995/09/11 13:09:35 adam
66 * More work on relevance feedback.
68 * Revision 1.8 1995/09/08 14:52:27 adam
69 * Minor changes. Dictionary is lower case now.
71 * Revision 1.7 1995/09/07 13:58:36 adam
72 * New parameter: result-set file descriptor (RSFD) to support multiple
73 * positions within the same result-set.
74 * Boolean operators: and, or, not implemented.
75 * Result-set references.
77 * Revision 1.6 1995/09/06 16:11:18 adam
78 * Option: only one word key per file.
80 * Revision 1.5 1995/09/06 10:33:04 adam
81 * More work on present. Some log messages removed.
83 * Revision 1.4 1995/09/05 15:28:40 adam
84 * More work on search engine.
86 * Revision 1.3 1995/09/04 15:20:22 adam
89 * Revision 1.2 1995/09/04 12:33:43 adam
90 * Various cleanup. YAZ util used instead.
92 * Revision 1.1 1995/09/04 09:10:40 adam
93 * More work on index add/del/update.
94 * Merge sort implemented.
95 * Initial work on z39 server.
103 #include <attribute.h>
111 int index_word_prefix_map (char *string, oid_value attrSet, int attrUse)
115 logf (LOG_DEBUG, "oid_value attrSet = %d, attrUse = %d", attrSet, attrUse);
116 attp = att_getentbyatt (attrSet, attrUse);
119 logf (LOG_DEBUG, "ord=%d", attp->attset_ordinal);
120 return index_word_prefix (string, attp->attset_ordinal,
121 attp->local_attribute);
125 * attr_print: log attributes
127 static void attr_print (Z_AttributesPlusTerm *t)
130 for (of = 0; of < t->num_attributes; of++)
132 Z_AttributeElement *element;
133 element = t->attributeList[of];
135 switch (element->which)
137 case Z_AttributeValue_numeric:
138 logf (LOG_DEBUG, "attributeType=%d value=%d",
139 *element->attributeType,
140 *element->value.numeric);
142 case Z_AttributeValue_complex:
143 logf (LOG_DEBUG, "attributeType=%d complex",
144 *element->attributeType);
145 for (i = 0; i<element->value.complex->num_list; i++)
147 if (element->value.complex->list[i]->which ==
148 Z_StringOrNumeric_string)
149 logf (LOG_DEBUG, " string: '%s'",
150 element->value.complex->list[i]->u.string);
151 else if (element->value.complex->list[i]->which ==
152 Z_StringOrNumeric_numeric)
153 logf (LOG_DEBUG, " numeric: '%d'",
154 *element->value.complex->list[i]->u.numeric);
167 Z_AttributesPlusTerm *zapt;
170 static int attr_find (AttrType *src, oid_value *attributeSetP)
172 while (src->major < src->zapt->num_attributes)
174 Z_AttributeElement *element;
176 element = src->zapt->attributeList[src->major];
177 if (src->type == *element->attributeType)
179 switch (element->which)
181 case Z_AttributeValue_numeric:
183 if (element->attributeSet && attributeSetP)
187 attrset = oid_getentbyoid (element->attributeSet);
188 *attributeSetP = attrset->value;
190 return *element->value.numeric;
192 case Z_AttributeValue_complex:
193 if (src->minor >= element->value.complex->num_list ||
194 element->value.complex->list[src->minor]->which !=
195 Z_StringOrNumeric_numeric)
198 if (element->attributeSet && attributeSetP)
202 attrset = oid_getentbyoid (element->attributeSet);
203 *attributeSetP = attrset->value;
205 return *element->value.complex->list[src->minor-1]->u.numeric;
215 static void attr_init (AttrType *src, Z_AttributesPlusTerm *zapt,
229 int (*cmp)(const void *p1, const void *p2);
236 static void heap_swap (struct trunc_info *ti, int i1, int i2)
241 ti->ptr[i1] = ti->ptr[i2];
245 static void heap_delete (struct trunc_info *ti)
247 int cur = 1, child = 2;
249 heap_swap (ti, 1, ti->heapnum--);
250 while (child <= ti->heapnum) {
251 if (child < ti->heapnum &&
252 (*ti->cmp)(ti->heap[ti->ptr[child]],
253 ti->heap[ti->ptr[1+child]]) > 0)
255 if ((*ti->cmp)(ti->heap[ti->ptr[cur]],
256 ti->heap[ti->ptr[child]]) > 0)
258 heap_swap (ti, cur, child);
267 static void heap_insert (struct trunc_info *ti, const char *buf, int indx)
271 cur = ++(ti->heapnum);
272 memcpy (ti->heap[ti->ptr[cur]], buf, ti->keysize);
273 ti->indx[ti->ptr[cur]] = indx;
275 while (parent && (*ti->cmp)(ti->heap[ti->ptr[parent]],
276 ti->heap[ti->ptr[cur]]) > 0)
278 heap_swap (ti, cur, parent);
285 struct trunc_info *heap_init (int size, int key_size,
286 int (*cmp)(const void *p1, const void *p2))
288 struct trunc_info *ti = xmalloc (sizeof(*ti));
293 ti->keysize = key_size;
295 ti->indx = xmalloc (size * sizeof(*ti->indx));
296 ti->heap = xmalloc (size * sizeof(*ti->heap));
297 ti->ptr = xmalloc (size * sizeof(*ti->ptr));
298 ti->swapbuf = xmalloc (ti->keysize);
299 ti->tmpbuf = xmalloc (ti->keysize);
300 ti->buf = xmalloc (size * ti->keysize);
301 for (i = size; --i >= 0; )
304 ti->heap[i] = ti->buf + ti->keysize * i;
309 static void heap_close (struct trunc_info *ti)
319 static RSET rset_trunc_r (ISAM isam, ISAM_P *isam_p, int from, int to,
324 rset_temp_parms parms;
326 parms.key_size = sizeof(struct it_key);
327 result = rset_create (rset_kind_temp, &parms);
328 result_rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
330 if (to - from > merge_chunk)
334 int i, i_add = (to-from)/merge_chunk + 1;
335 struct trunc_info *ti;
337 int rsmax = (to-from)/i_add + 1;
339 rset = xmalloc (sizeof(*rset) * rsmax);
340 rsfd = xmalloc (sizeof(*rsfd) * rsmax);
342 for (i = from; i < to; i += i_add)
345 rset[rscur] = rset_trunc_r (isam, isam_p, i, i+i_add,
348 rset[rscur] = rset_trunc_r (isam, isam_p, i, to,
352 ti = heap_init (rscur, sizeof(struct it_key), key_compare);
353 for (i = rscur; --i >= 0; )
355 rsfd[i] = rset_open (rset[i], RSETF_READ|RSETF_SORT_SYSNO);
356 if (rset_read (rset[i], rsfd[i], ti->tmpbuf))
357 heap_insert (ti, ti->tmpbuf, i);
360 rset_close (rset[i], rsfd[i]);
361 rset_delete (rset[i]);
366 int n = ti->indx[ti->ptr[1]];
368 rset_write (result, result_rsfd, ti->heap[ti->ptr[1]]);
372 if (!rset_read (rset[n], rsfd[n], ti->tmpbuf))
375 rset_close (rset[n], rsfd[n]);
376 rset_delete (rset[n]);
379 if ((*ti->cmp)(ti->tmpbuf, ti->heap[ti->ptr[1]]) > 1)
382 heap_insert (ti, ti->tmpbuf, n);
395 struct trunc_info *ti;
397 ispt = xmalloc (sizeof(*ispt) * (to-from));
399 ti = heap_init (to-from, sizeof(struct it_key),
401 for (i = to-from; --i >= 0; )
403 ispt[i] = is_position (isam, isam_p[from+i]);
404 if (is_readkey (ispt[i], ti->tmpbuf))
405 heap_insert (ti, ti->tmpbuf, i);
407 is_pt_free (ispt[i]);
411 int n = ti->indx[ti->ptr[1]];
413 rset_write (result, result_rsfd, ti->heap[ti->ptr[1]]);
416 if (is_readkey (ispt[n], ti->tmpbuf))
417 heap_insert (ti, ti->tmpbuf, n);
419 is_pt_free (ispt[n]);
423 if (!is_readkey (ispt[n], ti->tmpbuf))
426 is_pt_free (ispt[n]);
429 if ((*ti->cmp)(ti->tmpbuf, ti->heap[ti->ptr[1]]) > 1)
432 heap_insert (ti, ti->tmpbuf, n);
441 rset_close (result, result_rsfd);
445 static int isam_trunc_cmp (const void *p1, const void *p2)
447 ISAM_P i1 = *(ISAM_P*) p1;
448 ISAM_P i2 = *(ISAM_P*) p2;
451 d = is_type (i1) - is_type (i2);
454 return is_block (i1) - is_block (i2);
457 static RSET rset_trunc (ISAM isam, ISAM_P *isam_p, int no)
460 qsort (isam_p, no, sizeof(*isam_p), isam_trunc_cmp);
461 return rset_trunc_r (isam, isam_p, 0, no, 100);
470 static void add_isam_p (const char *info, struct grep_info *p)
472 if (p->isam_p_indx == p->isam_p_size)
474 ISAM_P *new_isam_p_buf;
476 p->isam_p_size = 2*p->isam_p_size + 100;
477 new_isam_p_buf = xmalloc (sizeof(*new_isam_p_buf) *
481 memcpy (new_isam_p_buf, p->isam_p_buf,
482 p->isam_p_indx * sizeof(*p->isam_p_buf));
483 xfree (p->isam_p_buf);
485 p->isam_p_buf = new_isam_p_buf;
487 assert (*info == sizeof(*p->isam_p_buf));
488 memcpy (p->isam_p_buf + p->isam_p_indx, info+1, sizeof(*p->isam_p_buf));
492 static int grep_handle (Dict_char *name, const char *info, void *p)
494 logf (LOG_DEBUG, "dict name: %s", name);
495 add_isam_p (info, p);
499 static int trunc_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
500 const char *term_sub,
501 oid_value attributeSet, struct grep_info *grep_info)
503 char term_dict[2*IT_MAX_WORD+2];
507 int truncation_value;
510 oid_value curAttributeSet = attributeSet;
512 attr_init (&use, zapt, 1);
513 use_value = attr_find (&use, &curAttributeSet);
514 logf (LOG_DEBUG, "use value %d", use_value);
515 attr_init (&truncation, zapt, 5);
516 truncation_value = attr_find (&truncation, NULL);
517 logf (LOG_DEBUG, "truncation value %d", truncation_value);
521 i = index_word_prefix_map (term_dict, curAttributeSet, use_value);
528 switch (truncation_value)
530 case -1: /* not specified */
531 case 100: /* do not truncate */
532 strcat (term_dict, term_sub);
533 logf (LOG_DEBUG, "dict_lookup: %s", term_dict);
534 if ((info = dict_lookup (zi->wordDict, term_dict)))
535 add_isam_p (info, grep_info);
537 case 1: /* right truncation */
538 strcat (term_dict, term_sub);
539 strcat (term_dict, ".*");
540 dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, grep_handle);
542 case 2: /* left truncation */
543 case 3: /* left&right truncation */
546 case 101: /* process # in term */
547 for (j = strlen(term_dict), i = 0; term_sub[i] && i < 2; i++)
548 term_dict[j++] = term_sub[i];
549 for (; term_sub[i]; i++)
550 if (term_sub[i] == '#')
552 term_dict[j++] = '.';
553 term_dict[j++] = '*';
556 term_dict[j++] = term_sub[i];
558 dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, grep_handle);
560 case 102: /* regular expression */
561 strcat (term_dict, term_sub);
562 dict_lookup_grep (zi->wordDict, term_dict, 0, grep_info, grep_handle);
565 logf (LOG_DEBUG, "%d positions", grep_info->isam_p_indx);
569 static void trans_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
573 Z_Term *term = zapt->term;
575 sizez = term->u.general->len;
576 if (sizez > IT_MAX_WORD)
578 for (i = 0; i < sizez; i++)
579 termz[i] = index_char_cvt (term->u.general->buf[i]);
583 static RSET rpn_search_APT_relevance (ZServerInfo *zi,
584 Z_AttributesPlusTerm *zapt,
585 oid_value attributeSet)
587 rset_relevance_parms parms;
588 char termz[IT_MAX_WORD+1];
589 char term_sub[IT_MAX_WORD+1];
590 struct grep_info grep_info;
591 char *p0 = termz, *p1 = NULL;
594 parms.key_size = sizeof(struct it_key);
596 parms.cmp = key_compare;
597 parms.is = zi->wordIsam;
599 if (zapt->term->which != Z_Term_general)
604 trans_term (zi, zapt, termz);
605 grep_info.isam_p_indx = 0;
606 grep_info.isam_p_size = 0;
607 grep_info.isam_p_buf = NULL;
610 if ((p1 = strchr (p0, ' ')))
612 memcpy (term_sub, p0, p1-p0);
613 term_sub[p1-p0] = '\0';
616 strcpy (term_sub, p0);
617 if (trunc_term (zi, zapt, term_sub, attributeSet, &grep_info))
625 parms.isam_positions = grep_info.isam_p_buf;
626 parms.no_isam_positions = grep_info.isam_p_indx;
627 if (grep_info.isam_p_indx > 0)
628 result = rset_create (rset_kind_relevance, &parms);
630 result = rset_create (rset_kind_null, NULL);
631 xfree (grep_info.isam_p_buf);
635 static RSET rpn_search_APT_word (ZServerInfo *zi,
636 Z_AttributesPlusTerm *zapt,
637 oid_value attributeSet)
639 rset_isam_parms parms;
640 char termz[IT_MAX_WORD+1];
641 struct grep_info grep_info;
644 if (zapt->term->which != Z_Term_general)
649 trans_term (zi, zapt, termz);
651 grep_info.isam_p_indx = 0;
652 grep_info.isam_p_size = 0;
653 grep_info.isam_p_buf = NULL;
655 if (trunc_term (zi, zapt, termz, attributeSet, &grep_info))
657 if (grep_info.isam_p_indx < 1)
658 result = rset_create (rset_kind_null, NULL);
659 else if (grep_info.isam_p_indx == 1)
661 parms.is = zi->wordIsam;
662 parms.pos = *grep_info.isam_p_buf;
663 result = rset_create (rset_kind_isam, &parms);
666 result = rset_trunc (zi->wordIsam, grep_info.isam_p_buf,
667 grep_info.isam_p_indx);
668 xfree (grep_info.isam_p_buf);
672 static RSET rpn_prox (RSET *rset, int rset_no)
680 rset_temp_parms parms;
682 rsfd = xmalloc (sizeof(*rsfd)*rset_no);
683 more = xmalloc (sizeof(*more)*rset_no);
684 buf = xmalloc (sizeof(*buf)*rset_no);
686 for (i = 0; i<rset_no; i++)
688 buf[i] = xmalloc (sizeof(**buf));
689 rsfd[i] = rset_open (rset[i], RSETF_READ|RSETF_SORT_SYSNO);
690 if (!(more[i] = rset_read (rset[i], rsfd[i], buf[i])))
694 rset_close (rset[i], rsfd[i]);
701 return rset_create (rset_kind_null, NULL);
704 parms.key_size = sizeof (struct it_key);
705 result = rset_create (rset_kind_temp, &parms);
706 rsfd_result = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
710 for (i = 1; i<rset_no; i++)
719 cmp = key_compare (buf[i], buf[i-1]);
722 more[i-1] = rset_read (rset[i-1], rsfd[i-1], buf[i-1]);
727 if (buf[i-1]->seqno+1 != buf[i]->seqno)
729 more[i-1] = rset_read (rset[i-1], rsfd[i-1], buf[i-1]);
735 more[i] = rset_read (rset[i], rsfd[i], buf[i]);
741 rset_write (result, rsfd_result, buf[0]);
742 more[0] = rset_read (*rset, *rsfd, *buf);
746 for (i = 0; i<rset_no; i++)
748 rset_close (rset[i], rsfd[i]);
751 rset_close (result, rsfd_result);
758 static RSET rpn_search_APT_phrase (ZServerInfo *zi,
759 Z_AttributesPlusTerm *zapt,
760 oid_value attributeSet)
762 char termz[IT_MAX_WORD+1];
763 char term_sub[IT_MAX_WORD+1];
764 char *p0 = termz, *p1 = NULL;
765 RSET rset[60], result;
767 struct grep_info grep_info;
769 if (zapt->term->which != Z_Term_general)
774 trans_term (zi, zapt, termz);
776 grep_info.isam_p_size = 0;
777 grep_info.isam_p_buf = NULL;
781 if ((p1 = strchr (p0, ' ')))
783 memcpy (term_sub, p0, p1-p0);
784 term_sub[p1-p0] = '\0';
787 strcpy (term_sub, p0);
789 grep_info.isam_p_indx = 0;
790 if (trunc_term (zi, zapt, term_sub, attributeSet, &grep_info))
792 if (grep_info.isam_p_indx == 0)
793 rset[rset_no] = rset_create (rset_kind_null, NULL);
794 else if (grep_info.isam_p_indx > 1)
795 rset[rset_no] = rset_trunc (zi->wordIsam,
796 grep_info.isam_p_buf,
797 grep_info.isam_p_indx);
800 rset_isam_parms parms;
802 parms.is = zi->wordIsam;
803 parms.pos = *grep_info.isam_p_buf;
804 rset[rset_no] = rset_create (rset_kind_isam, &parms);
806 assert (rset[rset_no]);
807 if (++rset_no >= sizeof(rset)/sizeof(*rset))
815 xfree (grep_info.isam_p_buf);
817 return rset_create (rset_kind_null, NULL);
818 else if (rset_no == 1)
821 result = rpn_prox (rset, rset_no);
822 for (i = 0; i<rset_no; i++)
823 rset_delete (rset[i]);
827 static RSET rpn_search_APT_local (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
828 oid_value attributeSet)
833 rset_temp_parms parms;
834 char termz[IT_MAX_WORD+1];
836 if (zapt->term->which != Z_Term_general)
841 parms.key_size = sizeof (struct it_key);
842 result = rset_create (rset_kind_temp, &parms);
843 rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO);
845 trans_term (zi, zapt, termz);
846 key.sysno = atoi (termz);
849 rset_write (result, rsfd, &key);
850 rset_close (result, rsfd);
855 static RSET rpn_search_APT (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
856 oid_value attributeSet)
860 int relation_value, structure_value;
862 attr_init (&relation, zapt, 2);
863 attr_init (&structure, zapt, 4);
865 relation_value = attr_find (&relation, NULL);
866 structure_value = attr_find (&structure, NULL);
867 switch (structure_value)
870 if (relation_value == 102) /* relevance relation */
871 return rpn_search_APT_relevance (zi, zapt, attributeSet);
872 return rpn_search_APT_phrase (zi, zapt, attributeSet);
874 if (relation_value == 102) /* relevance relation */
875 return rpn_search_APT_relevance (zi, zapt, attributeSet);
876 return rpn_search_APT_phrase (zi, zapt, attributeSet);
879 if (relation_value == 102) /* relevance relation */
880 return rpn_search_APT_relevance (zi, zapt, attributeSet);
881 return rpn_search_APT_word (zi, zapt, attributeSet);
886 case 5: /* date - normalized */
888 case 6: /* word list */
889 return rpn_search_APT_relevance (zi, zapt, attributeSet);
890 case 100: /* date - un-normalized */
892 case 101: /* name - normalized */
894 case 102: /* date - un-normalized */
896 case 103: /* structure */
900 case 105: /* free-form-text */
901 return rpn_search_APT_relevance (zi, zapt, attributeSet);
902 case 106: /* document-text */
903 return rpn_search_APT_relevance (zi, zapt, attributeSet);
904 case 107: /* local-number */
905 return rpn_search_APT_local (zi, zapt, attributeSet);
906 case 108: /* string */
907 return rpn_search_APT_word (zi, zapt, attributeSet);
908 case 109: /* numeric string */
915 static RSET rpn_search_ref (ZServerInfo *zi, Z_ResultSetId *resultSetId)
919 if (!(s = resultSetGet (zi, resultSetId)))
920 return rset_create (rset_kind_null, NULL);
924 static RSET rpn_search_structure (ZServerInfo *zi, Z_RPNStructure *zs,
925 oid_value attributeSet)
928 if (zs->which == Z_RPNStructure_complex)
930 rset_bool_parms bool_parms;
932 bool_parms.rset_l = rpn_search_structure (zi, zs->u.complex->s1,
934 if (bool_parms.rset_l == NULL)
936 bool_parms.rset_r = rpn_search_structure (zi, zs->u.complex->s2,
938 if (bool_parms.rset_r == NULL)
940 rset_delete (bool_parms.rset_l);
943 bool_parms.key_size = sizeof(struct it_key);
944 bool_parms.cmp = key_compare;
946 switch (zs->u.complex->operator->which)
949 r = rset_create (rset_kind_and, &bool_parms);
952 r = rset_create (rset_kind_or, &bool_parms);
954 case Z_Operator_and_not:
955 r = rset_create (rset_kind_not, &bool_parms);
961 else if (zs->which == Z_RPNStructure_simple)
963 if (zs->u.simple->which == Z_Operand_APT)
965 logf (LOG_DEBUG, "rpn_search_APT");
966 r = rpn_search_APT (zi, zs->u.simple->u.attributesPlusTerm,
969 else if (zs->u.simple->which == Z_Operand_resultSetId)
971 logf (LOG_DEBUG, "rpn_search_ref");
972 r = rpn_search_ref (zi, zs->u.simple->u.resultSetId);
986 static void count_set (RSET r, int *count)
992 logf (LOG_DEBUG, "rpn_save_set");
994 rfd = rset_open (r, RSETF_READ|RSETF_SORT_SYSNO);
995 while (rset_read (r, rfd, &key))
997 if (key.sysno != psysno)
1003 rset_close (r, rfd);
1004 logf (LOG_DEBUG, "%d distinct sysnos", *count);
1007 int rpn_search (ZServerInfo *zi,
1008 Z_RPNQuery *rpn, int num_bases, char **basenames,
1009 const char *setname, int *hits)
1013 oid_value attributeSet;
1016 zi->errString = NULL;
1018 attrset = oid_getentbyoid (rpn->attributeSetId);
1019 attributeSet = attrset->value;
1021 rset = rpn_search_structure (zi, rpn->RPNStructure, attributeSet);
1024 count_set (rset, hits);
1025 resultSetAdd (zi, setname, 1, rset);
1027 logf (LOG_DEBUG, "search error: %d", zi->errCode);
1032 struct scan_entry *list;
1039 static int scan_handle (Dict_char *name, const char *info, int pos,
1042 int len_prefix, idx;
1045 struct scan_info *scan_info = client;
1047 rset_isam_parms parms;
1049 len_prefix = strlen(scan_info->prefix);
1050 if (memcmp (name, scan_info->prefix, len_prefix))
1053 idx = scan_info->after - pos + scan_info->before;
1056 scan_info->list[idx].term = odr_malloc (scan_info->odr,
1057 strlen(name + len_prefix)+1);
1058 strcpy (scan_info->list[idx].term, name + len_prefix);
1059 assert (*info == sizeof(isam_p));
1060 memcpy (&isam_p, info+1, sizeof(isam_p));
1061 parms.is = scan_info->isam;
1064 rset = rset_create (rset_kind_isam, &parms);
1065 count_set (rset, &scan_info->list[idx].occurrences);
1068 scan_info->list[idx].occurrences = 1;
1070 logf (LOG_DEBUG, "pos=%3d idx=%3d name=%s", pos, idx, name);
1074 int rpn_scan (ZServerInfo *zi, ODR odr, Z_AttributesPlusTerm *zapt,
1075 int *position, int *num_entries, struct scan_entry **list,
1079 int pos = *position;
1080 int num = *num_entries;
1083 char termz[IT_MAX_WORD+20];
1086 Z_Term *term = zapt->term;
1087 struct scan_info scan_info;
1089 logf (LOG_DEBUG, "scan, position = %d, num = %d", pos, num);
1090 scan_info.before = before = pos-1;
1091 scan_info.after = after = 1+num-pos;
1092 scan_info.odr = odr;
1094 logf (LOG_DEBUG, "scan, before = %d, after = %d", before, after);
1096 scan_info.isam = zi->wordIsam;
1097 scan_info.list = odr_malloc (odr, (before+after)*sizeof(*scan_info.list));
1098 for (j = 0; j<before+after; j++)
1099 scan_info.list[j].term = NULL;
1100 attr_init (&use, zapt, 1);
1101 use_value = attr_find (&use, NULL);
1102 logf (LOG_DEBUG, "use value %d", use_value);
1104 if (use_value == -1)
1106 i = index_word_prefix (termz, 1, use_value);
1107 strcpy (scan_info.prefix, termz);
1108 sizez = term->u.general->len;
1109 if (sizez > IT_MAX_WORD)
1110 sizez = IT_MAX_WORD;
1111 for (j = 0; j<sizez; j++)
1112 termz[j+i] = index_char_cvt (term->u.general->buf[j]);
1115 dict_scan (zi->wordDict, termz, &before, &after, &scan_info, scan_handle);
1117 *status = BEND_SCAN_SUCCESS;
1119 for (i = 0; i<scan_info.after; i++)
1120 if (scan_info.list[scan_info.before+scan_info.after-i-1].term)
1124 *status = BEND_SCAN_PARTIAL;
1126 for (i = 0; i<scan_info.before; i++)
1127 if (scan_info.list[i].term)
1130 *status = BEND_SCAN_PARTIAL;
1134 *list = scan_info.list+i; /* list is set to first 'real' entry */
1136 if (*num_entries == 0) /* signal 'unsupported use-attribute' */
1137 zi->errCode = 114; /* if no entries was found */
1138 logf (LOG_DEBUG, "position = %d, num_entries = %d",
1139 *position, *num_entries);
1141 logf (LOG_DEBUG, "scan error: %d", zi->errCode);