facets.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef FACETS_H
  2. #define FACETS_H 1
  3. #include "../libnetdata.h"
  4. #define FACET_VALUE_UNSET "-"
  5. typedef enum __attribute__((packed)) {
  6. FACET_KEY_OPTION_FACET = (1 << 0), // filterable values
  7. FACET_KEY_OPTION_NO_FACET = (1 << 1), // non-filterable value
  8. FACET_KEY_OPTION_STICKY = (1 << 2), // should be sticky in the table
  9. FACET_KEY_OPTION_VISIBLE = (1 << 3), // should be in the default table
  10. FACET_KEY_OPTION_FTS = (1 << 4), // the key is filterable by full text search (FTS)
  11. FACET_KEY_OPTION_MAIN_TEXT = (1 << 5), // full width and wrap
  12. FACET_KEY_OPTION_REORDER = (1 << 6), // give the key a new order id on first encounter
  13. } FACET_KEY_OPTIONS;
  14. typedef struct facet_row_key_value {
  15. const char *tmp;
  16. BUFFER *wb;
  17. } FACET_ROW_KEY_VALUE;
  18. typedef struct facet_row {
  19. usec_t usec;
  20. DICTIONARY *dict;
  21. struct facet_row *prev, *next;
  22. } FACET_ROW;
  23. typedef struct facets FACETS;
  24. typedef struct facet_key FACET_KEY;
  25. #define FACET_STRING_HASH_SIZE 19
  26. void facets_string_hash(const char *src, char *out);
  27. typedef void (*facets_key_transformer_t)(FACETS *facets __maybe_unused, BUFFER *wb, void *data);
  28. typedef void (*facet_dynamic_row_t)(FACETS *facets, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row, void *data);
  29. FACET_KEY *facets_register_dynamic_key(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data);
  30. FACET_KEY *facets_register_key_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data);
  31. typedef enum __attribute__((packed)) {
  32. FACETS_OPTION_ALL_FACETS_VISIBLE = (1 << 0), // all facets, should be visible by default in the table
  33. FACETS_OPTION_ALL_KEYS_FTS = (1 << 1), // all keys are searchable by full text search
  34. } FACETS_OPTIONS;
  35. FACETS *facets_create(uint32_t items_to_return, usec_t anchor, FACETS_OPTIONS options, const char *visible_keys, const char *facet_keys, const char *non_facet_keys);
  36. void facets_destroy(FACETS *facets);
  37. void facets_accepted_param(FACETS *facets, const char *param);
  38. void facets_rows_begin(FACETS *facets);
  39. void facets_row_finished(FACETS *facets, usec_t usec);
  40. FACET_KEY *facets_register_key(FACETS *facets, const char *param, FACET_KEY_OPTIONS options);
  41. void facets_set_query(FACETS *facets, const char *query);
  42. void facets_set_items(FACETS *facets, uint32_t items);
  43. void facets_set_anchor(FACETS *facets, usec_t anchor);
  44. void facets_register_facet_filter(FACETS *facets, const char *key_id, char *value_ids, FACET_KEY_OPTIONS options);
  45. void facets_add_key_value(FACETS *facets, const char *key, const char *value);
  46. void facets_add_key_value_length(FACETS *facets, const char *key, const char *value, size_t value_len);
  47. void facets_report(FACETS *facets, BUFFER *wb);
  48. #endif