pub struct Query<'store> { /* private fields */ }Implementations§
Source§impl<'store> Query<'store>
impl<'store> Query<'store>
Sourcepub fn documents<F>(self, f: F) -> Self
pub fn documents<F>(self, f: F) -> Self
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"));Sourcepub fn under_heading(
self,
content: impl Into<String>,
depth: Option<u8>,
) -> Self
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.
Sourcepub fn under_interval(self, pre: u32, post: u32) -> Self
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.
Sourcepub fn block_type(self, ty: BlockType) -> Self
pub fn block_type(self, ty: BlockType) -> Self
Keep only blocks with the given BlockType.
Sourcepub fn heading_depth(self, depth: u8) -> Self
pub fn heading_depth(self, depth: u8) -> Self
Keep only heading blocks at the given depth.
Sourcepub fn code_lang(self, lang: impl Into<String>) -> Self
pub fn code_lang(self, lang: impl Into<String>) -> Self
Keep only code blocks with the given language tag.
Sourcepub fn content_contains(self, substring: impl Into<String>) -> Self
pub fn content_contains(self, substring: impl Into<String>) -> Self
Keep only blocks whose content contains substring (case-sensitive).
Sourcepub fn content_contains_ci(self, pattern: impl Into<String>) -> Self
pub fn content_contains_ci(self, pattern: impl Into<String>) -> Self
Keep only blocks whose content matches pattern (case-insensitive).
Sourcepub fn collect(&self) -> Vec<QueryResult<'_>>
pub fn collect(&self) -> Vec<QueryResult<'_>>
Execute the query, returning matched (block, document) pairs in document order.
Sourcepub fn blocks(&self) -> Vec<Block>
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);Sourcepub fn lint_heading_followed_by(
&self,
heading_depth: u8,
forbidden_types: &[BlockType],
) -> Vec<LintViolation<'_>>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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