ts_public.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*-------------------------------------------------------------------------
  2. *
  3. * ts_public.h
  4. * Public interface to various tsearch modules, such as
  5. * parsers and dictionaries.
  6. *
  7. * Copyright (c) 1998-2016, PostgreSQL Global Development Group
  8. *
  9. * src/include/tsearch/ts_public.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef _PG_TS_PUBLIC_H_
  14. #define _PG_TS_PUBLIC_H_
  15. #include "tsearch/ts_type.h"
  16. /*
  17. * Parser's framework
  18. */
  19. /*
  20. * returning type for prslextype method of parser
  21. */
  22. typedef struct
  23. {
  24. int lexid;
  25. char *alias;
  26. char *descr;
  27. } LexDescr;
  28. /*
  29. * Interface to headline generator
  30. */
  31. typedef struct
  32. {
  33. uint32 selected:1,
  34. in:1,
  35. replace:1,
  36. repeated:1,
  37. skip:1,
  38. unused:3,
  39. type:8,
  40. len:16;
  41. WordEntryPos pos;
  42. char *word;
  43. QueryOperand *item;
  44. } HeadlineWordEntry;
  45. typedef struct
  46. {
  47. HeadlineWordEntry *words;
  48. int32 lenwords;
  49. int32 curwords;
  50. int32 vectorpos; /* positions a-la tsvector */
  51. char *startsel;
  52. char *stopsel;
  53. char *fragdelim;
  54. int16 startsellen;
  55. int16 stopsellen;
  56. int16 fragdelimlen;
  57. } HeadlineParsedText;
  58. /*
  59. * Common useful things for tsearch subsystem
  60. */
  61. extern char *get_tsearch_config_filename(const char *basename,
  62. const char *extension);
  63. /*
  64. * Often useful stopword list management
  65. */
  66. typedef struct
  67. {
  68. int len;
  69. char **stop;
  70. } StopList;
  71. extern void readstoplist(const char *fname, StopList *s,
  72. char *(*wordop) (const char *));
  73. extern bool searchstoplist(StopList *s, char *key);
  74. /*
  75. * Interface with dictionaries
  76. */
  77. /* return struct for any lexize function */
  78. typedef struct
  79. {
  80. /*----------
  81. * Number of current variant of split word. For example the Norwegian
  82. * word 'fotballklubber' has two variants to split: ( fotball, klubb )
  83. * and ( fot, ball, klubb ). So, dictionary should return:
  84. *
  85. * nvariant lexeme
  86. * 1 fotball
  87. * 1 klubb
  88. * 2 fot
  89. * 2 ball
  90. * 2 klubb
  91. *
  92. * In general, a TSLexeme will be considered to belong to the same split
  93. * variant as the previous one if they have the same nvariant value.
  94. * The exact values don't matter, only changes from one lexeme to next.
  95. *----------
  96. */
  97. uint16 nvariant;
  98. uint16 flags; /* See flag bits below */
  99. char *lexeme; /* C string */
  100. } TSLexeme;
  101. /* Flag bits that can appear in TSLexeme.flags */
  102. #define TSL_ADDPOS 0x01
  103. #define TSL_PREFIX 0x02
  104. #define TSL_FILTER 0x04
  105. /*
  106. * Struct for supporting complex dictionaries like thesaurus.
  107. * 4th argument for dictlexize method is a pointer to this
  108. */
  109. typedef struct
  110. {
  111. bool isend; /* in: marks for lexize_info about text end is
  112. * reached */
  113. bool getnext; /* out: dict wants next lexeme */
  114. void *private_state; /* internal dict state between calls with
  115. * getnext == true */
  116. } DictSubState;
  117. #endif /* _PG_TS_PUBLIC_H_ */