use hipstr::HipStr;
use rapidhash::RapidHashMap;
use serde::{Deserialize, Serialize};
use super::meta::{IndexField, IndexOnDataType, SearchIndexSchema};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FtCreate {
pub index_name: String,
pub on_data_type: IndexOnDataType,
pub prefixes: Vec<String>,
pub filter: Option<String>,
pub default_score: f64,
pub score_field: Option<String>,
pub payload_field: Option<String>,
pub language: Option<String>,
pub language_field: Option<String>,
pub max_text_fields: bool,
pub no_offsets: bool,
pub no_hl: bool,
pub no_fields: bool,
pub no_freqs: bool,
pub stop_words: Vec<String>,
pub fields: Vec<IndexField>,
}
impl Default for FtCreate {
fn default() -> Self {
Self {
index_name: String::new(),
on_data_type: IndexOnDataType::Hash,
prefixes: Vec::new(),
filter: None,
default_score: 1.0,
score_field: None,
payload_field: None,
language: None,
language_field: None,
max_text_fields: false,
no_offsets: false,
no_hl: false,
no_fields: false,
no_freqs: false,
stop_words: Vec::new(),
fields: Vec::new(),
}
}
}
impl From<FtCreate> for SearchIndexSchema {
fn from(c: FtCreate) -> Self {
Self {
name: HipStr::from(c.index_name),
on_data_type: c.on_data_type,
prefixes: c.prefixes.into_iter().map(HipStr::from).collect(),
filter: c.filter.map(HipStr::from),
default_score: c.default_score,
score_field: c.score_field.map(HipStr::from),
payload_field: c.payload_field.map(HipStr::from),
language: c.language.map(HipStr::from),
language_field: c.language_field.map(HipStr::from),
max_text_fields: c.max_text_fields,
no_offsets: c.no_offsets,
no_hl: c.no_hl,
no_fields: c.no_fields,
no_freqs: c.no_freqs,
stop_words: c.stop_words.into_iter().map(HipStr::from).collect(),
fields: c.fields,
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct FtSearch {
pub nocontent: bool,
pub verbatim: bool,
pub nostopwords: bool,
pub withscores: bool,
pub withpayloads: bool,
pub withsortkeys: bool,
pub filter: Vec<(String, f64, f64)>, pub geofilter: Vec<(String, f64, f64, f64, String)>, pub inkeys: Vec<String>,
pub infields: Vec<String>,
pub returns: Vec<(String, Option<String>)>, pub sortby: Option<(String, bool)>, pub limit: Option<(usize, usize)>, pub params: RapidHashMap<String, String>,
pub dialect: Option<u32>,
pub slop: Option<usize>,
pub inorder: bool,
pub language: Option<String>,
pub expander: Option<String>,
pub scorer: Option<String>,
pub explain_cli: bool,
pub timeout: Option<u64>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct FtDropIndex {
pub dd: bool, }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FtIndexDefinition {
pub key_type: String,
pub prefixes: Vec<String>,
pub filter: Option<String>,
pub default_score: f64,
pub language: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FtFieldInfo {
pub identifier: String,
pub attribute: Option<String>,
pub field_type: String,
pub properties: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FtInfo {
pub index_name: String,
pub index_options: Vec<String>,
pub index_definition: FtIndexDefinition,
pub fields: Vec<FtFieldInfo>,
pub num_docs: usize,
pub max_doc_id: usize,
pub num_terms: usize,
pub num_records: usize,
pub inverted_sz_mb: f64,
pub vector_index_sz_mb: f64,
pub total_inverted_index_blocks: usize,
pub offset_vectors_sz_mb: f64,
pub doc_table_size_mb: f64,
pub sortable_values_size_mb: f64,
pub key_table_size_mb: f64,
pub records_per_doc_avg: f64,
pub bytes_per_record_avg: f64,
pub offsets_per_term_avg: f64,
pub offset_bits_per_record_avg: f64,
pub hash_indexing_failures: usize,
pub indexing: bool,
pub percent_indexed: f64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FtConfigCommand {
Get(String),
Set(String, String),
Help(String),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FtSugAdd {
pub key: String,
pub string: String,
pub score: f64,
pub incr: bool,
pub payload: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FtSugGet {
pub key: String,
pub prefix: String,
pub fuzzy: bool,
pub withscores: bool,
pub withpayloads: bool,
pub max: Option<usize>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SuggestionItem {
pub string: String,
pub score: f64,
pub payload: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SearchDoc {
pub id: HipStr<'static>,
pub score: f64,
pub payload: Option<Vec<u8>>,
pub sort_key: Option<String>,
pub fields: Vec<(HipStr<'static>, HipStr<'static>)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct FtList;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FtAliasAdd {
pub alias: String,
pub index_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FtAliasDel {
pub alias: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FtAliasUpdate {
pub alias: String,
pub index_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FtTagVals {
pub index_name: String,
pub field_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FtSugDel {
pub key: String,
pub string: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FtSugLen {
pub key: String,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct SearchResult {
pub total_results: usize,
pub docs: Vec<SearchDoc>,
}