fts2_porter.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. ** 2006 September 30
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** Implementation of the full-text-search tokenizer that implements
  13. ** a Porter stemmer.
  14. */
  15. /*
  16. ** The code in this file is only compiled if:
  17. **
  18. ** * The FTS2 module is being built as an extension
  19. ** (in which case SQLITE_CORE is not defined), or
  20. **
  21. ** * The FTS2 module is being built into the core of
  22. ** SQLite (in which case SQLITE_ENABLE_FTS2 is defined).
  23. */
  24. #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2)
  25. #include <assert.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include "sqlite3.h"
  30. #include "sqlite3ext.h"
  31. SQLITE_EXTENSION_INIT3
  32. #include "fts2_tokenizer.h"
  33. /*
  34. ** Class derived from sqlite3_tokenizer
  35. */
  36. typedef struct porter_tokenizer {
  37. sqlite3_tokenizer base; /* Base class */
  38. } porter_tokenizer;
  39. /*
  40. ** Class derived from sqlit3_tokenizer_cursor
  41. */
  42. typedef struct porter_tokenizer_cursor {
  43. sqlite3_tokenizer_cursor base;
  44. const char *zInput; /* input we are tokenizing */
  45. int nInput; /* size of the input */
  46. int iOffset; /* current position in zInput */
  47. int iToken; /* index of next token to be returned */
  48. char *zToken; /* storage for current token */
  49. int nAllocated; /* space allocated to zToken buffer */
  50. } porter_tokenizer_cursor;
  51. /* Forward declaration */
  52. static const sqlite3_tokenizer_module porterTokenizerModule;
  53. /*
  54. ** Create a new tokenizer instance.
  55. */
  56. static int porterCreate(
  57. int argc, const char * const *argv,
  58. sqlite3_tokenizer **ppTokenizer
  59. ){
  60. porter_tokenizer *t;
  61. t = (porter_tokenizer *) sqlite3_malloc(sizeof(*t));
  62. if( t==NULL ) return SQLITE_NOMEM;
  63. memset(t, 0, sizeof(*t));
  64. *ppTokenizer = &t->base;
  65. return SQLITE_OK;
  66. }
  67. /*
  68. ** Destroy a tokenizer
  69. */
  70. static int porterDestroy(sqlite3_tokenizer *pTokenizer){
  71. sqlite3_free(pTokenizer);
  72. return SQLITE_OK;
  73. }
  74. /*
  75. ** Prepare to begin tokenizing a particular string. The input
  76. ** string to be tokenized is zInput[0..nInput-1]. A cursor
  77. ** used to incrementally tokenize this string is returned in
  78. ** *ppCursor.
  79. */
  80. static int porterOpen(
  81. sqlite3_tokenizer *pTokenizer, /* The tokenizer */
  82. const char *zInput, int nInput, /* String to be tokenized */
  83. sqlite3_tokenizer_cursor **ppCursor /* OUT: Tokenization cursor */
  84. ){
  85. porter_tokenizer_cursor *c;
  86. c = (porter_tokenizer_cursor *) sqlite3_malloc(sizeof(*c));
  87. if( c==NULL ) return SQLITE_NOMEM;
  88. c->zInput = zInput;
  89. if( zInput==0 ){
  90. c->nInput = 0;
  91. }else if( nInput<0 ){
  92. c->nInput = (int)strlen(zInput);
  93. }else{
  94. c->nInput = nInput;
  95. }
  96. c->iOffset = 0; /* start tokenizing at the beginning */
  97. c->iToken = 0;
  98. c->zToken = NULL; /* no space allocated, yet. */
  99. c->nAllocated = 0;
  100. *ppCursor = &c->base;
  101. return SQLITE_OK;
  102. }
  103. /*
  104. ** Close a tokenization cursor previously opened by a call to
  105. ** porterOpen() above.
  106. */
  107. static int porterClose(sqlite3_tokenizer_cursor *pCursor){
  108. porter_tokenizer_cursor *c = (porter_tokenizer_cursor *) pCursor;
  109. sqlite3_free(c->zToken);
  110. sqlite3_free(c);
  111. return SQLITE_OK;
  112. }
  113. /*
  114. ** Vowel or consonant
  115. */
  116. static const char cType[] = {
  117. 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
  118. 1, 1, 1, 2, 1
  119. };
  120. /*
  121. ** isConsonant() and isVowel() determine if their first character in
  122. ** the string they point to is a consonant or a vowel, according
  123. ** to Porter ruls.
  124. **
  125. ** A consonate is any letter other than 'a', 'e', 'i', 'o', or 'u'.
  126. ** 'Y' is a consonant unless it follows another consonant,
  127. ** in which case it is a vowel.
  128. **
  129. ** In these routine, the letters are in reverse order. So the 'y' rule
  130. ** is that 'y' is a consonant unless it is followed by another
  131. ** consonent.
  132. */
  133. static int isVowel(const char*);
  134. static int isConsonant(const char *z){
  135. int j;
  136. char x = *z;
  137. if( x==0 ) return 0;
  138. assert( x>='a' && x<='z' );
  139. j = cType[x-'a'];
  140. if( j<2 ) return j;
  141. return z[1]==0 || isVowel(z + 1);
  142. }
  143. static int isVowel(const char *z){
  144. int j;
  145. char x = *z;
  146. if( x==0 ) return 0;
  147. assert( x>='a' && x<='z' );
  148. j = cType[x-'a'];
  149. if( j<2 ) return 1-j;
  150. return isConsonant(z + 1);
  151. }
  152. /*
  153. ** Let any sequence of one or more vowels be represented by V and let
  154. ** C be sequence of one or more consonants. Then every word can be
  155. ** represented as:
  156. **
  157. ** [C] (VC){m} [V]
  158. **
  159. ** In prose: A word is an optional consonant followed by zero or
  160. ** vowel-consonant pairs followed by an optional vowel. "m" is the
  161. ** number of vowel consonant pairs. This routine computes the value
  162. ** of m for the first i bytes of a word.
  163. **
  164. ** Return true if the m-value for z is 1 or more. In other words,
  165. ** return true if z contains at least one vowel that is followed
  166. ** by a consonant.
  167. **
  168. ** In this routine z[] is in reverse order. So we are really looking
  169. ** for an instance of of a consonant followed by a vowel.
  170. */
  171. static int m_gt_0(const char *z){
  172. while( isVowel(z) ){ z++; }
  173. if( *z==0 ) return 0;
  174. while( isConsonant(z) ){ z++; }
  175. return *z!=0;
  176. }
  177. /* Like mgt0 above except we are looking for a value of m which is
  178. ** exactly 1
  179. */
  180. static int m_eq_1(const char *z){
  181. while( isVowel(z) ){ z++; }
  182. if( *z==0 ) return 0;
  183. while( isConsonant(z) ){ z++; }
  184. if( *z==0 ) return 0;
  185. while( isVowel(z) ){ z++; }
  186. if( *z==0 ) return 1;
  187. while( isConsonant(z) ){ z++; }
  188. return *z==0;
  189. }
  190. /* Like mgt0 above except we are looking for a value of m>1 instead
  191. ** or m>0
  192. */
  193. static int m_gt_1(const char *z){
  194. while( isVowel(z) ){ z++; }
  195. if( *z==0 ) return 0;
  196. while( isConsonant(z) ){ z++; }
  197. if( *z==0 ) return 0;
  198. while( isVowel(z) ){ z++; }
  199. if( *z==0 ) return 0;
  200. while( isConsonant(z) ){ z++; }
  201. return *z!=0;
  202. }
  203. /*
  204. ** Return TRUE if there is a vowel anywhere within z[0..n-1]
  205. */
  206. static int hasVowel(const char *z){
  207. while( isConsonant(z) ){ z++; }
  208. return *z!=0;
  209. }
  210. /*
  211. ** Return TRUE if the word ends in a double consonant.
  212. **
  213. ** The text is reversed here. So we are really looking at
  214. ** the first two characters of z[].
  215. */
  216. static int doubleConsonant(const char *z){
  217. return isConsonant(z) && z[0]==z[1] && isConsonant(z+1);
  218. }
  219. /*
  220. ** Return TRUE if the word ends with three letters which
  221. ** are consonant-vowel-consonent and where the final consonant
  222. ** is not 'w', 'x', or 'y'.
  223. **
  224. ** The word is reversed here. So we are really checking the
  225. ** first three letters and the first one cannot be in [wxy].
  226. */
  227. static int star_oh(const char *z){
  228. return
  229. z[0]!=0 && isConsonant(z) &&
  230. z[0]!='w' && z[0]!='x' && z[0]!='y' &&
  231. z[1]!=0 && isVowel(z+1) &&
  232. z[2]!=0 && isConsonant(z+2);
  233. }
  234. /*
  235. ** If the word ends with zFrom and xCond() is true for the stem
  236. ** of the word that preceeds the zFrom ending, then change the
  237. ** ending to zTo.
  238. **
  239. ** The input word *pz and zFrom are both in reverse order. zTo
  240. ** is in normal order.
  241. **
  242. ** Return TRUE if zFrom matches. Return FALSE if zFrom does not
  243. ** match. Not that TRUE is returned even if xCond() fails and
  244. ** no substitution occurs.
  245. */
  246. static int stem(
  247. char **pz, /* The word being stemmed (Reversed) */
  248. const char *zFrom, /* If the ending matches this... (Reversed) */
  249. const char *zTo, /* ... change the ending to this (not reversed) */
  250. int (*xCond)(const char*) /* Condition that must be true */
  251. ){
  252. char *z = *pz;
  253. while( *zFrom && *zFrom==*z ){ z++; zFrom++; }
  254. if( *zFrom!=0 ) return 0;
  255. if( xCond && !xCond(z) ) return 1;
  256. while( *zTo ){
  257. *(--z) = *(zTo++);
  258. }
  259. *pz = z;
  260. return 1;
  261. }
  262. /*
  263. ** This is the fallback stemmer used when the porter stemmer is
  264. ** inappropriate. The input word is copied into the output with
  265. ** US-ASCII case folding. If the input word is too long (more
  266. ** than 20 bytes if it contains no digits or more than 6 bytes if
  267. ** it contains digits) then word is truncated to 20 or 6 bytes
  268. ** by taking 10 or 3 bytes from the beginning and end.
  269. */
  270. static void copy_stemmer(const char *zIn, int nIn, char *zOut, int *pnOut){
  271. int i, mx, j;
  272. int hasDigit = 0;
  273. for(i=0; i<nIn; i++){
  274. int c = zIn[i];
  275. if( c>='A' && c<='Z' ){
  276. zOut[i] = c - 'A' + 'a';
  277. }else{
  278. if( c>='0' && c<='9' ) hasDigit = 1;
  279. zOut[i] = c;
  280. }
  281. }
  282. mx = hasDigit ? 3 : 10;
  283. if( nIn>mx*2 ){
  284. for(j=mx, i=nIn-mx; i<nIn; i++, j++){
  285. zOut[j] = zOut[i];
  286. }
  287. i = j;
  288. }
  289. zOut[i] = 0;
  290. *pnOut = i;
  291. }
  292. /*
  293. ** Stem the input word zIn[0..nIn-1]. Store the output in zOut.
  294. ** zOut is at least big enough to hold nIn bytes. Write the actual
  295. ** size of the output word (exclusive of the '\0' terminator) into *pnOut.
  296. **
  297. ** Any upper-case characters in the US-ASCII character set ([A-Z])
  298. ** are converted to lower case. Upper-case UTF characters are
  299. ** unchanged.
  300. **
  301. ** Words that are longer than about 20 bytes are stemmed by retaining
  302. ** a few bytes from the beginning and the end of the word. If the
  303. ** word contains digits, 3 bytes are taken from the beginning and
  304. ** 3 bytes from the end. For long words without digits, 10 bytes
  305. ** are taken from each end. US-ASCII case folding still applies.
  306. **
  307. ** If the input word contains not digits but does characters not
  308. ** in [a-zA-Z] then no stemming is attempted and this routine just
  309. ** copies the input into the input into the output with US-ASCII
  310. ** case folding.
  311. **
  312. ** Stemming never increases the length of the word. So there is
  313. ** no chance of overflowing the zOut buffer.
  314. */
  315. static void porter_stemmer(const char *zIn, int nIn, char *zOut, int *pnOut){
  316. int i, j, c;
  317. char zReverse[28];
  318. char *z, *z2;
  319. if( nIn<3 || nIn>=sizeof(zReverse)-7 ){
  320. /* The word is too big or too small for the porter stemmer.
  321. ** Fallback to the copy stemmer */
  322. copy_stemmer(zIn, nIn, zOut, pnOut);
  323. return;
  324. }
  325. for(i=0, j=sizeof(zReverse)-6; i<nIn; i++, j--){
  326. c = zIn[i];
  327. if( c>='A' && c<='Z' ){
  328. zReverse[j] = c + 'a' - 'A';
  329. }else if( c>='a' && c<='z' ){
  330. zReverse[j] = c;
  331. }else{
  332. /* The use of a character not in [a-zA-Z] means that we fallback
  333. ** to the copy stemmer */
  334. copy_stemmer(zIn, nIn, zOut, pnOut);
  335. return;
  336. }
  337. }
  338. memset(&zReverse[sizeof(zReverse)-5], 0, 5);
  339. z = &zReverse[j+1];
  340. /* Step 1a */
  341. if( z[0]=='s' ){
  342. if(
  343. !stem(&z, "sess", "ss", 0) &&
  344. !stem(&z, "sei", "i", 0) &&
  345. !stem(&z, "ss", "ss", 0)
  346. ){
  347. z++;
  348. }
  349. }
  350. /* Step 1b */
  351. z2 = z;
  352. if( stem(&z, "dee", "ee", m_gt_0) ){
  353. /* Do nothing. The work was all in the test */
  354. }else if(
  355. (stem(&z, "gni", "", hasVowel) || stem(&z, "de", "", hasVowel))
  356. && z!=z2
  357. ){
  358. if( stem(&z, "ta", "ate", 0) ||
  359. stem(&z, "lb", "ble", 0) ||
  360. stem(&z, "zi", "ize", 0) ){
  361. /* Do nothing. The work was all in the test */
  362. }else if( doubleConsonant(z) && (*z!='l' && *z!='s' && *z!='z') ){
  363. z++;
  364. }else if( m_eq_1(z) && star_oh(z) ){
  365. *(--z) = 'e';
  366. }
  367. }
  368. /* Step 1c */
  369. if( z[0]=='y' && hasVowel(z+1) ){
  370. z[0] = 'i';
  371. }
  372. /* Step 2 */
  373. switch( z[1] ){
  374. case 'a':
  375. stem(&z, "lanoita", "ate", m_gt_0) ||
  376. stem(&z, "lanoit", "tion", m_gt_0);
  377. break;
  378. case 'c':
  379. stem(&z, "icne", "ence", m_gt_0) ||
  380. stem(&z, "icna", "ance", m_gt_0);
  381. break;
  382. case 'e':
  383. stem(&z, "rezi", "ize", m_gt_0);
  384. break;
  385. case 'g':
  386. stem(&z, "igol", "log", m_gt_0);
  387. break;
  388. case 'l':
  389. stem(&z, "ilb", "ble", m_gt_0) ||
  390. stem(&z, "illa", "al", m_gt_0) ||
  391. stem(&z, "iltne", "ent", m_gt_0) ||
  392. stem(&z, "ile", "e", m_gt_0) ||
  393. stem(&z, "ilsuo", "ous", m_gt_0);
  394. break;
  395. case 'o':
  396. stem(&z, "noitazi", "ize", m_gt_0) ||
  397. stem(&z, "noita", "ate", m_gt_0) ||
  398. stem(&z, "rota", "ate", m_gt_0);
  399. break;
  400. case 's':
  401. stem(&z, "msila", "al", m_gt_0) ||
  402. stem(&z, "ssenevi", "ive", m_gt_0) ||
  403. stem(&z, "ssenluf", "ful", m_gt_0) ||
  404. stem(&z, "ssensuo", "ous", m_gt_0);
  405. break;
  406. case 't':
  407. stem(&z, "itila", "al", m_gt_0) ||
  408. stem(&z, "itivi", "ive", m_gt_0) ||
  409. stem(&z, "itilib", "ble", m_gt_0);
  410. break;
  411. }
  412. /* Step 3 */
  413. switch( z[0] ){
  414. case 'e':
  415. stem(&z, "etaci", "ic", m_gt_0) ||
  416. stem(&z, "evita", "", m_gt_0) ||
  417. stem(&z, "ezila", "al", m_gt_0);
  418. break;
  419. case 'i':
  420. stem(&z, "itici", "ic", m_gt_0);
  421. break;
  422. case 'l':
  423. stem(&z, "laci", "ic", m_gt_0) ||
  424. stem(&z, "luf", "", m_gt_0);
  425. break;
  426. case 's':
  427. stem(&z, "ssen", "", m_gt_0);
  428. break;
  429. }
  430. /* Step 4 */
  431. switch( z[1] ){
  432. case 'a':
  433. if( z[0]=='l' && m_gt_1(z+2) ){
  434. z += 2;
  435. }
  436. break;
  437. case 'c':
  438. if( z[0]=='e' && z[2]=='n' && (z[3]=='a' || z[3]=='e') && m_gt_1(z+4) ){
  439. z += 4;
  440. }
  441. break;
  442. case 'e':
  443. if( z[0]=='r' && m_gt_1(z+2) ){
  444. z += 2;
  445. }
  446. break;
  447. case 'i':
  448. if( z[0]=='c' && m_gt_1(z+2) ){
  449. z += 2;
  450. }
  451. break;
  452. case 'l':
  453. if( z[0]=='e' && z[2]=='b' && (z[3]=='a' || z[3]=='i') && m_gt_1(z+4) ){
  454. z += 4;
  455. }
  456. break;
  457. case 'n':
  458. if( z[0]=='t' ){
  459. if( z[2]=='a' ){
  460. if( m_gt_1(z+3) ){
  461. z += 3;
  462. }
  463. }else if( z[2]=='e' ){
  464. stem(&z, "tneme", "", m_gt_1) ||
  465. stem(&z, "tnem", "", m_gt_1) ||
  466. stem(&z, "tne", "", m_gt_1);
  467. }
  468. }
  469. break;
  470. case 'o':
  471. if( z[0]=='u' ){
  472. if( m_gt_1(z+2) ){
  473. z += 2;
  474. }
  475. }else if( z[3]=='s' || z[3]=='t' ){
  476. stem(&z, "noi", "", m_gt_1);
  477. }
  478. break;
  479. case 's':
  480. if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
  481. z += 3;
  482. }
  483. break;
  484. case 't':
  485. stem(&z, "eta", "", m_gt_1) ||
  486. stem(&z, "iti", "", m_gt_1);
  487. break;
  488. case 'u':
  489. if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
  490. z += 3;
  491. }
  492. break;
  493. case 'v':
  494. case 'z':
  495. if( z[0]=='e' && z[2]=='i' && m_gt_1(z+3) ){
  496. z += 3;
  497. }
  498. break;
  499. }
  500. /* Step 5a */
  501. if( z[0]=='e' ){
  502. if( m_gt_1(z+1) ){
  503. z++;
  504. }else if( m_eq_1(z+1) && !star_oh(z+1) ){
  505. z++;
  506. }
  507. }
  508. /* Step 5b */
  509. if( m_gt_1(z) && z[0]=='l' && z[1]=='l' ){
  510. z++;
  511. }
  512. /* z[] is now the stemmed word in reverse order. Flip it back
  513. ** around into forward order and return.
  514. */
  515. *pnOut = i = strlen(z);
  516. zOut[i] = 0;
  517. while( *z ){
  518. zOut[--i] = *(z++);
  519. }
  520. }
  521. /*
  522. ** Characters that can be part of a token. We assume any character
  523. ** whose value is greater than 0x80 (any UTF character) can be
  524. ** part of a token. In other words, delimiters all must have
  525. ** values of 0x7f or lower.
  526. */
  527. static const char porterIdChar[] = {
  528. /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
  529. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
  530. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
  531. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
  532. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
  533. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
  534. };
  535. #define isDelim(C) (((ch=C)&0x80)==0 && (ch<0x30 || !porterIdChar[ch-0x30]))
  536. /*
  537. ** Extract the next token from a tokenization cursor. The cursor must
  538. ** have been opened by a prior call to porterOpen().
  539. */
  540. static int porterNext(
  541. sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by porterOpen */
  542. const char **pzToken, /* OUT: *pzToken is the token text */
  543. int *pnBytes, /* OUT: Number of bytes in token */
  544. int *piStartOffset, /* OUT: Starting offset of token */
  545. int *piEndOffset, /* OUT: Ending offset of token */
  546. int *piPosition /* OUT: Position integer of token */
  547. ){
  548. porter_tokenizer_cursor *c = (porter_tokenizer_cursor *) pCursor;
  549. const char *z = c->zInput;
  550. while( c->iOffset<c->nInput ){
  551. int iStartOffset, ch;
  552. /* Scan past delimiter characters */
  553. while( c->iOffset<c->nInput && isDelim(z[c->iOffset]) ){
  554. c->iOffset++;
  555. }
  556. /* Count non-delimiter characters. */
  557. iStartOffset = c->iOffset;
  558. while( c->iOffset<c->nInput && !isDelim(z[c->iOffset]) ){
  559. c->iOffset++;
  560. }
  561. if( c->iOffset>iStartOffset ){
  562. int n = c->iOffset-iStartOffset;
  563. if( n>c->nAllocated ){
  564. c->nAllocated = n+20;
  565. c->zToken = sqlite3_realloc(c->zToken, c->nAllocated);
  566. if( c->zToken==NULL ) return SQLITE_NOMEM;
  567. }
  568. porter_stemmer(&z[iStartOffset], n, c->zToken, pnBytes);
  569. *pzToken = c->zToken;
  570. *piStartOffset = iStartOffset;
  571. *piEndOffset = c->iOffset;
  572. *piPosition = c->iToken++;
  573. return SQLITE_OK;
  574. }
  575. }
  576. return SQLITE_DONE;
  577. }
  578. /*
  579. ** The set of routines that implement the porter-stemmer tokenizer
  580. */
  581. static const sqlite3_tokenizer_module porterTokenizerModule = {
  582. 0,
  583. porterCreate,
  584. porterDestroy,
  585. porterOpen,
  586. porterClose,
  587. porterNext,
  588. };
  589. /*
  590. ** Allocate a new porter tokenizer. Return a pointer to the new
  591. ** tokenizer in *ppModule
  592. */
  593. void sqlite3Fts2PorterTokenizerModule(
  594. sqlite3_tokenizer_module const**ppModule
  595. ){
  596. *ppModule = &porterTokenizerModule;
  597. }
  598. #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS2) */