*** estxview.c.orig	Wed Dec  1 13:25:58 2004
--- estxview.c	Fri Dec  3 20:36:38 2004
***************
*** 53,58 ****
--- 53,60 ----
  CURIA *scdb = NULL;                      /* handle of the score database */
  DEPOT *dtdb = NULL;                      /* handle of the date database */
  int optmax = DEFMAX;                     /* default number of shown documents */
+ int optboolunit = UNITINIT;
+ int optpage = 0;
  int optclshow = 0;                       /* number of shown clusters */
  int optclcode = 0;                       /* code of the cluster for narrowing */
  int optdrep = 0;                         /* level of directory rep */
***************
*** 135,140 ****
--- 137,148 ----
        } else if(!strcmp(argv[i], "-max")){
          if(++i >= argc) usage();
          optmax = atoi(argv[i]);
+       } else if(!strcmp(argv[i], "-boolunit")){
+         if(++i >= argc) usage();
+         optboolunit = atoi(argv[i]);
+       } else if(!strcmp(argv[i], "-page")){
+         if(++i >= argc) usage();
+         optpage = atoi(argv[i]);
        } else if(!strcmp(argv[i], "-drep")){
          if(++i >= argc) usage();
          optdrep = atoi(argv[i]);
***************
*** 188,193 ****
--- 196,203 ----
    if(strcmp(optstype, "score") && strcmp(optstype, "r-score") &&
       strcmp(optstype, "date") && strcmp(optstype, "r-date")) usage();
    if(optmax < 0) usage();
+   if(optboolunit < 0) usage();
+   if(optpage < 1) optpage = 1;
    if(optclshow < 0) usage();
    if(optclcode < 0) usage();
    if(optdrep < 0) usage();
***************
*** 477,483 ****
    pnum = *np;
    if(pnum > CLUSTUNIT) pnum = CLUSTUNIT;
    blnum = *np;
!   if(blnum > UNITINIT) blnum = UNITINIT;
    clusts = cbmalloc(pnum * sizeof(CLUSTER) + 1);
    clnum = 0;
    tails = cbmalloc(blnum * sizeof(CBMAP *) + 1);
--- 487,493 ----
    pnum = *np;
    if(pnum > CLUSTUNIT) pnum = CLUSTUNIT;
    blnum = *np;
!   if(blnum > optboolunit) blnum = optboolunit;
    clusts = cbmalloc(pnum * sizeof(CLUSTER) + 1);
    clnum = 0;
    tails = cbmalloc(blnum * sizeof(CBMAP *) + 1);
***************
*** 951,957 ****
    ODPAIR *pairs;
    const char *word, *score;
    char *mbuf, *tmbuf, *tmp;
!   int i, err, msiz, tmsiz, wsiz, wnum, pnum, lnum, show;
    int ovec[RELVECNUM], tvec[RELVECNUM];
    err = FALSE;
    showpreamble();
--- 961,967 ----
    ODPAIR *pairs;
    const char *word, *score;
    char *mbuf, *tmbuf, *tmp;
!   int i, err, msiz, tmsiz, wsiz, wnum, pnum, lnum, show, step;
    int ovec[RELVECNUM], tvec[RELVECNUM];
    err = FALSE;
    showpreamble();
***************
*** 963,970 ****
      xmlprintf("<query operator=\"related\">%d</query>\n", id);
    }
    xmlprintf("<option max=\"%d\" tfidf=\"%@\" clshow=\"%d\" clcode=\"%d\""
!             " drep=\"%d\" expr=\"none\" sort=\"none\"/>\n",
!             optmax, optni ? "false" : "true", optclshow, optclcode, optdrep);
    doc = NULL;
    mbuf = NULL;
    scores = NULL;
--- 973,980 ----
      xmlprintf("<query operator=\"related\">%d</query>\n", id);
    }
    xmlprintf("<option max=\"%d\" tfidf=\"%@\" clshow=\"%d\" clcode=\"%d\""
!             " drep=\"%d\" expr=\"none\" sort=\"none\" boolunit=\"%d\" page=\"%d\"/>\n",
!             optmax, optni ? "false" : "true", optclshow, optclcode, optdrep,optboolunit,optpage);
    doc = NULL;
    mbuf = NULL;
    scores = NULL;
***************
*** 1001,1007 ****
        cbdatumcat(phrase, word, wsiz);
      }
      words = estsearchwords(cbdatumptr(phrase), &wnum, FALSE);
!     pairs = estsearch(odeum, words, wnum, UNITINIT, !optni, &pnum, &lnum, FALSE, FALSE, 0);
      setovec(scores, ovec);
      for(i = 0; i < pnum; i++){
        if((tmbuf = crget(scdb, (char *)&(pairs[i].id), sizeof(int), 0, -1, &tmsiz)) != NULL){
--- 1011,1017 ----
        cbdatumcat(phrase, word, wsiz);
      }
      words = estsearchwords(cbdatumptr(phrase), &wnum, FALSE);
!     pairs = estsearch(odeum, words, wnum, optboolunit, !optni, &pnum, &lnum, FALSE, FALSE, 0);
      setovec(scores, ovec);
      for(i = 0; i < pnum; i++){
        if((tmbuf = crget(scdb, (char *)&(pairs[i].id), sizeof(int), 0, -1, &tmsiz)) != NULL){
***************
*** 1032,1042 ****
--- 1042,1057 ----
    if(pairs){
      if(scdb && optclshow > 0 && pnum > 0) showclusters(pairs, &pnum);
      show = 0;
+     step = 0;
      dirs = NULL;
      if(optdrep > 0) dirs = cbmapopen();
      for(i = 0; i < pnum && show < optmax; i++){
        if(opttiny && !dirs){
          if(!odcheck(odeum, pairs[i].id)) continue;
+       if(optpage > 1 && step < (optpage -1) * optmax){
+       	step++;
+       	continue;
+       }
          showdoctiny(pairs[i].id, -1, pairs[i].score);
          show++;
        } else {
***************
*** 1051,1063 ****
            cbmapput(dirs, tmp, -1, "", 0, FALSE);
            free(tmp);
          }
          if(opttiny){
            showdoctiny(pairs[i].id, -1, pairs[i].score);
          } else {
            showdoc(tdoc, -1, pairs[i].score, NULL, 0);
          }
          oddocclose(tdoc);
!         show++;
        }
      }
      if(dirs) cbmapclose(dirs);
--- 1066,1084 ----
            cbmapput(dirs, tmp, -1, "", 0, FALSE);
            free(tmp);
          }
+       if(optpage > 1 && step < (optpage -1) * optmax){
+       	oddocclose(tdoc);
+       	step++;
+       	continue;
+       }
+       show++;
          if(opttiny){
            showdoctiny(pairs[i].id, -1, pairs[i].score);
          } else {
            showdoc(tdoc, -1, pairs[i].score, NULL, 0);
          }
          oddocclose(tdoc);
!         
        }
      }
      if(dirs) cbmapclose(dirs);
***************
*** 1081,1093 ****
    CBMAP *dirs;
    const char *dstr;
    char *tmp;
!   int i, err, unit, ldnum, pnum, lnum, date, show;
    err = FALSE;
    showpreamble();
    xmlprintf("<estxview version=\"%@\" options=\"%@\">\n", _EST_VERSION, getoptionstr());
    xmlprintf("<meta>\n");
    pairs = NULL;
!   unit = UNITINIT;
    if(optdrep > 0) unit *= optdrep + 1;
    if(strcmp(optstype, "score")) unit = INT_MAX;
    do {
--- 1102,1114 ----
    CBMAP *dirs;
    const char *dstr;
    char *tmp;
!   int i, err, unit, ldnum, pnum, lnum, date, show, step;
    err = FALSE;
    showpreamble();
    xmlprintf("<estxview version=\"%@\" options=\"%@\">\n", _EST_VERSION, getoptionstr());
    xmlprintf("<meta>\n");
    pairs = NULL;
!   unit = optboolunit;
    if(optdrep > 0) unit *= optdrep + 1;
    if(strcmp(optstype, "score")) unit = INT_MAX;
    do {
***************
*** 1132,1139 ****
      }
    }
    xmlprintf("<option max=\"%d\" tfidf=\"%@\" clshow=\"%d\" clcode=\"%d\""
!             " drep=\"%d\" expr=\"%?\" sort=\"%?\"/>\n",
!             optmax, optni ? "false" : "true", optclshow, optclcode, optdrep, optetype, optstype);
    if(pnum < 1){
      showerror("There is no corresponding document.", dpecode);
      err = TRUE;
--- 1153,1160 ----
      }
    }
    xmlprintf("<option max=\"%d\" tfidf=\"%@\" clshow=\"%d\" clcode=\"%d\""
!             " drep=\"%d\" expr=\"%?\" sort=\"%?\" boolunit=\"%d\" page=\"%d\"/>\n",
!             optmax, optni ? "false" : "true", optclshow, optclcode, optdrep, optetype, optstype,optboolunit,optpage);
    if(pnum < 1){
      showerror("There is no corresponding document.", dpecode);
      err = TRUE;
***************
*** 1143,1153 ****
--- 1164,1179 ----
    xmlprintf("</meta>\n");
    if(scdb && optclshow > 0 && pnum > 0) showclusters(pairs, &pnum);
    show = 0;
+   step=0;
    dirs = NULL;
    if(optdrep > 0) dirs = cbmapopen();
    for(i = 0; i < pnum && show < optmax; i++){
      if(opttiny && !dirs){
        if(!odcheck(odeum, pairs[i].id)) continue;
+       if(optpage > 1 && step < (optpage -1) * optmax){
+       	step++;
+       	continue;
+       }
        showdoctiny(pairs[i].id, pairs[i].score, -1.0);
        show++;
      } else {
***************
*** 1162,1174 ****
          cbmapput(dirs, tmp, -1, "", 0, FALSE);
          free(tmp);
        }
        if(opttiny){
          showdoctiny(pairs[i].id, pairs[i].score, -1.0);
        } else {
          showdoc(doc, pairs[i].score, -1.0, words, wnum);
        }
        oddocclose(doc);
-       show++;
      }
    }
    if(dirs) cbmapclose(dirs);
--- 1188,1205 ----
          cbmapput(dirs, tmp, -1, "", 0, FALSE);
          free(tmp);
        }
+       if(optpage > 1 && step < (optpage -1) * optmax){
+       	oddocclose(doc);
+       	step++;
+       	continue;
+       }
+       show++;
        if(opttiny){
          showdoctiny(pairs[i].id, pairs[i].score, -1.0);
        } else {
          showdoc(doc, pairs[i].score, -1.0, words, wnum);
        }
        oddocclose(doc);
      }
    }
    if(dirs) cbmapclose(dirs);

