MDQueryBuilder

Struct MDQueryBuilder 

Source
pub struct MDQueryBuilder { /* private fields */ }
Expand description

Builder for constructing MDQuery instances with a fluent interface.

This builder allows for creating complex metadata queries on macOS using the Spotlight search technology. It provides methods to build search expressions that can be combined with logical AND operations.

§Examples

use mdquery_rs::{MDQueryBuilder, MDQueryScope};

// Find files containing "document" in their name
let query = MDQueryBuilder::default()
    .name_like("document")
    .build(vec![MDQueryScope::Home], None)
    .unwrap();
     
let results = query.execute().unwrap();
for item in results {
    println!("{:?}", item.path());
}

Implementations§

Source§

impl MDQueryBuilder

Source

pub fn build( self, scopes: Vec<MDQueryScope>, max_count: Option<usize>, ) -> Result<MDQuery>

Builds the final MDQuery with the current expressions.

§Parameters
  • scopes - List of search scopes to apply (e.g., Home, Computer)
  • max_count - Optional maximum number of results to return
§Returns

A Result containing the MDQuery if successful, or an error if no expressions were added.

§Errors

Returns an error if no expressions were added to the builder.

Source

pub fn from_condition(condition: MDQueryCondition) -> Self

Creates a new builder from a condition.

§Parameters
  • condition - The condition to add to the builder
§Returns

Self for method chaining

Source

pub fn from_raw(query: &str) -> Self

Creates a new builder from a raw query string.

§Parameters
  • query - The raw query string
§Returns

Self for method chaining

Source

pub fn name_like(self, name: &str) -> Self

Adds an expression to match items whose display name contains the specified string.

This performs a case-insensitive substring search and supports Chinese Pinyin.

§Parameters
  • name - The substring to match in display names
§Returns

Self for method chaining

Source

pub fn name_is(self, name: &str) -> Self

Adds an expression to match items whose display name exactly matches the specified string.

This performs a case-insensitive exact match.

§Parameters
  • name - The exact name to match
§Returns

Self for method chaining

Source

pub fn time(self, key: MDItemKey, op: MDQueryCompareOp, timestamp: i64) -> Self

Adds a time-based comparison expression.

§Parameters
  • key - The time-related metadata key to compare
  • op - The comparison operator to use
  • timestamp - Unix timestamp to compare against
§Returns

Self for method chaining

§Panics

Panics if the provided key is not a time-related key.

Source

pub fn size(self, op: MDQueryCompareOp, size: u64) -> Self

Adds a file size comparison expression.

§Parameters
  • op - The comparison operator to use
  • size - The file size in bytes to compare against
§Returns

Self for method chaining

Source

pub fn is_dir(self, value: bool) -> Self

Adds an expression to filter items based on whether they are directories.

§Parameters
  • value - If true, matches only directories; if false, matches only non-directories
§Returns

Self for method chaining

§Note

Special directory types such as app bundles are not included in the directory scope.

Source

pub fn is_app(self) -> Self

Adds an expression to filter items based on whether they are application bundles.

§Returns

Self for method chaining

Source

pub fn extension(self, ext: &str) -> Self

Adds an expression to match items with the specified file extension.

§Parameters
  • ext - The file extension to match (without the leading dot)
§Returns

Self for method chaining

Source

pub fn content_type(self, content_type: &str) -> Self

Adds an expression to match items with the specified content type.

§Parameters
  • content_type - The content type UTI string to match
§Returns

Self for method chaining

Trait Implementations§

Source§

impl Default for MDQueryBuilder

Source§

fn default() -> MDQueryBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<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, 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.
Source§

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