fts3_porter.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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 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. if( !stem(&z, "lanoita", "ate", m_gt_0) ){
  375. stem(&z, "lanoit", "tion", m_gt_0);
  376. }
  377. break;
  378. case 'c':
  379. if( !stem(&z, "icne", "ence", m_gt_0) ){
  380. stem(&z, "icna", "ance", m_gt_0);
  381. }
  382. break;
  383. case 'e':
  384. stem(&z, "rezi", "ize", m_gt_0);
  385. break;
  386. case 'g':
  387. stem(&z, "igol", "log", m_gt_0);
  388. break;
  389. case 'l':
  390. if( !stem(&z, "ilb", "ble", m_gt_0)
  391. && !stem(&z, "illa", "al", m_gt_0)
  392. && !stem(&z, "iltne", "ent", m_gt_0)
  393. && !stem(&z, "ile", "e", m_gt_0)
  394. ){
  395. stem(&z, "ilsuo", "ous", m_gt_0);
  396. }
  397. break;
  398. case 'o':
  399. if( !stem(&z, "noitazi", "ize", m_gt_0)
  400. && !stem(&z, "noita", "ate", m_gt_0)
  401. ){
  402. stem(&z, "rota", "ate", m_gt_0);
  403. }
  404. break;
  405. case 's':
  406. if( !stem(&z, "msila", "al", m_gt_0)
  407. && !stem(&z, "ssenevi", "ive", m_gt_0)
  408. && !stem(&z, "ssenluf", "ful", m_gt_0)
  409. ){
  410. stem(&z, "ssensuo", "ous", m_gt_0);
  411. }
  412. break;
  413. case 't':
  414. if( !stem(&z, "itila", "al", m_gt_0)
  415. && !stem(&z, "itivi", "ive", m_gt_0)
  416. ){
  417. stem(&z, "itilib", "ble", m_gt_0);
  418. }
  419. break;
  420. }
  421. /* Step 3 */
  422. switch( z[0] ){
  423. case 'e':
  424. if( !stem(&z, "etaci", "ic", m_gt_0)
  425. && !stem(&z, "evita", "", m_gt_0)
  426. ){
  427. stem(&z, "ezila", "al", m_gt_0);
  428. }
  429. break;
  430. case 'i':
  431. stem(&z, "itici", "ic", m_gt_0);
  432. break;
  433. case 'l':
  434. if( !stem(&z, "laci", "ic", m_gt_0) ){
  435. stem(&z, "luf", "", m_gt_0);
  436. }
  437. break;
  438. case 's':
  439. stem(&z, "ssen", "", m_gt_0);
  440. break;
  441. }
  442. /* Step 4 */
  443. switch( z[1] ){
  444. case 'a':
  445. if( z[0]=='l' && m_gt_1(z+2) ){
  446. z += 2;
  447. }
  448. break;
  449. case 'c':
  450. if( z[0]=='e' && z[2]=='n' && (z[3]=='a' || z[3]=='e') && m_gt_1(z+4) ){
  451. z += 4;
  452. }
  453. break;
  454. case 'e':
  455. if( z[0]=='r' && m_gt_1(z+2) ){
  456. z += 2;
  457. }
  458. break;
  459. case 'i':
  460. if( z[0]=='c' && m_gt_1(z+2) ){
  461. z += 2;
  462. }
  463. break;
  464. case 'l':
  465. if( z[0]=='e' && z[2]=='b' && (z[3]=='a' || z[3]=='i') && m_gt_1(z+4) ){
  466. z += 4;
  467. }
  468. break;
  469. case 'n':
  470. if( z[0]=='t' ){
  471. if( z[2]=='a' ){
  472. if( m_gt_1(z+3) ){
  473. z += 3;
  474. }
  475. }else if( z[2]=='e' ){
  476. if( !stem(&z, "tneme", "", m_gt_1)
  477. && !stem(&z, "tnem", "", m_gt_1)
  478. ){
  479. stem(&z, "tne", "", m_gt_1);
  480. }
  481. }
  482. }
  483. break;
  484. case 'o':
  485. if( z[0]=='u' ){
  486. if( m_gt_1(z+2) ){
  487. z += 2;
  488. }
  489. }else if( z[3]=='s' || z[3]=='t' ){
  490. stem(&z, "noi", "", m_gt_1);
  491. }
  492. break;
  493. case 's':
  494. if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){
  495. z += 3;
  496. }
  497. break;
  498. case 't':
  499. if( !stem(&z, "eta", "", m_gt_1) ){
  500. stem(&z, "iti", "", m_gt_1);
  501. }
  502. break;
  503. case 'u':
  504. if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){
  505. z += 3;
  506. }
  507. break;
  508. case 'v':
  509. case 'z':
  510. if( z[0]=='e' && z[2]=='i' && m_gt_1(z+3) ){
  511. z += 3;
  512. }
  513. break;
  514. }
  515. /* Step 5a */
  516. if( z[0]=='e' ){
  517. if( m_gt_1(z+1) ){
  518. z++;
  519. }else if( m_eq_1(z+1) && !star_oh(z+1) ){
  520. z++;
  521. }
  522. }
  523. /* Step 5b */
  524. if( m_gt_1(z) && z[0]=='l' && z[1]=='l' ){
  525. z++;
  526. }
  527. /* z[] is now the stemmed word in reverse order. Flip it back
  528. ** around into forward order and return.
  529. */
  530. *pnOut = i = (int)strlen(z);
  531. zOut[i] = 0;
  532. while( *z ){
  533. zOut[--i] = *(z++);
  534. }
  535. }
  536. /*
  537. ** Characters that can be part of a token. We assume any character
  538. ** whose value is greater than 0x80 (any UTF character) can be
  539. ** part of a token. In other words, delimiters all must have
  540. ** values of 0x7f or lower.
  541. */
  542. static const char porterIdChar[] = {
  543. /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
  544. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
  545. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
  546. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
  547. 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
  548. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
  549. };
  550. #define isDelim(C) (((ch=C)&0x80)==0 && (ch<0x30 || !porterIdChar[ch-0x30]))
  551. /*
  552. ** Extract the next token from a tokenization cursor. The cursor must
  553. ** have been opened by a prior call to porterOpen().
  554. */
  555. static int porterNext(
  556. sqlite3_tokenizer_cursor *pCursor, /* Cursor returned by porterOpen */
  557. const char **pzToken, /* OUT: *pzToken is the token text */
  558. int *pnBytes, /* OUT: Number of bytes in token */
  559. int *piStartOffset, /* OUT: Starting offset of token */
  560. int *piEndOffset, /* OUT: Ending offset of token */
  561. int *piPosition /* OUT: Position integer of token */
  562. ){
  563. porter_tokenizer_cursor *c = (porter_tokenizer_cursor *) pCursor;
  564. const char *z = c->zInput;
  565. while( c->iOffset<c->nInput ){
  566. int iStartOffset, ch;
  567. /* Scan past delimiter characters */
  568. while( c->iOffset<c->nInput && isDelim(z[c->iOffset]) ){
  569. c->iOffset++;
  570. }
  571. /* Count non-delimiter characters. */
  572. iStartOffset = c->iOffset;
  573. while( c->iOffset<c->nInput && !isDelim(z[c->iOffset]) ){
  574. c->iOffset++;
  575. }
  576. if( c->iOffset>iStartOffset ){
  577. int n = c->iOffset-iStartOffset;
  578. if( n>c->nAllocated ){
  579. char *pNew;
  580. c->nAllocated = n+20;
  581. pNew = sqlite3_realloc64(c->zToken, c->nAllocated);
  582. if( !pNew ) return SQLITE_NOMEM;
  583. c->zToken = pNew;
  584. }
  585. porter_stemmer(&z[iStartOffset], n, c->zToken, pnBytes);
  586. *pzToken = c->zToken;
  587. *piStartOffset = iStartOffset;
  588. *piEndOffset = c->iOffset;
  589. *piPosition = c->iToken++;
  590. return SQLITE_OK;
  591. }
  592. }
  593. return SQLITE_DONE;
  594. }
  595. /*
  596. ** The set of routines that implement the porter-stemmer tokenizer
  597. */
  598. static const sqlite3_tokenizer_module porterTokenizerModule = {
  599. 0,
  600. porterCreate,
  601. porterDestroy,
  602. porterOpen,
  603. porterClose,
  604. porterNext,
  605. 0
  606. };
  607. /*
  608. ** Allocate a new porter tokenizer. Return a pointer to the new
  609. ** tokenizer in *ppModule
  610. */
  611. void sqlite3Fts3PorterTokenizerModule(
  612. sqlite3_tokenizer_module const**ppModule
  613. ){
  614. *ppModule = &porterTokenizerModule;
  615. }
  616. #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */