/ Check-in [aef1e8f4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the 'y' flag to the fts3/4 matchinfo() function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: aef1e8f47123e2e865432a0abf194dea4f23447a
User & Date: dan 2015-05-04 12:29:50
Context
2015-05-04
13:25
Add the --lib option to the sqldiff.exe command-line utility. check-in: a117e8f6 user: drh tags: trunk
12:29
Add the 'y' flag to the fts3/4 matchinfo() function. check-in: aef1e8f4 user: dan tags: trunk
2015-05-02
19:54
Improvements to fuzzershell: Avoid excess memory allocations when loading many files. Show the total runtime on final output. Show individual filenames as they are processed even if they are single test-case files. check-in: 34a722a2 user: drh tags: trunk
09:44
Add the experimental matchinfo 'y' flag to fts3/4. Closed-Leaf check-in: 92941609 user: dan tags: fts3-matchinfo-y
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_snippet.c.

    23     23   #define FTS3_MATCHINFO_NPHRASE   'p'        /* 1 value */
    24     24   #define FTS3_MATCHINFO_NCOL      'c'        /* 1 value */
    25     25   #define FTS3_MATCHINFO_NDOC      'n'        /* 1 value */
    26     26   #define FTS3_MATCHINFO_AVGLENGTH 'a'        /* nCol values */
    27     27   #define FTS3_MATCHINFO_LENGTH    'l'        /* nCol values */
    28     28   #define FTS3_MATCHINFO_LCS       's'        /* nCol values */
    29     29   #define FTS3_MATCHINFO_HITS      'x'        /* 3*nCol*nPhrase values */
           30  +#define FTS3_MATCHINFO_LHITS     'y'        /* nCol*nPhrase values */
    30     31   
    31     32   /*
    32     33   ** The default value for the second argument to matchinfo(). 
    33     34   */
    34     35   #define FTS3_MATCHINFO_DEFAULT   "pcx"
    35     36   
    36     37   
................................................................................
   804    805       }else{
   805    806         p->aMatchinfo[iStart+i*3] = 0;
   806    807       }
   807    808     }
   808    809   
   809    810     return rc;
   810    811   }
          812  +
          813  +/*
          814  +** fts3ExprIterate() callback used to gather information for the matchinfo
          815  +** directive 'y'.
          816  +*/
          817  +static int fts3ExprLHitsCb(
          818  +  Fts3Expr *pExpr,                /* Phrase expression node */
          819  +  int iPhrase,                    /* Phrase number */
          820  +  void *pCtx                      /* Pointer to MatchInfo structure */
          821  +){
          822  +  MatchInfo *p = (MatchInfo *)pCtx;
          823  +  Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
          824  +  int rc = SQLITE_OK;
          825  +  int iStart = iPhrase * p->nCol;
          826  +  Fts3Expr *pEof;                 /* Ancestor node already at EOF */
          827  +  
          828  +  /* This must be a phrase */
          829  +  assert( pExpr->pPhrase );
          830  +
          831  +  /* Initialize all output integers to zero. */
          832  +  memset(&p->aMatchinfo[iStart], 0, sizeof(u32) * p->nCol);
          833  +
          834  +  /* Check if this or any parent node is at EOF. If so, then all output
          835  +  ** values are zero.  */
          836  +  for(pEof=pExpr; pEof && pEof->bEof==0; pEof=pEof->pParent);
          837  +
          838  +  if( pEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
          839  +    Fts3Phrase *pPhrase = pExpr->pPhrase;
          840  +    char *pIter = pPhrase->doclist.pList;
          841  +    int iCol = 0;
          842  +
          843  +    while( 1 ){
          844  +      int nHit = fts3ColumnlistCount(&pIter);
          845  +      if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
          846  +        p->aMatchinfo[iStart + iCol] = (u32)nHit;
          847  +      }
          848  +      assert( *pIter==0x00 || *pIter==0x01 );
          849  +      if( *pIter!=0x01 ) break;
          850  +      pIter++;
          851  +      pIter += fts3GetVarint32(pIter, &iCol);
          852  +    }
          853  +  }
          854  +
          855  +  return rc;
          856  +}
   811    857   
   812    858   static int fts3MatchinfoCheck(
   813    859     Fts3Table *pTab, 
   814    860     char cArg,
   815    861     char **pzErr
   816    862   ){
   817    863     if( (cArg==FTS3_MATCHINFO_NPHRASE)
   818    864      || (cArg==FTS3_MATCHINFO_NCOL)
   819    865      || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
   820    866      || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
   821    867      || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
   822    868      || (cArg==FTS3_MATCHINFO_LCS)
   823    869      || (cArg==FTS3_MATCHINFO_HITS)
          870  +   || (cArg==FTS3_MATCHINFO_LHITS)
   824    871     ){
   825    872       return SQLITE_OK;
   826    873     }
   827    874     sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
   828    875     return SQLITE_ERROR;
   829    876   }
   830    877   
................................................................................
   839    886         break;
   840    887   
   841    888       case FTS3_MATCHINFO_AVGLENGTH:
   842    889       case FTS3_MATCHINFO_LENGTH:
   843    890       case FTS3_MATCHINFO_LCS:
   844    891         nVal = pInfo->nCol;
   845    892         break;
          893  +
          894  +    case FTS3_MATCHINFO_LHITS:
          895  +      nVal = pInfo->nCol * pInfo->nPhrase;
          896  +      break;
   846    897   
   847    898       default:
   848    899         assert( cArg==FTS3_MATCHINFO_HITS );
   849    900         nVal = pInfo->nCol * pInfo->nPhrase * 3;
   850    901         break;
   851    902     }
   852    903   
................................................................................
  1093   1144   
  1094   1145         case FTS3_MATCHINFO_LCS:
  1095   1146           rc = fts3ExprLoadDoclists(pCsr, 0, 0);
  1096   1147           if( rc==SQLITE_OK ){
  1097   1148             rc = fts3MatchinfoLcs(pCsr, pInfo);
  1098   1149           }
  1099   1150           break;
         1151  +
         1152  +      case FTS3_MATCHINFO_LHITS:
         1153  +        (void)fts3ExprIterate(pCsr->pExpr, fts3ExprLHitsCb, (void*)pInfo);
         1154  +        break;
  1100   1155   
  1101   1156         default: {
  1102   1157           Fts3Expr *pExpr;
  1103   1158           assert( zArg[i]==FTS3_MATCHINFO_HITS );
  1104   1159           pExpr = pCsr->pExpr;
  1105   1160           rc = fts3ExprLoadDoclists(pCsr, 0, 0);
  1106   1161           if( rc!=SQLITE_OK ) break;

Changes to test/fts3matchinfo.test.

   445    445       JOIN (SELECT 1 AS idx UNION SELECT 2 UNION SELECT 3) AS x
   446    446      WHERE t10 MATCH x.idx
   447    447        AND matchinfo(t10) not null
   448    448      GROUP BY docId
   449    449      ORDER BY 1;
   450    450   } {1 1 one 2 2 two 3 3 three}
   451    451     
          452  +#---------------------------------------------------------------------------
          453  +# Test the 'y' matchinfo flag
          454  +#
          455  +set sqlite_fts3_enable_parentheses 1
          456  +reset_db
          457  +do_execsql_test 11.0 {
          458  +  CREATE VIRTUAL TABLE tt USING fts3(x, y);
          459  +  INSERT INTO tt VALUES('c d a c d d', 'e a g b d a');   -- 1
          460  +  INSERT INTO tt VALUES('c c g a e b', 'c g d g e c');   -- 2
          461  +  INSERT INTO tt VALUES('b e f d e g', 'b a c b c g');   -- 3
          462  +  INSERT INTO tt VALUES('a c f f g d', 'd b f d e g');   -- 4
          463  +  INSERT INTO tt VALUES('g a c f c f', 'd g g b c c');   -- 5
          464  +  INSERT INTO tt VALUES('g a c e b b', 'd b f b g g');   -- 6
          465  +  INSERT INTO tt VALUES('f d a a f c', 'e e a d c f');   -- 7
          466  +  INSERT INTO tt VALUES('a c b b g f', 'a b a e d f');   -- 8
          467  +  INSERT INTO tt VALUES('b a f e c c', 'f d b b a b');   -- 9
          468  +  INSERT INTO tt VALUES('f d c e a c', 'f a f a a f');   -- 10
          469  +}
          470  +
          471  +db func mit mit
          472  +foreach {tn expr res} {
          473  +  1 "a" {
          474  +      1 {1 2}   2 {1 0}   3 {0 1}   4 {1 0}   5 {1 0}
          475  +      6 {1 0}   7 {2 1}   8 {1 2}   9 {1 1}  10 {1 3}
          476  +  }
          477  +
          478  +  2 "b" {
          479  +      1 {0 1}   2 {1 0}   3 {1 2}   4 {0 1}   5 {0 1}
          480  +      6 {2 2}             8 {2 1}   9 {1 3}            
          481  +  }
          482  +
          483  +  3 "y:a" {
          484  +      1 {0 2}             3 {0 1}                    
          485  +                7 {0 1}   8 {0 2}   9 {0 1}  10 {0 3}
          486  +  }
          487  +
          488  +  4 "x:a" {
          489  +      1 {1 0}   2 {1 0}             4 {1 0}   5 {1 0}
          490  +      6 {1 0}   7 {2 0}   8 {1 0}   9 {1 0}  10 {1 0}
          491  +  }
          492  +
          493  +  5 "a OR b" {
          494  +      1 {1 2 0 1}   2 {1 0 1 0}   3 {0 1 1 2}   4 {1 0 0 1}   5 {1 0 0 1}
          495  +      6 {1 0 2 2}   7 {2 1 0 0}   8 {1 2 2 1}   9 {1 1 1 3}  10 {1 3 0 0}
          496  +  }
          497  +
          498  +  6 "a AND b" {
          499  +      1 {1 2 0 1}   2 {1 0 1 0}   3 {0 1 1 2}   4 {1 0 0 1}   5 {1 0 0 1}
          500  +      6 {1 0 2 2}                 8 {1 2 2 1}   9 {1 1 1 3}              
          501  +  }
          502  +
          503  +  7 "a OR (a AND b)" {
          504  +      1 {1 2 1 2 0 1}   2 {1 0 1 0 1 0}   3 {0 1 0 1 1 2}   4 {1 0 1 0 0 1}   
          505  +      5 {1 0 1 0 0 1}   6 {1 0 1 0 2 2}   7 {2 1 0 0 0 0}   8 {1 2 1 2 2 1}   
          506  +      9 {1 1 1 1 1 3}  10 {1 3 0 0 0 0}
          507  +  }
          508  +
          509  +} {
          510  +  do_execsql_test 11.1.$tn  {
          511  +    SELECT rowid, mit(matchinfo(tt, 'y')) FROM tt WHERE tt MATCH $expr
          512  +  } $res
          513  +}
          514  +set sqlite_fts3_enable_parentheses 0
   452    515   
   453    516   finish_test