.TH "hyle/query.h" 3 "libhyle" \" -*- nroff -*- .ad l .nh .SH NAME hyle/query.h \- URL query parsing and the filter/sort/paginate pipeline\&. .SH SYNOPSIS .br .PP \fR#include \fP .br \fR#include \fP .br \fR#include \fP .br \fR#include 'ctx\&.h'\fP .br \fR#include 'field\&.h'\fP .br .SS "Data Structures" .in +1c .ti -1c .RI "struct \fBhyle_field_filter_t\fP" .br .RI "Per-field filter as parsed from the URL query string\&. " .ti -1c .RI "struct \fBhyle_query_t\fP" .br .RI "Parsed view state: sort, page and filter options\&. " .ti -1c .RI "struct \fBhyle_row_set_t\fP" .br .RI "Handle pair identifying a set of rows and its field values\&. " .in -1c .SS "Functions" .in +1c .ti -1c .RI "int \fBhyle_parse_query\fP (char *query_str, \fBhyle_query_t\fP *out)" .br .RI "Parse a URL-encoded query string into a \fBhyle_query_t\fP\&. " .ti -1c .RI "void \fBhyle_query_clear\fP (\fBhyle_query_t\fP *q)" .br .RI "Free the filter and include arrays owned by a parsed query\&. " .ti -1c .RI "int \fBhyle_ci_substr\fP (const char *str, const char *sub)" .br .RI "Case-insensitive, accent-sensitive substring match\&. " .ti -1c .RI "int \fBhyle_ci_substr_punct\fP (const char *str, const char *sub)" .br .RI "Case-insensitive substring match with punctuation normalization\&. " .ti -1c .RI "int \fBhyle_ci_match_score\fP (const char *str, const char *sub, int punct_norm)" .br .RI "Case-insensitive match precision scoring (0 = no match, 1 = substring, 2 = word boundary, 3 = prefix, 4 = exact)\&. " .ti -1c .RI "void \fBhyle_filter_rows\fP (\fBhyle_ctx_t\fP *ctx, const \fBhyle_row_set_t\fP *input, const char *q, const \fBhyle_field_filter_t\fP *filters, unsigned filter_count, const \fBhyle_field_t\fP *fields, size_t field_count, \fBhyle_row_set_t\fP *output)" .br .RI "Emit the rows in input that match q and all filters\&. " .ti -1c .RI "void \fBhyle_sort_rows\fP (\fBhyle_ctx_t\fP *ctx, const \fBhyle_row_set_t\fP *input, const char *sort_field, bool sort_asc, \fBhyle_row_set_t\fP *output)" .br .RI "Sort a row set by a field value (numeric when all numeric)\&. " .ti -1c .RI "void \fBhyle_paginate\fP (\fBhyle_ctx_t\fP *ctx, const \fBhyle_row_set_t\fP *input, uint32_t page, uint32_t per_page, \fBhyle_row_set_t\fP *output, uint32_t *total_out)" .br .RI "Emit only the requested page of a row set\&. " .ti -1c .RI "void \fBhyle_apply_view\fP (\fBhyle_ctx_t\fP *ctx, const \fBhyle_row_set_t\fP *input, const \fBhyle_query_t\fP *query, const \fBhyle_field_t\fP *fields, size_t field_count, \fBhyle_row_set_t\fP *output, uint32_t *total_out)" .br .RI "Apply the filter, sort and paginate pipeline in one call\&. " .in -1c .SH "Detailed Description" .PP URL query parsing and the filter/sort/paginate pipeline\&. \fBhyle_query_t\fP carries parsed sort/page/filter state; the helpers below apply it to a row set (accent-sensitive matching, corm-backed filter)\&. .SH "Function Documentation" .PP .SS "void hyle_apply_view (\fBhyle_ctx_t\fP * ctx, const \fBhyle_row_set_t\fP * input, const \fBhyle_query_t\fP * query, const \fBhyle_field_t\fP * fields, size_t field_count, \fBhyle_row_set_t\fP * output, uint32_t * total_out)" .PP Apply the filter, sort and paginate pipeline in one call\&. .PP \fBParameters\fP .RS 4 \fIctx\fP Context used for intermediate results\&. .br \fIinput\fP Source row set\&. .br \fIquery\fP Parsed view state to apply\&. .br \fIfields\fP Field schema, forwarded to \fBhyle_filter_rows()\fP\&. .br \fIfield_count\fP Number of entries in fields\&. .br \fIoutput\fP Receives the resulting row set\&. .br \fItotal_out\fP Receives the total matching row count, or NULL\&. .RE .PP .SS "int hyle_ci_match_score (const char * str, const char * sub, int punct_norm)" .PP Case-insensitive match precision scoring (0 = no match, 1 = substring, 2 = word boundary, 3 = prefix, 4 = exact)\&. .PP \fBParameters\fP .RS 4 \fIstr\fP String to search\&. .br \fIsub\fP Substring / query term\&. .br \fIpunct_norm\fP Non-zero for Google-like punctuation normalization\&. .RE .PP \fBReturns\fP .RS 4 Score 0 to 4\&. .RE .PP .SS "int hyle_ci_substr (const char * str, const char * sub)" .PP Case-insensitive, accent-sensitive substring match\&. .PP \fBParameters\fP .RS 4 \fIstr\fP String to search\&. .br \fIsub\fP Substring to look for\&. .RE .PP \fBReturns\fP .RS 4 1 when sub occurs in str (case-folded), 0 otherwise\&. .RE .PP .SS "int hyle_ci_substr_punct (const char * str, const char * sub)" .PP 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"\&. .PP \fBParameters\fP .RS 4 \fIstr\fP String to search\&. .br \fIsub\fP Substring to look for\&. .RE .PP \fBReturns\fP .RS 4 1 when sub matches str after normalization, 0 otherwise\&. .RE .PP .SS "void hyle_filter_rows (\fBhyle_ctx_t\fP * ctx, const \fBhyle_row_set_t\fP * input, const char * q, const \fBhyle_field_filter_t\fP * filters, unsigned filter_count, const \fBhyle_field_t\fP * fields, size_t field_count, \fBhyle_row_set_t\fP * output)" .PP 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\&. .PP \fBParameters\fP .RS 4 \fIctx\fP Context (unused, may be NULL)\&. .br \fIinput\fP Source row set\&. .br \fIq\fP Free-text term, or NULL for no search\&. .br \fIfilters\fP Per-field filters, or NULL\&. .br \fIfilter_count\fP Number of entries in filters\&. .br \fIfields\fP Field schema for multi-reference token matching\&. .br \fIfield_count\fP Number of entries in fields\&. .br \fIoutput\fP Receives the matching row set\&. .RE .PP .SS "void hyle_paginate (\fBhyle_ctx_t\fP * ctx, const \fBhyle_row_set_t\fP * input, uint32_t page, uint32_t per_page, \fBhyle_row_set_t\fP * output, uint32_t * total_out)" .PP Emit only the requested page of a row set\&. .PP \fBParameters\fP .RS 4 \fIctx\fP Context (unused, may be NULL)\&. .br \fIinput\fP Source row set\&. .br \fIpage\fP One-based page number\&. .br \fIper_page\fP Rows per page\&. .br \fIoutput\fP Receives the page's rows\&. .br \fItotal_out\fP Receives the total row count, or NULL\&. .RE .PP .SS "int hyle_parse_query (char * query_str, \fBhyle_query_t\fP * out)" .PP Parse a URL-encoded query string into a \fBhyle_query_t\fP\&. Recognizes sort, page, per_page, q and include, treats "_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\&. .PP \fBParameters\fP .RS 4 \fIquery_str\fP URL-encoded query string (modified in place)\&. .br \fIout\fP Query to fill; clear with \fBhyle_query_clear()\fP\&. .RE .PP \fBReturns\fP .RS 4 0 on success, or -1 when an allocation fails\&. .RE .PP .SS "void hyle_query_clear (\fBhyle_query_t\fP * q)" .PP Free the filter and include arrays owned by a parsed query\&. .PP \fBParameters\fP .RS 4 \fIq\fP Query to release, or NULL\&. .RE .PP .SS "void hyle_sort_rows (\fBhyle_ctx_t\fP * ctx, const \fBhyle_row_set_t\fP * input, const char * sort_field, bool sort_asc, \fBhyle_row_set_t\fP * output)" .PP Sort a row set by a field value (numeric when all numeric)\&. .PP \fBParameters\fP .RS 4 \fIctx\fP Context (unused, may be NULL)\&. .br \fIinput\fP Source row set\&. .br \fIsort_field\fP Field to sort by, or NULL for passthrough\&. .br \fIsort_asc\fP Non-zero for ascending order\&. .br \fIoutput\fP Receives the sorted row set\&. .RE .PP .SH "Author" .PP Generated automatically by Doxygen for libhyle from the source code\&.