From f466739b09be1baffd13110b431ecd8057a40771 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 24 Aug 2020 13:43:13 -0700 Subject: WIP: expanding query parsing --- src/lib.rs | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 165 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1ba6207..615e4ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,35 +1,193 @@ use serde::{Serialize, Deserialize}; +use std::collections::HashMap; #[derive(Serialize, Deserialize, Debug)] pub struct ApiRequest { pub method: String, pub path_and_query: String, - pub body: Option, + pub body: Option, } +/* + +URL query parameters: + + pub allow_no_indices: Option, + pub allow_partial_search_results: Option, + pub batched_reduce_size: Option, + pub ccs_minimize_roundtrips: Option, + pub docvalue_fields: Option, // array of strings, comma-separated + pub expand_wildcards: Option, + pub explain: Option, + pub from: Option, + pub ignore_throttled: Option, + pub ignore_unavailable: Option, + pub max_concurrent_shard_requests: Option, + pub pre_filter_shard_size: Option, + pub preference: Option, + pub q: Option + pub request_cache: Option, + pub rest_total_hits_as_int: Option, + pub routing: Option, + pub scroll: Option, // string is "time value" + pub search_type: Option, + pub seq_no_primary_term: Option, + pub size: Option, + pub sort: Option, // array of strings, comma-separated + pub _source: Option, // TODO: bool or string + pub _source_excludes: Option, // array of strings, comma-separated + pub _source_includes: Option, // array of strings, comma-separated + pub stats: Option, + pub stored_fields: Option, // array of strings, comma-separated + pub suggest_field: Option, + pub suggest_text: Option, + pub terminate_after: Option, + pub timeout: Option, // string is "time units" + pub track_scores: Option, + pub track_total_hits: Option, // XXX: bool or integer + pub typed_keys: Option, + pub version: Option, +*/ + +// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html #[derive(Serialize, Deserialize, Debug)] -pub struct ApiBody { +pub struct SearchBody { pub query: Option, + pub highlight: Option, + pub collapse: Option, + pub post_filter: Option, // TODO: leaf query only? + pub rescore: Option, // TODO: single or an array of rescore objects + // script_fields disabled + + // https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html + // pub sort: Option>, // XXX: array of object or string + + pub slice: Option, + pub stored_fields: Option, // array of strings, or "_none_" + + // overlap with URL query parameters + pub docvalue_fields: Option>, // XXX: array of strings or objects? {field, format} in the objects + pub explain: Option, pub from: Option, + pub min_score: Option, + pub seq_no_primary_term: Option, pub size: Option, - pub sort: Option, // XXX - pub slice: Option, // XXX + pub _source: Option, // XXX: bool, string, or object + pub terminate_after: Option, + pub timeout: Option, // string is "time units" + + // not enumerated in direct docs, but seems to be allowed? +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ApiSlice { + id: u32, + max: u32, + field: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ApiRescore{ + pub query: Option, + pub window_size: Option, } #[derive(Serialize, Deserialize, Debug)] pub enum ApiQuery { + // compound queries + #[serde(rename = "bool")] + Bool(HashMap), + #[serde(rename = "boosting")] + Boosting {positive: Box, negative: Box, negative_boost: f64}, + #[serde(rename = "constant_score")] + ConstantScore {filter: Box, boost: Option}, + + // fulltext (leaf) queries + + // term-level (leaf) queries #[serde(rename = "match")] - Match(MatchQuery), + Match(HashMap), + #[serde(rename = "match_phrase")] + MatchPhrase(HashMap), + #[serde(rename = "query_string")] + QueryString(QueryField), + + // other + #[serde(rename = "nested")] + Nested(NestedQuery), + #[serde(rename = "rescore_query")] + Rescore(Box), +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ApiHighlight{ + // TODO: fields could also be an array of strings? + fields: HashMap, + + #[serde(flatten)] + settings: HighlightField, } #[derive(Serialize, Deserialize, Debug)] -pub struct MatchQuery { - message: QueryField, +#[serde(untagged)] +pub enum QueryFieldOrString { + Object(QueryField), + String(String), } #[derive(Serialize, Deserialize, Debug)] pub struct QueryField{ query: String, fuzziness: Option, + slop: Option, + boost: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct NestedQuery{ + path: String, + query: Box, + score_mode: Option, + ignore_unmapped: Option, +} + +// https://www.elastic.co/guide/en/elasticsearch/reference/current/highlighting.html +#[derive(Serialize, Deserialize, Debug)] +pub struct HighlightField{ + boundary_chars: Option, + boundary_max_scan: Option, + boundary_scanner: Option, + boundary_scanner_locale: Option, + encoder: Option, + force_source: Option, + fragmenter: Option, + fragment_offset: Option, + fragment_size: Option, + highlight_query: Option, + matched_fields: Option>, + no_match_size: Option, + number_of_fragments: Option, + order: Option, + phrase_limit: Option, + pre_tags: Option>, + post_tags: Option>, + require_field_match: Option, + tags_schema: Option, + #[serde(rename = "type")] + highlight_type: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ApiCollapse{ + field: String, + inner_hits: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct InnerHits { + from: Option, + size: Option, + sort: Option>, + name: Option, } -- cgit v1.2.3