fts1_porter.c 17 KB

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