summary refs log tree commit diff stats
path: root/lib/wrappers/sphinx.nim
blob: a4fce0205b6f72a43742abaf4be2f46fe04b8932 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#
# $Id: sphinxclient.h 2654 2011-01-31 01:20:58Z kevg $
#
#
# Copyright (c) 2001-2011, Andrew Aksyonoff
# Copyright (c) 2008-2011, Sphinx Technologies Inc
# All rights reserved
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library General Public License. You should
# have received a copy of the LGPL license along with this program; if you
# did not, you can find it at http://www.gnu.org/
#

## Nimrod wrapper for ``shpinx``.

{.deadCodeElim: on.}
when defined(windows):
  const
    sphinxDll* = "spinx.dll"
elif defined(macosx):
  const
    sphinxDll* = "libspinx.dylib"
else:
  const
    sphinxDll* = "libspinxclient.so"

#/ known searchd status codes:
const 
  SEARCHD_OK* = 0
  SEARCHD_ERROR* = 1
  SEARCHD_RETRY* = 2
  SEARCHD_WARNING* = 3

#/ known match modes

const 
  SPH_MATCH_ALL* = 0
  SPH_MATCH_ANY* = 1
  SPH_MATCH_PHRASE* = 2
  SPH_MATCH_BOOLEAN* = 3
  SPH_MATCH_EXTENDED* = 4
  SPH_MATCH_FULLSCAN* = 5
  SPH_MATCH_EXTENDED2* = 6

#/ known ranking modes (ext2 only)

const 
  SPH_RANK_PROXIMITY_BM25* = 0
  SPH_RANK_BM25* = 1
  SPH_RANK_NONE* = 2
  SPH_RANK_WORDCOUNT* = 3
  SPH_RANK_PROXIMITY* = 4
  SPH_RANK_MATCHANY* = 5
  SPH_RANK_FIELDMASK* = 6
  SPH_RANK_SPH04* = 7
  SPH_RANK_DEFAULT* = SPH_RANK_PROXIMITY_BM25

#/ known sort modes

const 
  SPH_SORT_RELEVANCE* = 0
  SPH_SORT_ATTR_DESC* = 1
  SPH_SORT_ATTR_ASC* = 2
  SPH_SORT_TIME_SEGMENTS* = 3
  SPH_SORT_EXTENDED* = 4
  SPH_SORT_EXPR* = 5

#/ known filter types

const 
  SPH_FILTER_VALUES* = 0
  SPH_FILTER_RANGE* = 1
  SPH_FILTER_FLOATRANGE* = 2

#/ known attribute types

const 
  SPH_ATTR_INTEGER* = 1
  SPH_ATTR_TIMESTAMP* = 2
  SPH_ATTR_ORDINAL* = 3
  SPH_ATTR_BOOL* = 4
  SPH_ATTR_FLOAT* = 5
  SPH_ATTR_BIGINT* = 6
  SPH_ATTR_STRING* = 7
  SPH_ATTR_MULTI* = 0x40000000

#/ known grouping functions

const 
  SPH_GROUPBY_DAY* = 0
  SPH_GROUPBY_WEEK* = 1
  SPH_GROUPBY_MONTH* = 2
  SPH_GROUPBY_YEAR* = 3
  SPH_GROUPBY_ATTR* = 4
  SPH_GROUPBY_ATTRPAIR* = 5

type  
  TSphinxBool* {.size: sizeof(cint).} = enum
    SPH_FALSE = 0,
    SPH_TRUE = 1

  Tclient {.pure, final.} = object
  PClient* = ptr TClient
  Twordinfo*{.pure, final.} = object 
    word*: cstring
    docs*: cint
    hits*: cint

  Tresult*{.pure, final.} = object 
    error*: cstring
    warning*: cstring
    status*: cint
    num_fields*: cint
    fields*: cstringArray
    num_attrs*: cint
    attr_names*: cstringArray
    attr_types*: ptr array [0..100_000, cint]
    num_matches*: cint
    values_pool*: pointer
    total*: cint
    total_found*: cint
    time_msec*: cint
    num_words*: cint
    words*: ptr array [0..100_000, TWordinfo]

  Texcerpt_options*{.pure, final.} = object 
    before_match*: cstring
    after_match*: cstring
    chunk_separator*: cstring
    html_strip_mode*: cstring
    passage_boundary*: cstring
    limit*: cint
    limit_passages*: cint
    limit_words*: cint
    around*: cint
    start_passage_id*: cint
    exact_phrase*: TSphinxBool
    single_passage*: TSphinxBool
    use_boundaries*: TSphinxBool
    weight_order*: TSphinxBool
    query_mode*: TSphinxBool
    force_all_words*: TSphinxBool
    load_files*: TSphinxBool
    allow_empty*: TSphinxBool
    emit_zones*: TSphinxBool

  Tkeyword_info*{.pure, final.} = object 
    tokenized*: cstring
    normalized*: cstring
    num_docs*: cint
    num_hits*: cint


proc create*(copy_args: TSphinxBool): PClient{.cdecl, importc: "sphinx_create", 
    dynlib: sphinxDll.}
proc cleanup*(client: PClient){.cdecl, importc: "sphinx_cleanup", 
                                    dynlib: sphinxDll.}
proc destroy*(client: PClient){.cdecl, importc: "sphinx_destroy", 
                                    dynlib: sphinxDll.}
proc error*(client: PClient): cstring{.cdecl, importc: "sphinx_error", 
    dynlib: sphinxDll.}
proc warning*(client: PClient): cstring{.cdecl, importc: "sphinx_warning", 
    dynlib: sphinxDll.}
proc set_server*(client: PClient, host: cstring, port: cint): TSphinxBool{.cdecl, 
    importc: "sphinx_set_server", dynlib: sphinxDll.}
proc set_connect_timeout*(client: PClient, seconds: float32): TSphinxBool{.cdecl, 
    importc: "sphinx_set_connect_timeout", dynlib: sphinxDll.}
proc open*(client: PClient): TSphinxBool{.cdecl, importc: "sphinx_open", 
                                        dynlib: sphinxDll.}
proc close*(client: PClient): TSphinxBool{.cdecl, importc: "sphinx_close", 
    dynlib: sphinxDll.}
proc set_limits*(client: PClient, offset: cint, limit: cint, 
                 max_matches: cint, cutoff: cint): TSphinxBool{.cdecl, 
    importc: "sphinx_set_limits", dynlib: sphinxDll.}
proc set_max_query_time*(client: PClient, max_query_time: cint): TSphinxBool{.
    cdecl, importc: "sphinx_set_max_query_time", dynlib: sphinxDll.}
proc set_match_mode*(client: PClient, mode: cint): TSphinxBool{.cdecl, 
    importc: "sphinx_set_match_mode", dynlib: sphinxDll.}
proc set_ranking_mode*(client: PClient, ranker: cint): TSphinxBool{.cdecl, 
    importc: "sphinx_set_ranking_mode", dynlib: sphinxDll.}
proc set_sort_mode*(client: PClient, mode: cint, sortby: cstring): TSphinxBool{.
    cdecl, importc: "sphinx_set_sort_mode", dynlib: sphinxDll.}
proc set_field_weights*(client: PClient, num_weights: cint, 
                        field_names: cstringArray, field_weights: ptr cint): TSphinxBool{.
    cdecl, importc: "sphinx_set_field_weights", dynlib: sphinxDll.}
proc set_index_weights*(client: PClient, num_weights: cint, 
                        index_names: cstringArray, index_weights: ptr cint): TSphinxBool{.
    cdecl, importc: "sphinx_set_index_weights", dynlib: sphinxDll.}
proc set_id_range*(client: PClient, minid: int64, maxid: int64): TSphinxBool{.
    cdecl, importc: "sphinx_set_id_range", dynlib: sphinxDll.}
proc add_filter*(client: PClient, attr: cstring, num_values: cint, 
                 values: ptr int64, exclude: TSphinxBool): TSphinxBool{.cdecl, 
    importc: "sphinx_add_filter", dynlib: sphinxDll.}
proc add_filter_range*(client: PClient, attr: cstring, umin: int64, 
                       umax: int64, exclude: TSphinxBool): TSphinxBool{.cdecl, 
    importc: "sphinx_add_filter_range", dynlib: sphinxDll.}
proc add_filter_float_range*(client: PClient, attr: cstring, fmin: float32, 
                             fmax: float32, exclude: TSphinxBool): TSphinxBool{.cdecl, 
    importc: "sphinx_add_filter_float_range", dynlib: sphinxDll.}
proc set_geoanchor*(client: PClient, attr_latitude: cstring, 
                    attr_longitude: cstring, latitude: float32, longitude: float32): TSphinxBool{.
    cdecl, importc: "sphinx_set_geoanchor", dynlib: sphinxDll.}
proc set_groupby*(client: PClient, attr: cstring, groupby_func: cint, 
                  group_sort: cstring): TSphinxBool{.cdecl, 
    importc: "sphinx_set_groupby", dynlib: sphinxDll.}
proc set_groupby_distinct*(client: PClient, attr: cstring): TSphinxBool{.cdecl, 
    importc: "sphinx_set_groupby_distinct", dynlib: sphinxDll.}
proc set_retries*(client: PClient, count: cint, delay: cint): TSphinxBool{.cdecl, 
    importc: "sphinx_set_retries", dynlib: sphinxDll.}
proc add_override*(client: PClient, attr: cstring, docids: ptr int64, 
                   num_values: cint, values: ptr cint): TSphinxBool{.cdecl, 
    importc: "sphinx_add_override", dynlib: sphinxDll.}
proc set_select*(client: PClient, select_list: cstring): TSphinxBool{.cdecl, 
    importc: "sphinx_set_select", dynlib: sphinxDll.}
proc reset_filters*(client: PClient){.cdecl, 
    importc: "sphinx_reset_filters", dynlib: sphinxDll.}
proc reset_groupby*(client: PClient){.cdecl, 
    importc: "sphinx_reset_groupby", dynlib: sphinxDll.}
proc query*(client: PClient, query: cstring, index_list: cstring, 
            comment: cstring): ptr Tresult{.cdecl, importc: "sphinx_query", 
    dynlib: sphinxDll.}
proc add_query*(client: PClient, query: cstring, index_list: cstring, 
                comment: cstring): cint{.cdecl, importc: "sphinx_add_query", 
    dynlib: sphinxDll.}
proc run_queries*(client: PClient): ptr Tresult{.cdecl, 
    importc: "sphinx_run_queries", dynlib: sphinxDll.}
proc get_num_results*(client: PClient): cint{.cdecl, 
    importc: "sphinx_get_num_results", dynlib: sphinxDll.}
proc get_id*(result: ptr Tresult, match: cint): int64{.cdecl, 
    importc: "sphinx_get_id", dynlib: sphinxDll.}
proc get_weight*(result: ptr Tresult, match: cint): cint{.cdecl, 
    importc: "sphinx_get_weight", dynlib: sphinxDll.}
proc get_int*(result: ptr Tresult, match: cint, attr: cint): int64{.cdecl, 
    importc: "sphinx_get_int", dynlib: sphinxDll.}
proc get_float*(result: ptr Tresult, match: cint, attr: cint): float32{.cdecl, 
    importc: "sphinx_get_float", dynlib: sphinxDll.}
proc get_mva*(result: ptr Tresult, match: cint, attr: cint): ptr cint{.
    cdecl, importc: "sphinx_get_mva", dynlib: sphinxDll.}
proc get_string*(result: ptr Tresult, match: cint, attr: cint): cstring{.cdecl, 
    importc: "sphinx_get_string", dynlib: sphinxDll.}
proc init_excerpt_options*(opts: ptr Texcerpt_options){.cdecl, 
    importc: "sphinx_init_excerpt_options", dynlib: sphinxDll.}
proc build_excerpts*(client: PClient, num_docs: cint, docs: cstringArray, 
                     index: cstring, words: cstring, opts: ptr Texcerpt_options): cstringArray{.
    cdecl, importc: "sphinx_build_excerpts", dynlib: sphinxDll.}
proc update_attributes*(client: PClient, index: cstring, num_attrs: cint, 
                        attrs: cstringArray, num_docs: cint, 
                        docids: ptr int64, values: ptr int64): cint{.
    cdecl, importc: "sphinx_update_attributes", dynlib: sphinxDll.}
proc update_attributes_mva*(client: PClient, index: cstring, attr: cstring, 
                            docid: int64, num_values: cint, 
                            values: ptr cint): cint{.cdecl, 
    importc: "sphinx_update_attributes_mva", dynlib: sphinxDll.}
proc build_keywords*(client: PClient, query: cstring, index: cstring, 
                     hits: TSphinxBool, out_num_keywords: ptr cint): ptr Tkeyword_info{.
    cdecl, importc: "sphinx_build_keywords", dynlib: sphinxDll.}
proc status*(client: PClient, num_rows: ptr cint, num_cols: ptr cint): cstringArray{.
    cdecl, importc: "sphinx_status", dynlib: sphinxDll.}
proc status_destroy*(status: cstringArray, num_rows: cint, num_cols: cint){.
    cdecl, importc: "sphinx_status_destroy", dynlib: sphinxDll.}