1
0

fts1_tokenizer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. ** 2006 July 10
  3. **
  4. ** The author disclaims copyright to this source code.
  5. **
  6. *************************************************************************
  7. ** Defines the interface to tokenizers used by fulltext-search. There
  8. ** are three basic components:
  9. **
  10. ** sqlite3_tokenizer_module is a singleton defining the tokenizer
  11. ** interface functions. This is essentially the class structure for
  12. ** tokenizers.
  13. **
  14. ** sqlite3_tokenizer is used to define a particular tokenizer, perhaps
  15. ** including customization information defined at creation time.
  16. **
  17. ** sqlite3_tokenizer_cursor is generated by a tokenizer to generate
  18. ** tokens from a particular input.
  19. */
  20. #ifndef _FTS1_TOKENIZER_H_
  21. #define _FTS1_TOKENIZER_H_
  22. /* TODO(shess) Only used for SQLITE_OK and SQLITE_DONE at this time.
  23. ** If tokenizers are to be allowed to call sqlite3_*() functions, then
  24. ** we will need a way to register the API consistently.
  25. */
  26. #include "sqlite3.h"
  27. /*
  28. ** Structures used by the tokenizer interface.
  29. */
  30. typedef struct sqlite3_tokenizer sqlite3_tokenizer;
  31. typedef struct sqlite3_tokenizer_cursor sqlite3_tokenizer_cursor;
  32. typedef struct sqlite3_tokenizer_module sqlite3_tokenizer_module;
  33. struct sqlite3_tokenizer_module {
  34. int iVersion; /* currently 0 */
  35. /*
  36. ** Create and destroy a tokenizer. argc/argv are passed down from
  37. ** the fulltext virtual table creation to allow customization.
  38. */
  39. int (*xCreate)(int argc, const char *const*argv,
  40. sqlite3_tokenizer **ppTokenizer);
  41. int (*xDestroy)(sqlite3_tokenizer *pTokenizer);
  42. /*
  43. ** Tokenize a particular input. Call xOpen() to prepare to
  44. ** tokenize, xNext() repeatedly until it returns SQLITE_DONE, then
  45. ** xClose() to free any internal state. The pInput passed to
  46. ** xOpen() must exist until the cursor is closed. The ppToken
  47. ** result from xNext() is only valid until the next call to xNext()
  48. ** or until xClose() is called.
  49. */
  50. /* TODO(shess) current implementation requires pInput to be
  51. ** nul-terminated. This should either be fixed, or pInput/nBytes
  52. ** should be converted to zInput.
  53. */
  54. int (*xOpen)(sqlite3_tokenizer *pTokenizer,
  55. const char *pInput, int nBytes,
  56. sqlite3_tokenizer_cursor **ppCursor);
  57. int (*xClose)(sqlite3_tokenizer_cursor *pCursor);
  58. int (*xNext)(sqlite3_tokenizer_cursor *pCursor,
  59. const char **ppToken, int *pnBytes,
  60. int *piStartOffset, int *piEndOffset, int *piPosition);
  61. };
  62. struct sqlite3_tokenizer {
  63. const sqlite3_tokenizer_module *pModule; /* The module for this tokenizer */
  64. /* Tokenizer implementations will typically add additional fields */
  65. };
  66. struct sqlite3_tokenizer_cursor {
  67. sqlite3_tokenizer *pTokenizer; /* Tokenizer for this cursor. */
  68. /* Tokenizer implementations will typically add additional fields */
  69. };
  70. /*
  71. ** Get the module for a tokenizer which generates tokens based on a
  72. ** set of non-token characters. The default is to break tokens at any
  73. ** non-alnum character, though the set of delimiters can also be
  74. ** specified by the first argv argument to xCreate().
  75. */
  76. /* TODO(shess) This doesn't belong here. Need some sort of
  77. ** registration process.
  78. */
  79. void sqlite3Fts1SimpleTokenizerModule(sqlite3_tokenizer_module const**ppModule);
  80. void sqlite3Fts1PorterTokenizerModule(sqlite3_tokenizer_module const**ppModule);
  81. #endif /* _FTS1_TOKENIZER_H_ */