libwebsockets
Lightweight C library for HTML5 websockets
lws-fts.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
33 
34 struct lws_fts;
35 struct lws_fts_file;
36 
37 /*
38  * Queries produce their results in an lwsac, using these public API types.
39  * The first thing in the lwsac is always a struct lws_fts_result (see below)
40  * containing heads for linked-lists of the other result types.
41  */
42 
43 /* one filepath's results */
44 
46  struct lws_fts_result_filepath *next;
47  int matches; /* logical number of matches */
48  int matches_length; /* bytes in length table (may be zero) */
49  int lines_in_file;
50  int filepath_length;
51 
52  /* - uint32_t line table follows (first for alignment) */
53  /* - filepath (of filepath_length) follows */
54 };
55 
56 /* autocomplete result */
57 
59  struct lws_fts_result_autocomplete *next;
60  int instances;
61  int agg_instances;
62  int ac_length;
63  char elided; /* children skipped in interest of antecedent children */
64  char has_children;
65 
66  /* - autocomplete suggestion (of length ac_length) follows */
67 };
68 
69 /*
70  * The results lwsac always starts with this. If no results and / or no
71  * autocomplete the members may be NULL. This implies the symbol nor any
72  * suffix on it exists in the trie file.
73  */
75  struct lws_fts_result_filepath *filepath_head;
76  struct lws_fts_result_autocomplete *autocomplete_head;
77  int duration_ms;
78  int effective_flags; /* the search flags that were used */
79 };
80 
81 /*
82  * index creation functions
83  */
84 
92 LWS_VISIBLE LWS_EXTERN struct lws_fts *
94 
103 LWS_VISIBLE LWS_EXTERN void
104 lws_fts_destroy(struct lws_fts **trie);
105 
116 LWS_VISIBLE LWS_EXTERN int
117 lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len,
118  int priority);
119 
130 LWS_VISIBLE LWS_EXTERN int
131 lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf,
132  size_t len);
133 
143 LWS_VISIBLE LWS_EXTERN int
144 lws_fts_serialize(struct lws_fts *t);
145 
146 /*
147  * index search functions
148  */
149 
158 LWS_VISIBLE LWS_EXTERN struct lws_fts_file *
159 lws_fts_open(const char *filepath);
160 
161 #define LWSFTS_F_QUERY_AUTOCOMPLETE (1 << 0)
162 #define LWSFTS_F_QUERY_FILES (1 << 1)
163 #define LWSFTS_F_QUERY_FILE_LINES (1 << 2)
164 #define LWSFTS_F_QUERY_QUOTE_LINE (1 << 3)
165 
167  /* the actual search term */
168  const char *needle;
169  /* if non-NULL, FILE results for this filepath only */
170  const char *only_filepath;
171  /* will be set to the results lwsac */
172  struct lwsac *results_head;
173  /* combination of LWSFTS_F_QUERY_* flags */
174  int flags;
175  /* maximum number of autocomplete suggestions to return */
176  int max_autocomplete;
177  /* maximum number of filepaths to return */
178  int max_files;
179  /* maximum number of line number results to return per filepath */
180  int max_lines;
181 };
182 
202 LWS_VISIBLE LWS_EXTERN struct lws_fts_result *
203 lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp);
204 
212 LWS_VISIBLE LWS_EXTERN void
213 lws_fts_close(struct lws_fts_file *jtf);
214 
LWS_VISIBLE LWS_EXTERN int lws_fts_serialize(struct lws_fts *t)
LWS_VISIBLE LWS_EXTERN void lws_fts_destroy(struct lws_fts **trie)
LWS_VISIBLE LWS_EXTERN struct lws_fts_file * lws_fts_open(const char *filepath)
LWS_VISIBLE LWS_EXTERN int lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len, int priority)
LWS_VISIBLE LWS_EXTERN struct lws_fts_result * lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp)
LWS_VISIBLE LWS_EXTERN struct lws_fts * lws_fts_create(int fd)
LWS_VISIBLE LWS_EXTERN int lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf, size_t len)
LWS_VISIBLE LWS_EXTERN void lws_fts_close(struct lws_fts_file *jtf)
Definition: lws-fts.h:58
Definition: lws-fts.h:45
Definition: lws-fts.h:74
Definition: lws-fts.h:166