SQLite4
Check-in [069e299d06]
Not logged in

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

Overview
Comment:Add support for the "columnname : phrase" syntax to fts5.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 069e299d061d27423ccbfa515cba2ecde00d394e
User & Date: dan 2012-12-30 12:03:06
Context
2013-01-01
09:07
Avoid leaking shared-memory pages when rolling back a large transaction. check-in: d9a06d9403 user: dan tags: trunk
2012-12-30
12:03
Add support for the "columnname : phrase" syntax to fts5. check-in: 069e299d06 user: dan tags: trunk
11:45
Add support for prefix queries to fts5. Still no support for prefix indexes, just prefix queries using the regular term index. check-in: dd018f834a user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/fts5.c.

1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
....
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
....
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
      return 0;
    }
  }

  return (p->iCol==pFirst->iCol && p->iOff==iReq);
}

static int fts5StringFindInstances(Fts5Cursor *pCsr, Fts5Str *pStr){
  int i;
  int rc = SQLITE4_OK;
  int bEof = 0;
  int nByte = sizeof(InstanceList) * pStr->nToken;
  InstanceList *aIn;
  InstanceList out;

................................................................................
  }

  while( rc==SQLITE4_OK && bEof==0 ){
    for(i=1; i<pStr->nToken; i++){
      int bMatch = fts5TokenAdvanceToMatch(&aIn[i], &aIn[0], i, &bEof);
      if( bMatch==0 || bEof ) break;
    }
    if( i==pStr->nToken ){
      /* Record a match here */
      fts5InstanceListAppend(&out, aIn[0].iCol, aIn[0].iWeight, aIn[0].iOff);
    }
    bEof = fts5InstanceListNext(&aIn[0]);
  }

  pStr->nList = out.iList;
................................................................................

  /* At this point, it is established that all of the token cursors in the
  ** phrase point to an entry with the same primary key. Now figure out if
  ** the various string constraints are met. Along the way, synthesize a 
  ** position list for each Fts5Str object.  */
  for(i=0; rc==SQLITE4_OK && i<pPhrase->nStr; i++){
    Fts5Str *pStr = &pPhrase->aStr[i];
    rc = fts5StringFindInstances(pCsr, pStr);
  }

  /* Trim the instance lists according to any NEAR constraints.  */
  for(i=1; rc==SQLITE4_OK && i<pPhrase->nStr; i++){
    int n = pPhrase->aiNear[i-1];
    rc = fts5StringNearTrim(pCsr, &pPhrase->aStr[i], &pPhrase->aStr[i-1], n);
  }







|







 







|







 







|







1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
....
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
....
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
      return 0;
    }
  }

  return (p->iCol==pFirst->iCol && p->iOff==iReq);
}

static int fts5StringFindInstances(Fts5Cursor *pCsr, int iCol, Fts5Str *pStr){
  int i;
  int rc = SQLITE4_OK;
  int bEof = 0;
  int nByte = sizeof(InstanceList) * pStr->nToken;
  InstanceList *aIn;
  InstanceList out;

................................................................................
  }

  while( rc==SQLITE4_OK && bEof==0 ){
    for(i=1; i<pStr->nToken; i++){
      int bMatch = fts5TokenAdvanceToMatch(&aIn[i], &aIn[0], i, &bEof);
      if( bMatch==0 || bEof ) break;
    }
    if( i==pStr->nToken && (iCol<0 || aIn[0].iCol==iCol) ){
      /* Record a match here */
      fts5InstanceListAppend(&out, aIn[0].iCol, aIn[0].iWeight, aIn[0].iOff);
    }
    bEof = fts5InstanceListNext(&aIn[0]);
  }

  pStr->nList = out.iList;
................................................................................

  /* At this point, it is established that all of the token cursors in the
  ** phrase point to an entry with the same primary key. Now figure out if
  ** the various string constraints are met. Along the way, synthesize a 
  ** position list for each Fts5Str object.  */
  for(i=0; rc==SQLITE4_OK && i<pPhrase->nStr; i++){
    Fts5Str *pStr = &pPhrase->aStr[i];
    rc = fts5StringFindInstances(pCsr, pPhrase->iCol, pStr);
  }

  /* Trim the instance lists according to any NEAR constraints.  */
  for(i=1; rc==SQLITE4_OK && i<pPhrase->nStr; i++){
    int n = pPhrase->aiNear[i-1];
    rc = fts5StringNearTrim(pCsr, &pPhrase->aStr[i], &pPhrase->aStr[i-1], n);
  }

Changes to test/fts5query1.test.

99
100
101
102
103
104
105
106
107
108
109
110
111
112


113
114
115
116
117
118
119





















120
121
122
  INSERT INTO t3 VALUES(123, 'fix the hash table', NULL, NULL);
}
do_execsql_test 5.1 {
  SELECT docid FROM t3 WHERE t3 MATCH 'h*';
} {123}

do_execsql_test 6.0 {

BEGIN TRANSACTION;
CREATE TABLE t4(docid PRIMARY KEY, a, b, c);
CREATE INDEX i4 ON t4 USING fts5();

INSERT INTO "t4" VALUES(34,'ndmv jk qhiv cnz kyev blu qs nxhf etm uen','uh hu as wcvo hw whgu wd zm saus jvg bmbx kyev bnyk wmbz yf uh rb yf ju blu jkb jk qkfl jk gimj uh brsu ptic ka ztc vniq uprt kyev rxcf blu bnyk mu hgjo rxcf rnxr vcy vllx mve nxhf kb iddj qpnv fal iddj ju zidh mu pvjr cu my blu ztc vllx ono ndmv ib mu qpnv ldfi jvg jvg ztc uprt qrwj ptic saus fltt uen cnz ju qrwj gfap jk krag bwsr kb csjq kn krag ono uv krag da cu bil wd sk','ib qrwj iddj cku qdye uv pnz hu wte kyev ka jvg hu mu las bwsr mu uv da szem vllx bwsr wfar blu uv ztc qpnv wwne osok qpnv');
INSERT INTO "t4" VALUES(50,'ldfi zlc cku cnz sk juhw nxhf iddj las hu qhiv bmbx nq kn uprt las jk pvjr urvy qs bwsr uyn pmh ssc fltt bmbx ldfi rnxr cnz yf rnxr ndmv wmbz fal pmh uyn sk uh szem uv ssc bnyk yle jvg zm hgjo uh blu jvg rxcf whgu ztc kyev xdza cku kyev juhw nq ldfi las uprt wwne uprt qrwj vniq fal szem fteo cnz bwsr jrx jk jpa uv pmh nq qdye gfap ldfi uen sk wgwd zidh cu gfap','wd ndmv saus pnz hgjo gimj ztc jrx krag jrx gimj qhiv saj hgjo jrx xdza gvp cku kn szem my saus bnyk saj pmh gw bnyk saj as zimg ssc kh pvjr fal etm cu jvg krag hbtv kb szem qdye uv bil aayx wmbz xdza zm ib ldfi brsu zm rnxr csjq ldfi kb vllx zidh','gw fteo ka cu ib hu fteo juhw yf pnz blu jk ka bnyk bwsr da pnz pvjr yf pmh csjq my ztc zm hbtv qrwj cnz hu mu za ldfi qpnv saj');


COMMIT;
}

breakpoint
do_execsql_test 6.1 {
  SELECT docid FROM t4 WHERE t4 MATCH 'm*' 
} {34 50}






















finish_test








<
|
|
|
<
<
<
>
>
|

<
<



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



99
100
101
102
103
104
105

106
107
108



109
110
111
112


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  INSERT INTO t3 VALUES(123, 'fix the hash table', NULL, NULL);
}
do_execsql_test 5.1 {
  SELECT docid FROM t3 WHERE t3 MATCH 'h*';
} {123}

do_execsql_test 6.0 {

  BEGIN TRANSACTION;
    CREATE TABLE t4(docid PRIMARY KEY, a);
    CREATE INDEX i4 ON t4 USING fts5();



    INSERT INTO "t4" VALUES(34, 'abc mnm xyz');
    INSERT INTO "t4" VALUES(50, 'abc mnm xyz');
  COMMIT;
}


do_execsql_test 6.1 {
  SELECT docid FROM t4 WHERE t4 MATCH 'm*' 
} {34 50}

#-------------------------------------------------------------------------
#
do_execsql_test 7.0 {
  BEGIN TRANSACTION;
    CREATE TABLE t7(docid PRIMARY KEY, a, b, c);
    CREATE INDEX i7 ON t7 USING fts5();
    INSERT INTO t7 VALUES(1, 'a b c', 'd e f', 'a b c');
    INSERT INTO t7 VALUES(2, 'x y z', 'a b c', 'a b c');
  COMMIT;
}

foreach {tn expr res} {
  1 {a}    {1 2}
  2 {a:a}  {1}
  3 {b:a}  {2}
  4 {c:a}  {1 2}
  5 {a:a*} {1}
} {
  do_execsql_test 7.$tn {SELECT docid FROM t7 WHERE t7 MATCH $expr} $res
}

finish_test