JASSv2
JASS_anytime_api.h
Go to the documentation of this file.
1 /*
2  JASS_ANYTIME_API.H
3  ------------------
4  Copyright (c) 2021 Andrew Trotman
5  Released under the 2-clause BSD license (See:https://en.wikipedia.org/wiki/BSD_licenses)
6 */
13 #pragma once
14 
15 #include "query.h"
16 #include "top_k_limit.h"
17 #include "parser_query.h"
18 #include "JASS_anytime_query.h"
19 #include "JASS_anytime_stats.h"
20 #include "deserialised_jass_v2.h"
21 #include "JASS_anytime_result.h"
23 
24 /*
25  ENUM JASS_ERROR
26  ---------------
27 */
32  {
40 };
41 
42 /*
43  CLASS JASS_ANYTIME_API
44  ----------------------
45 */
51  {
52  private:
53  static constexpr size_t MAX_QUANTUM = 0x0FFF;
54  static constexpr size_t MAX_TERMS_PER_QUERY = 1024;
55 
56  private:
57  /*
58  @class thread_data
59  @brief thread local data - one of these is needed per thread
60  */
62  {
63  public:
64  std::unique_ptr<JASS::deserialised_jass_v1::segment_header[]> segment_order;
65  JASS::query *jass_query;
66  };
67 
68  private:
72  size_t top_k;
76  std::map<size_t, thread_data> thread_local_data;
77  std::string accumulator_manager;
78 
79  private:
80  /*
81  JASS_ANYTIME_API::JASS_ANYTIME_API()
82  ------------------------------------
83  Boilerplate the class to prevent assignment and copying.
84  */
85  JASS_anytime_api(JASS_anytime_api &from) = delete;
86  JASS_anytime_api(JASS_anytime_api &&from) = delete;
87 
88  /*
89  JASS_ANYTIME_API::OPERATOR=()
90  -----------------------------
91  Boilerplate the class to prevent assignment and copying.
92  */
93  JASS_anytime_api &operator=(JASS_anytime_api &from) = delete;
94  JASS_anytime_api &operator=(JASS_anytime_api &&from) = delete;
95 
96  /*
97  JASS_ANYTIME_API::ANYTIME()
98  ---------------------------
99  */
105  void anytime(JASS_anytime_thread_result &output, std::vector<JASS_anytime_query> &query_list, size_t thread_number = 0);
106 
107  /*
108  JASS_ANYTIME_API::ANYTIME_BOOTSTRAP()
109  -------------------------------------
110  */
118  static void anytime_bootstrap(JASS_anytime_api *thiss, JASS_anytime_thread_result &output, std::vector<JASS_anytime_query> &query_list, size_t thread_number);
119 
120  /*
121  JASS_ANYTIME_API::GET_THREAD_LOCAL_DATA()
122  -----------------------------------------
123  */
129  thread_data &get_thread_local_data(size_t thread_number);
130 
131  public:
132  /*
133  JASS_ANYTIME_API::JASS_ANYTIME_API()
134  ------------------------------------
135  */
140 
141  /*
142  JASS_ANYTIME_API::~JASS_ANYTIME_API()
143  -------------------------------------
144  */
148  virtual ~JASS_anytime_api();
149 
150  /*
151  JASS_ANYTIME_API::LOAD_INDEX()
152  ------------------------------
153  */
161  JASS_ERROR load_index(size_t index_version, const std::string &directory = "", bool verbose = false); // verbose prints progress as it loads the index
162 
163  /*
164  JASS_ANYTIME_API::GET_DOCUMENT_COUNT()
165  --------------------------------------
166  */
171  uint32_t get_document_count(void);
172 
173  /*
174  JASS_ANYTIME_API::GET_ENCODING_SCHEME()
175  ---------------------------------------
176  */
184  JASS_ERROR get_encoding_scheme(std::string &codex_name, int32_t &d_ness);
185 
186  /*
187  JASS_ANYTIME_API::GET_ENCODING_SCHEME_NAME()
188  --------------------------------------------
189  */
194  std::string get_encoding_scheme_name(void);
195 
196  /*
197  JASS_ANYTIME_API::GET_ENCODING_SCHEME_D()
198  -----------------------------------------
199  */
204  int32_t get_encoding_scheme_d(void);
205 
206  /*
207  JASS_ANYTIME_API::SET_ACCUMULATOR_MANAGER()
208  -------------------------------------------
209  */
214  void set_accumulator_manager(const std::string &name)
215  {
216  accumulator_manager = name;
217  }
218 
219  /*
220  JASS_ANYTIME_API::SET_POSTINGS_TO_PROCESS_PROPORTION()
221  ------------------------------------------------------
222  */
230 
231 
232  /*
233  JASS_ANYTIME_API::SET_POSTINGS_TO_PROCESS_RELATIVE()
234  ----------------------------------------------------
235  */
243 
244 
245  /*
246  JASS_ANYTIME_API::SET_POSTINGS_TO_PROCESS()
247  -------------------------------------------
248  */
255  JASS_ERROR set_postings_to_process(size_t count);
256 
257  /*
258  JASS_ANYTIME_API::GET_POSTINGS_TO_PROCESS()
259  -------------------------------------------
260  */
265  uint32_t get_postings_to_process(void);
266 
267  /*
268  JASS_ANYTIME_API::GET_MAX_TOP_K()
269  ---------------------------------
270  */
275  uint32_t get_max_top_k(void);
276 
277  /*
278  JASS_ANYTIME_API::SET_TOP_K()
279  -----------------------------
280  */
286  JASS_ERROR set_top_k(size_t k);
287 
288  /*
289  JASS_ANYTIME_API::GET_TOP_K()
290  -----------------------------
291  */
296  size_t get_top_k(void);
297 
298  /*
299  JASS_ANYTIME_API::SET_ACCUMULATOR_WIDTH()
300  -----------------------------------------
301  */
307  JASS_ERROR set_accumulator_width(size_t width);
308 
309  /*
310  JASS_ANYTIME_API::USE_ASCII_PARSER()
311  ------------------------------------
312  */
318 
319  /*
320  JASS_ANYTIME_API::USE_QUERY_PARSER()
321  ------------------------------------
322  */
328 
329  /*
330  JASS_ANYTIME_API::SEARCH()
331  --------------------------
332  */
338  JASS_anytime_result search(const std::string &query);
339 
340  /*
341  JASS_ANYTIME_API::SEARCH()
342  --------------------------
343  */
352  JASS_ERROR search(std::vector<JASS_anytime_thread_result> &output, std::vector<JASS_anytime_query> &query_list, size_t thread_count);
353 
354  /*
355  JASS_ANYTIME_API::THREADED_SEARCH()
356  -----------------------------------
357  */
364  std::vector<JASS_anytime_thread_result> threaded_search(std::vector<std::string> &query_list, size_t thread_count);
365  } ;
366 
367 /*
368  CLASS ANYTIME
369  -------------
370 */
375 class anytime : public JASS_anytime_api
376  {
377  /*
378  Nothing
379  */
380  };
Runtime statistics for the anytime search engine.
Definition: JASS_anytime_stats.h:22
JASS_ERROR set_postings_to_process_proportion(double percent)
Set the number of postings to process as a proportion of the number of documents in the collection...
Definition: JASS_anytime_api.cpp:142
JASS_ERROR set_postings_to_process(size_t count)
Set the number of postings to process as an absolute number.
Definition: JASS_anytime_api.cpp:167
JASS::parser_query::parser_type which_query_parser
Use the simple ASCII parser or the regular query parser.
Definition: JASS_anytime_api.h:73
thread_data & get_thread_local_data(size_t thread_number)
Return the expensive-to-initialise thread local data that has already been allocated on index load...
Definition: JASS_anytime_api.cpp:59
JASS_ERROR set_postings_to_process_relative(double percent)
Set the number of postings to process as a proportion of the number of postings for this query...
Definition: JASS_anytime_api.cpp:156
Definition: JASS_anytime_api.h:61
parser_type
Which parser to use.
Definition: parser_query.h:49
Management of top-k rsv limiting.
JASS_ERROR use_ascii_parser(void)
Use the query parser that seperates tokens on whitespace along (this method is not normally needed)...
Definition: JASS_anytime_api.cpp:278
Completed successfully without error.
Definition: JASS_anytime_api.h:34
size_t top_k
The number of documents we want in the results list.
Definition: JASS_anytime_api.h:72
double relative_postings_to_process
If not 1 then then this is the proportion of this query&#39;s postings that should be processed...
Definition: JASS_anytime_api.h:71
JASS_ERROR
Definition: JASS_anytime_api.h:31
Load and deserialise a JASS v2 index.
Everything necessary to process a query. Subclassed in order to get add_rsv()
JASS_ERROR load_index(size_t index_version, const std::string &directory="", bool verbose=false)
Load a JASS index from the given directory.
Definition: JASS_anytime_api.cpp:91
size_t postings_to_process
The maximunm number of postings to process.
Definition: JASS_anytime_api.h:70
size_t accumulator_width
Width of the accumulator array.
Definition: JASS_anytime_api.h:74
Load and deserialise a JASS v1 index.
JASS_anytime_stats stats
Stats for this "session".
Definition: JASS_anytime_api.h:75
Definition: JASS_anytime_result.h:23
The API to JASS&#39;s anytime seach engine.
Definition: JASS_anytime_api.h:50
std::string get_encoding_scheme_name(void)
Return the name of the compression algorithm used on this index.
Definition: JASS_anytime_api.cpp:248
int32_t get_encoding_scheme_d(void)
Return the d-gap value used in this index.
Definition: JASS_anytime_api.cpp:263
The results of a single thread in the Anytime engine.
virtual ~JASS_anytime_api()
Destructor.
Definition: JASS_anytime_api.cpp:50
A query object - used to facilitate parallel query resolution.
Results from a single thread of execution in parallel search.
Definition: JASS_anytime_thread_result.h:26
uint32_t get_postings_to_process(void)
Return the current maimum number of postings to process value. This might be very large...
Definition: JASS_anytime_api.cpp:178
std::string accumulator_manager
The name of the accumulator manager.
Definition: JASS_anytime_api.h:77
void set_accumulator_manager(const std::string &name)
Set the name of the accumulator manager to use.
Definition: JASS_anytime_api.h:214
static constexpr size_t MAX_QUANTUM
The maximum number of segments in a query.
Definition: JASS_anytime_api.h:53
top-k is larger than the system-wide maximum top-k value (or the accumulator width is too large) ...
Definition: JASS_anytime_api.h:38
An alias for JASS_anytime_api.
Definition: JASS_anytime_api.h:375
The index must be loaded before this operation can occur.
Definition: JASS_anytime_api.h:33
Attempt to load an index when an index has alrady been loaded.
Definition: JASS_anytime_api.h:39
The index version number specified is not supported.
Definition: JASS_anytime_api.h:35
static constexpr size_t MAX_TERMS_PER_QUERY
The maximum number of terms in a query.
Definition: JASS_anytime_api.h:54
JASS::deserialised_jass_v1 * index
The index.
Definition: JASS_anytime_api.h:69
JASS_ERROR use_query_parser(void)
Use the default query parser that understands alphanumnerics, spaces, unicode, and so on (this method...
Definition: JASS_anytime_api.cpp:288
The results of a single query.
uint32_t get_max_top_k(void)
Return the largest possible top_k value, which might be smaller than the number of documents in the c...
Definition: JASS_anytime_api.cpp:225
size_t get_top_k(void)
Return the current top-k value.
Definition: JASS_anytime_api.cpp:216
Simple parser for queries.
This index cannot be loaded by this instance of the APIs because it contains more documents than the ...
Definition: JASS_anytime_api.h:37
JASS_anytime_result search(const std::string &query)
Search using the current index and the current parameters.
Definition: JASS_anytime_api.cpp:314
std::map< size_t, thread_data > thread_local_data
Data needed by each thread (the accumulators array, etc)
Definition: JASS_anytime_api.h:76
JASS_ERROR get_encoding_scheme(std::string &codex_name, int32_t &d_ness)
Return the name of the compression algorithm and the delta (d-gap) size.
Definition: JASS_anytime_api.cpp:234
Load and deserialise a JASS v1 index.
Definition: deserialised_jass_v1.h:36
Everything necessary to process a query is encapsulated in an object of this type.
Definition: query.h:34
static void anytime_bootstrap(JASS_anytime_api *thiss, JASS_anytime_thread_result &output, std::vector< JASS_anytime_query > &query_list, size_t thread_number)
Bootstrapping method for a thread to call into anytime()
Definition: JASS_anytime_api.cpp:25
JASS_ERROR set_accumulator_width(size_t width)
Set the accumulator page-table width (assuming a page-table like approach is being used) ...
Definition: JASS_anytime_api.cpp:298
void anytime(JASS_anytime_thread_result &output, std::vector< JASS_anytime_query > &query_list, size_t thread_number=0)
This method calls into the search engine with a set of queries and retrieves a set of results for eac...
Definition: JASS_anytime_api.cpp:391
JASS_ERROR set_top_k(size_t k)
Set the maximum numbre of documents to return in a resuts list.
Definition: JASS_anytime_api.cpp:187
std::vector< JASS_anytime_thread_result > threaded_search(std::vector< std::string > &query_list, size_t thread_count)
Search using the current index and the current parameters.
Definition: JASS_anytime_api.cpp:332
An exception occurred - probably not caused by JASS (might be a C++ RTL exception) ...
Definition: JASS_anytime_api.h:36
JASS_anytime_api()
Constructor.
Definition: JASS_anytime_api.cpp:34
uint32_t get_document_count(void)
Return the number of documents in the index.
Definition: JASS_anytime_api.cpp:204