hyle/query.h(3)libhyle

NAME

hyle/query.h - URL query parsing and the filter/sort/paginate pipeline.

SYNOPSIS

#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include 'ctx.h'
#include 'field.h'

Data Structures

struct hyle_field_filter_t

Per-field filter as parsed from the URL query string.

struct hyle_query_t

Parsed view state: sort, page and filter options.

struct hyle_row_set_t

Handle pair identifying a set of rows and its field values.

Functions

int hyle_parse_query (char *query_str, hyle_query_t *out)

Parse a URL-encoded query string into a hyle_query_t.

void hyle_query_clear (hyle_query_t *q)

Free the filter and include arrays owned by a parsed query.

int hyle_ci_substr (const char *str, const char *sub)

Case-insensitive, accent-sensitive substring match.

int hyle_ci_substr_punct (const char *str, const char *sub)

Case-insensitive substring match with punctuation normalization.

int hyle_ci_match_score (const char *str, const char *sub, int punct_norm)

Case-insensitive match precision scoring (0 = no match, 1 = substring, 2 = word boundary, 3 = prefix, 4 = exact).

void hyle_filter_rows (hyle_ctx_t *ctx, const hyle_row_set_t *input, const char *q, const hyle_field_filter_t *filters, unsigned filter_count, const hyle_field_t *fields, size_t field_count, hyle_row_set_t *output)

Emit the rows in input that match q and all filters.

void hyle_sort_rows (hyle_ctx_t *ctx, const hyle_row_set_t *input, const char *sort_field, bool sort_asc, hyle_row_set_t *output)

Sort a row set by a field value (numeric when all numeric).

void hyle_paginate (hyle_ctx_t *ctx, const hyle_row_set_t *input, uint32_t page, uint32_t per_page, hyle_row_set_t *output, uint32_t *total_out)

Emit only the requested page of a row set.

void hyle_apply_view (hyle_ctx_t *ctx, const hyle_row_set_t *input, const hyle_query_t *query, const hyle_field_t *fields, size_t field_count, hyle_row_set_t *output, uint32_t *total_out)

Apply the filter, sort and paginate pipeline in one call.

Detailed Description

URL query parsing and the filter/sort/paginate pipeline.

hyle_query_t carries parsed sort/page/filter state; the helpers below apply it to a row set (accent-sensitive matching, corm-backed filter).

Function Documentation

void hyle_apply_view (hyle_ctx_t * ctx, const hyle_row_set_t * input, const hyle_query_t * query, const hyle_field_t * fields, size_t field_count, hyle_row_set_t * output, uint32_t * total_out)

Apply the filter, sort and paginate pipeline in one call.

Parameters

ctx Context used for intermediate results.
input Source row set.
query Parsed view state to apply.
fields Field schema, forwarded to hyle_filter_rows().
field_count Number of entries in fields.
output Receives the resulting row set.
total_out Receives the total matching row count, or NULL.

int hyle_ci_match_score (const char * str, const char * sub, int punct_norm)

Case-insensitive match precision scoring (0 = no match, 1 = substring, 2 = word boundary, 3 = prefix, 4 = exact).

Parameters

str String to search.
sub Substring / query term.
punct_norm Non-zero for Google-like punctuation normalization.

Returns

Score 0 to 4.

int hyle_ci_substr (const char * str, const char * sub)

Case-insensitive, accent-sensitive substring match.

Parameters

str String to search.
sub Substring to look for.

Returns

1 when sub occurs in str (case-folded), 0 otherwise.

int hyle_ci_substr_punct (const char * str, const char * sub)

Case-insensitive substring match with punctuation normalization. Most punctuation is replaced with spaces, apostrophes are stripped, and whitespace is collapsed before a folded substring match, so "well-known" matches "well known" and "don't" matches "dont".

Parameters

str String to search.
sub Substring to look for.

Returns

1 when sub matches str after normalization, 0 otherwise.

void hyle_filter_rows (hyle_ctx_t * ctx, const hyle_row_set_t * input, const char * q, const hyle_field_filter_t * filters, unsigned filter_count, const hyle_field_t * fields, size_t field_count, hyle_row_set_t * output)

Emit the rows in input that match q and all filters. A NULL/empty q passes all rows; per-field filters are ANDed and match case-insensitively. When the field schema is supplied, multi-reference fields match on whole newline-delimited tokens instead of substrings.

Parameters

ctx Context (unused, may be NULL).
input Source row set.
q Free-text term, or NULL for no search.
filters Per-field filters, or NULL.
filter_count Number of entries in filters.
fields Field schema for multi-reference token matching.
field_count Number of entries in fields.
output Receives the matching row set.

void hyle_paginate (hyle_ctx_t * ctx, const hyle_row_set_t * input, uint32_t page, uint32_t per_page, hyle_row_set_t * output, uint32_t * total_out)

Emit only the requested page of a row set.

Parameters

ctx Context (unused, may be NULL).
input Source row set.
page One-based page number.
per_page Rows per page.
output Receives the page's rows.
total_out Receives the total row count, or NULL.

int hyle_parse_query (char * query_str, hyle_query_t * out)

Parse a URL-encoded query string into a hyle_query_t. Recognizes sort, page, per_page, q and include, treats "<field>_op" as a within-field combination override, and turns every other key=value pair into a filter. query_str is modified in place and the parsed pointers reference its tokens, so it must outlive the query.

Parameters

query_str URL-encoded query string (modified in place).
out Query to fill; clear with hyle_query_clear().

Returns

0 on success, or -1 when an allocation fails.

void hyle_query_clear (hyle_query_t * q)

Free the filter and include arrays owned by a parsed query.

Parameters

q Query to release, or NULL.

void hyle_sort_rows (hyle_ctx_t * ctx, const hyle_row_set_t * input, const char * sort_field, bool sort_asc, hyle_row_set_t * output)

Sort a row set by a field value (numeric when all numeric).

Parameters

ctx Context (unused, may be NULL).
input Source row set.
sort_field Field to sort by, or NULL for passthrough.
sort_asc Non-zero for ascending order.
output Receives the sorted row set.

Author

Generated automatically by Doxygen for libhyle from the source code.