fts3_porter.c 17 KB

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