use serde::{Deserialize, Serialize};
mod noop;
mod strict;
pub use noop::NoopEngine;
pub use strict::StrictEngine;
#[derive(Debug)]
pub struct SearchOptions {
pub offset: u64,
pub limit: u8,
pub strict: bool,
pub yanked: bool,
}
impl Default for SearchOptions {
fn default() -> Self {
SearchOptions {
offset: 0,
limit: 50,
strict: false,
yanked: false,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Matches {
pub query: String,
pub strict: bool,
pub offset: u64,
pub limit: u8,
pub total: u64,
pub more: bool,
pub yanked: bool,
pub invoices: Vec<crate::Invoice>,
}
impl Matches {
fn new(opts: &SearchOptions, query: String) -> Self {
Matches {
query,
strict: opts.strict,
offset: opts.offset,
limit: opts.limit,
yanked: opts.yanked,
invoices: vec![],
more: false,
total: 0,
}
}
}
#[async_trait::async_trait]
pub trait Search {
async fn query(
&self,
term: &str,
filter: &str,
options: SearchOptions,
) -> anyhow::Result<Matches>;
async fn index(&self, document: &crate::Invoice) -> anyhow::Result<()>;
}