libwebsockets
Lightweight C library for HTML5 websockets
lws-fts.h
1 /*
2  * libwebsockets - fulltext search
3  *
4  * Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
32 
33 struct lws_fts;
34 struct lws_fts_file;
35 
36 /*
37  * Queries produce their results in an lwsac, using these public API types.
38  * The first thing in the lwsac is always a struct lws_fts_result (see below)
39  * containing heads for linked-lists of the other result types.
40  */
41 
42 /* one filepath's results */
43 
45  struct lws_fts_result_filepath *next;
46  int matches; /* logical number of matches */
47  int matches_length; /* bytes in length table (may be zero) */
48  int lines_in_file;
49  int filepath_length;
50 
51  /* - uint32_t line table follows (first for alignment) */
52  /* - filepath (of filepath_length) follows */
53 };
54 
55 /* autocomplete result */
56 
58  struct lws_fts_result_autocomplete *next;
59  int instances;
60  int agg_instances;
61  int ac_length;
62  char elided; /* children skipped in interest of antecedent children */
63  char has_children;
64 
65  /* - autocomplete suggestion (of length ac_length) follows */
66 };
67 
68 /*
69  * The results lwsac always starts with this. If no results and / or no
70  * autocomplete the members may be NULL. This implies the symbol nor any
71  * suffix on it exists in the trie file.
72  */
74  struct lws_fts_result_filepath *filepath_head;
75  struct lws_fts_result_autocomplete *autocomplete_head;
76  int duration_ms;
77  int effective_flags; /* the search flags that were used */
78 };
79 
80 /*
81  * index creation functions
82  */
83 
91 LWS_VISIBLE LWS_EXTERN struct lws_fts *
93 
102 LWS_VISIBLE LWS_EXTERN void
103 lws_fts_destroy(struct lws_fts **trie);
104 
115 LWS_VISIBLE LWS_EXTERN int
116 lws_fts_file_index(struct lws_fts *t, const char *filepath, int filepath_len,
117  int priority);
118 
129 LWS_VISIBLE LWS_EXTERN int
130 lws_fts_fill(struct lws_fts *t, uint32_t file_index, const char *buf,
131  size_t len);
132 
142 LWS_VISIBLE LWS_EXTERN int
143 lws_fts_serialize(struct lws_fts *t);
144 
145 /*
146  * index search functions
147  */
148 
157 LWS_VISIBLE LWS_EXTERN struct lws_fts_file *
158 lws_fts_open(const char *filepath);
159 
160 #define LWSFTS_F_QUERY_AUTOCOMPLETE (1 << 0)
161 #define LWSFTS_F_QUERY_FILES (1 << 1)
162 #define LWSFTS_F_QUERY_FILE_LINES (1 << 2)
163 #define LWSFTS_F_QUERY_QUOTE_LINE (1 << 3)
164 
166  /* the actual search term */
167  const char *needle;
168  /* if non-NULL, FILE results for this filepath only */
169  const char *only_filepath;
170  /* will be set to the results lwsac */
171  struct lwsac *results_head;
172  /* combination of LWSFTS_F_QUERY_* flags */
173  int flags;
174  /* maximum number of autocomplete suggestions to return */
175  int max_autocomplete;
176  /* maximum number of filepaths to return */
177  int max_files;
178  /* maximum number of line number results to return per filepath */
179  int max_lines;
180 };
181 
201 LWS_VISIBLE LWS_EXTERN struct lws_fts_result *
202 lws_fts_search(struct lws_fts_file *jtf, struct lws_fts_search_params *ftsp);
203 
211 LWS_VISIBLE LWS_EXTERN void
212 lws_fts_close(struct lws_fts_file *jtf);
213 
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:57
Definition: lws-fts.h:44
Definition: lws-fts.h:73
Definition: lws-fts.h:165