Skip to main content

Query

Struct Query 

Source
pub struct Query<'store> { /* private fields */ }

Implementations§

Source§

impl<'store> Query<'store>

Source

pub fn documents<F>(self, f: F) -> Self
where F: Fn(&Document) -> bool + 'store,

Skip documents for which predicate returns false.

Use this to leverage zone-map statistics before scanning blocks:

store.query()
    .documents(|doc| doc.zone_maps.code_languages.contains("python"));
Source

pub fn under_heading( self, content: impl Into<String>, depth: Option<u8>, ) -> Self

Restrict results to blocks that fall within the heading section identified by content and optional depth.

Equivalent to the SQL WHERE b UNDER (SELECT id FROM blocks WHERE ...).

For best performance, chain a .documents(|d| d.zone_maps.heading_contents.contains("...")) filter before this to skip irrelevant documents via zone maps.

Source

pub fn under_interval(self, pre: u32, post: u32) -> Self

Restrict results to blocks that fall within the interval (pre, post).

Use this when you already know the ancestor block’s interval values.

Source

pub fn filter<F>(self, f: F) -> Self
where F: Fn(&Block) -> bool + 'store,

Keep only blocks for which predicate returns true.

Source

pub fn block_type(self, ty: BlockType) -> Self

Keep only blocks with the given BlockType.

Source

pub fn heading_depth(self, depth: u8) -> Self

Keep only heading blocks at the given depth.

Source

pub fn code_lang(self, lang: impl Into<String>) -> Self

Keep only code blocks with the given language tag.

Source

pub fn content_contains(self, substring: impl Into<String>) -> Self

Keep only blocks whose content contains substring (case-sensitive).

Source

pub fn content_contains_ci(self, pattern: impl Into<String>) -> Self

Keep only blocks whose content matches pattern (case-insensitive).

Source

pub fn limit(self, n: usize) -> Self

Stop collecting after n results.

Source

pub fn collect(&self) -> Vec<QueryResult<'_>>

Execute the query, returning matched (block, document) pairs in document order.

Source

pub fn blocks(&self) -> Vec<Block>

Like [collect], but returns cloned blocks (discarding document context).

Returns owned Vec<Block> so it can be used on temporaries:

let blocks = store.query().heading_depth(1).blocks();
assert_eq!(blocks.len(), 1);
Source

pub fn count(&self) -> usize

Returns the number of matching blocks without materialising them.

Source

pub fn lint_heading_followed_by( &self, heading_depth: u8, forbidden_types: &[BlockType], ) -> Vec<LintViolation<'_>>

Find all (heading, next_sibling) pairs where the heading matches the given depth and the immediately following sibling has one of the forbidden_types.

This is the foundation for structural lint rules such as:

“An H2 heading must not be immediately followed by a list.”

§Example
use mq_db::{DocumentStore, block::BlockType};

let mut store = DocumentStore::new();
store.add_str("## Section\n\n- item\n").unwrap();

let q = store.query();
let violations = q.lint_heading_followed_by(2, &[BlockType::List]);

assert_eq!(violations.len(), 1);

Auto Trait Implementations§

§

impl<'store> !RefUnwindSafe for Query<'store>

§

impl<'store> !Send for Query<'store>

§

impl<'store> !Sync for Query<'store>

§

impl<'store> !UnwindSafe for Query<'store>

§

impl<'store> Freeze for Query<'store>

§

impl<'store> Unpin for Query<'store>

§

impl<'store> UnsafeUnpin for Query<'store>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.