sphinxclient.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // $Id$
  3. //
  4. //
  5. // Copyright (c) 2001-2016, Andrew Aksyonoff
  6. // Copyright (c) 2008-2016, Sphinx Technologies Inc
  7. // All rights reserved
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU Library General Public License version 3 or later.
  11. // You should have received a copy of the LGPL license along with this program;
  12. // if you did not, you can find it at http://www.gnu.org/
  13. //
  14. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  15. // WARNING
  16. // We strongly recommend you to use SphinxQL instead of the API
  17. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  18. #ifndef _sphinxclient_
  19. #define _sphinxclient_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /// known searchd status codes
  24. enum
  25. {
  26. SEARCHD_OK = 0,
  27. SEARCHD_ERROR = 1,
  28. SEARCHD_RETRY = 2,
  29. SEARCHD_WARNING = 3
  30. };
  31. /// known match modes
  32. enum
  33. {
  34. SPH_MATCH_ALL = 0,
  35. SPH_MATCH_ANY = 1,
  36. SPH_MATCH_PHRASE = 2,
  37. SPH_MATCH_BOOLEAN = 3,
  38. SPH_MATCH_EXTENDED = 4,
  39. SPH_MATCH_FULLSCAN = 5,
  40. SPH_MATCH_EXTENDED2 = 6
  41. };
  42. /// known ranking modes (ext2 only)
  43. enum
  44. {
  45. SPH_RANK_PROXIMITY_BM25 = 0,
  46. SPH_RANK_BM25 = 1,
  47. SPH_RANK_NONE = 2,
  48. SPH_RANK_WORDCOUNT = 3,
  49. SPH_RANK_PROXIMITY = 4,
  50. SPH_RANK_MATCHANY = 5,
  51. SPH_RANK_FIELDMASK = 6,
  52. SPH_RANK_SPH04 = 7,
  53. SPH_RANK_EXPR = 8,
  54. SPH_RANK_TOTAL = 9,
  55. SPH_RANK_DEFAULT = SPH_RANK_PROXIMITY_BM25
  56. };
  57. /// known sort modes
  58. enum
  59. {
  60. SPH_SORT_RELEVANCE = 0,
  61. SPH_SORT_ATTR_DESC = 1,
  62. SPH_SORT_ATTR_ASC = 2,
  63. SPH_SORT_TIME_SEGMENTS = 3,
  64. SPH_SORT_EXTENDED = 4,
  65. SPH_SORT_EXPR = 5
  66. };
  67. /// known filter types
  68. enum
  69. { SPH_FILTER_VALUES = 0,
  70. SPH_FILTER_RANGE = 1,
  71. SPH_FILTER_FLOATRANGE = 2,
  72. SPH_FILTER_STRING = 3
  73. };
  74. /// known attribute types
  75. enum
  76. {
  77. SPH_ATTR_INTEGER = 1,
  78. SPH_ATTR_TIMESTAMP = 2,
  79. SPH_ATTR_ORDINAL = 3,
  80. SPH_ATTR_BOOL = 4,
  81. SPH_ATTR_FLOAT = 5,
  82. SPH_ATTR_BIGINT = 6,
  83. SPH_ATTR_STRING = 7,
  84. SPH_ATTR_DOUBLE = 13,
  85. SPH_ATTR_FACTORS = 1001,
  86. SPH_ATTR_MULTI = 0x40000001UL,
  87. SPH_ATTR_MULTI64 = 0x40000002UL
  88. };
  89. /// known grouping functions
  90. enum
  91. { SPH_GROUPBY_DAY = 0,
  92. SPH_GROUPBY_WEEK = 1,
  93. SPH_GROUPBY_MONTH = 2,
  94. SPH_GROUPBY_YEAR = 3,
  95. SPH_GROUPBY_ATTR = 4,
  96. SPH_GROUPBY_ATTRPAIR = 5
  97. };
  98. //////////////////////////////////////////////////////////////////////////
  99. #if defined(_MSC_VER)
  100. typedef __int64 sphinx_int64_t;
  101. typedef unsigned __int64 sphinx_uint64_t;
  102. #else // !defined(_MSC_VER)
  103. typedef long long sphinx_int64_t;
  104. typedef unsigned long long sphinx_uint64_t;
  105. #endif // !defined(_MSC_VER)
  106. typedef int sphinx_bool;
  107. #define SPH_TRUE 1
  108. #define SPH_FALSE 0
  109. //////////////////////////////////////////////////////////////////////////
  110. typedef struct st_sphinx_client sphinx_client;
  111. typedef struct st_sphinx_wordinfo
  112. {
  113. const char * word;
  114. int docs;
  115. int hits;
  116. } sphinx_wordinfo;
  117. typedef struct st_sphinx_result
  118. {
  119. const char * error;
  120. const char * warning;
  121. int status;
  122. int num_fields;
  123. char ** fields;
  124. int num_attrs;
  125. char ** attr_names;
  126. int * attr_types;
  127. int num_matches;
  128. void * values_pool;
  129. int total;
  130. int total_found;
  131. int time_msec;
  132. int num_words;
  133. sphinx_wordinfo * words;
  134. } sphinx_result;
  135. typedef struct st_sphinx_excerpt_options
  136. {
  137. const char * before_match;
  138. const char * after_match;
  139. const char * chunk_separator;
  140. const char * html_strip_mode;
  141. const char * passage_boundary;
  142. int limit;
  143. int limit_passages;
  144. int limit_words;
  145. int around;
  146. int start_passage_id;
  147. sphinx_bool single_passage;
  148. sphinx_bool use_boundaries;
  149. sphinx_bool weight_order;
  150. sphinx_bool force_all_words;
  151. sphinx_bool load_files;
  152. sphinx_bool allow_empty;
  153. sphinx_bool emit_zones;
  154. } sphinx_excerpt_options;
  155. typedef struct st_sphinx_keyword_info
  156. {
  157. char * tokenized;
  158. char * normalized;
  159. int num_docs;
  160. int num_hits;
  161. } sphinx_keyword_info;
  162. //////////////////////////////////////////////////////////////////////////
  163. sphinx_client * sphinx_create ( sphinx_bool copy_args );
  164. void sphinx_cleanup ( sphinx_client * client );
  165. void sphinx_destroy ( sphinx_client * client );
  166. const char * sphinx_error ( sphinx_client * client );
  167. const char * sphinx_warning ( sphinx_client * client );
  168. sphinx_bool sphinx_set_server ( sphinx_client * client, const char * host, int port );
  169. sphinx_bool sphinx_set_connect_timeout ( sphinx_client * client, float seconds );
  170. sphinx_bool sphinx_open ( sphinx_client * client );
  171. sphinx_bool sphinx_close ( sphinx_client * client );
  172. sphinx_bool sphinx_set_limits ( sphinx_client * client, int offset, int limit, int max_matches, int cutoff );
  173. sphinx_bool sphinx_set_max_query_time ( sphinx_client * client, int max_query_time );
  174. sphinx_bool sphinx_set_match_mode ( sphinx_client * client, int mode );
  175. sphinx_bool sphinx_set_ranking_mode ( sphinx_client * client, int ranker, const char * rankexpr );
  176. sphinx_bool sphinx_set_sort_mode ( sphinx_client * client, int mode, const char * sortby );
  177. sphinx_bool sphinx_set_field_weights ( sphinx_client * client, int num_weights, const char ** field_names, const int * field_weights );
  178. sphinx_bool sphinx_set_index_weights ( sphinx_client * client, int num_weights, const char ** index_names, const int * index_weights );
  179. sphinx_bool sphinx_set_id_range ( sphinx_client * client, sphinx_uint64_t minid, sphinx_uint64_t maxid );
  180. sphinx_bool sphinx_add_filter ( sphinx_client * client, const char * attr, int num_values, const sphinx_int64_t * values, sphinx_bool exclude );
  181. sphinx_bool sphinx_add_filter_string ( sphinx_client * client, const char * attr, const char * value, sphinx_bool exclude );
  182. sphinx_bool sphinx_add_filter_range ( sphinx_client * client, const char * attr, sphinx_int64_t umin, sphinx_int64_t umax, sphinx_bool exclude );
  183. sphinx_bool sphinx_add_filter_float_range ( sphinx_client * client, const char * attr, float fmin, float fmax, sphinx_bool exclude );
  184. sphinx_bool sphinx_set_geoanchor ( sphinx_client * client, const char * attr_latitude, const char * attr_longitude, float latitude, float longitude );
  185. sphinx_bool sphinx_set_groupby ( sphinx_client * client, const char * attr, int groupby_func, const char * group_sort );
  186. sphinx_bool sphinx_set_groupby_distinct ( sphinx_client * client, const char * attr );
  187. sphinx_bool sphinx_set_retries ( sphinx_client * client, int count, int delay );
  188. sphinx_bool sphinx_add_override ( sphinx_client * client, const char * attr, const sphinx_uint64_t * docids, int num_values, const unsigned int * values );
  189. sphinx_bool sphinx_set_select ( sphinx_client * client, const char * select_list );
  190. sphinx_bool sphinx_set_query_flags ( sphinx_client * client, const char * flag_name, sphinx_bool enabled, int max_predicted_msec );
  191. void sphinx_reset_query_flags ( sphinx_client * client );
  192. sphinx_bool sphinx_set_outer_select ( sphinx_client * client, const char * orderby, int offset, int limit );
  193. void sphinx_reset_outer_select ( sphinx_client * client );
  194. void sphinx_reset_filters ( sphinx_client * client );
  195. void sphinx_reset_groupby ( sphinx_client * client );
  196. sphinx_result * sphinx_query ( sphinx_client * client, const char * query, const char * index_list, const char * comment );
  197. int sphinx_add_query ( sphinx_client * client, const char * query, const char * index_list, const char * comment );
  198. sphinx_result * sphinx_run_queries ( sphinx_client * client );
  199. int sphinx_get_num_results ( sphinx_client * client );
  200. sphinx_uint64_t sphinx_get_id ( sphinx_result * result, int match );
  201. int sphinx_get_weight ( sphinx_result * result, int match );
  202. sphinx_int64_t sphinx_get_int ( sphinx_result * result, int match, int attr );
  203. float sphinx_get_float ( sphinx_result * result, int match, int attr );
  204. unsigned int * sphinx_get_mva ( sphinx_result * result, int match, int attr );
  205. sphinx_uint64_t sphinx_get_mva64_value ( unsigned int * mva, int i );
  206. const char * sphinx_get_string ( sphinx_result * result, int match, int attr );
  207. void sphinx_init_excerpt_options ( sphinx_excerpt_options * opts );
  208. char ** sphinx_build_excerpts ( sphinx_client * client, int num_docs, const char ** docs, const char * index, const char * words, sphinx_excerpt_options * opts );
  209. int sphinx_update_attributes ( sphinx_client * client, const char * index, int num_attrs, const char ** attrs, int num_docs, const sphinx_uint64_t * docids, const sphinx_int64_t * values );
  210. int sphinx_update_attributes_mva ( sphinx_client * client, const char * index, const char * attr, sphinx_uint64_t docid, int num_values, const unsigned int * values );
  211. sphinx_keyword_info * sphinx_build_keywords ( sphinx_client * client, const char * query, const char * index, sphinx_bool hits, int * out_num_keywords );
  212. char ** sphinx_status ( sphinx_client * client, int * num_rows, int * num_cols );
  213. char ** sphinx_status_extended ( sphinx_client * client, int * num_rows, int * num_cols, int local );
  214. void sphinx_status_destroy ( char ** status, int num_rows, int num_cols );
  215. /////////////////////////////////////////////////////////////////////////////
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219. #endif // _sphinxclient_
  220. //
  221. // $Id$
  222. //