libwebsockets
Lightweight C library for HTML5 websockets
lws-fts.h
Go to the documentation of this file.
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 
47  int matches; /* logical number of matches */
48  int matches_length; /* bytes in length table (may be zero) */
51 
52  /* - uint32_t line table follows (first for alignment) */
53  /* - filepath (of filepath_length) follows */
54 };
55 
56 /* autocomplete result */
57 
60  int instances;
62  int ac_length;
63  char elided; /* children skipped in interest of antecedent 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  */
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 
104 lws_fts_destroy(struct lws_fts **trie);
105 
117 lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len,
118  int priority);
119 
131 lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf,
132  size_t len);
133 
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 */
177  /* maximum number of filepaths to return */
179  /* maximum number of line number results to return per filepath */
181 };
182 
203 lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp);
204 
213 lws_fts_close(struct lws_fts_file *jtf);
214 
struct lws_fts_result_filepath * next
Definition: lws-fts.h:46
struct lwsac * results_head
Definition: lws-fts.h:172
const char * only_filepath
Definition: lws-fts.h:170
struct lws_fts_result_autocomplete * next
Definition: lws-fts.h:59
const char * needle
Definition: lws-fts.h:168
int effective_flags
Definition: lws-fts.h:78
struct lws_fts_result_filepath * filepath_head
Definition: lws-fts.h:75
struct lws_fts_result_autocomplete * autocomplete_head
Definition: lws-fts.h:76
int duration_ms
Definition: lws-fts.h:77
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)
unsigned int uint32_t
#define LWS_EXTERN
#define LWS_VISIBLE