MDQuery

Overview

MDQuery is a CF-compliant object, follows the CF conventions, and can be used with the CF polymorphic functions, such as CFRetain. MDQuery encapsulates queries against the System store of the file metadata.

An MDQuery normally executes asynchronously and posts progress notifications as the results are collected. During the gathering phase the query results conform to the specified value lists and sorting.

MDQuery gathers results and processes updates only while the current thread's run loop is running.

For functions that take an MDQueryRef parameter, if this parameter is not a valid MDQueryRef, the behavior is undefined. NULL is not a valid MDQueryRef.

For functions that take CF*Ref parameters, such as CFStringRef and CFArrayRef, if this parameter is not a valid CF object of the correct type, the behavior is undefined. NULL is not a valid CF*Ref.

Topics

Creating Queries

MDQueryCreate

Creates a new query instance.

MDQueryCreateSubset

Creates a new query that is a subset of the specified parentquery.

MDQuerySetSearchScope

Sets the search scope for a query instance.

MDQuerySetDispatchQueue

Sets the dispatch queue on which query results will be delivered by MDQueryExecute.

Getting and Setting Query Parameters

MDQuerySetMaxCount

Sets the maximum number of results returned.

MDQueryGetBatchingParameters

Returns the current parameters that control the batching of progress notifications.

MDQuerySetBatchingParameters

Set the query batching parameters.

MDQueryCopyValueListAttributes

Returns the list of attribute names for which values are being collected by the query.

MDQueryCopySortingAttributes

Returns the list of attribute names used to sort the results.

MDQueryCopyQueryString

Returns the query string of the query.

Setting Callback Functions

MDQuerySetCreateResultFunction

Sets the function used to create the result objects of the MDQuery.

MDQuerySetSortComparator

Sets the function used to sort the results of an MDQuery.

MDQuerySetCreateValueFunction

Sets the function used to create the value objects of the MDQuery.

Starting, Stopping and Pausing Queries

MDQueryExecute

Run the query, and populate the query with the results.

MDQueryStop

Stops the query from generating more results.

MDQueryDisableUpdates

Disables updates to the query result list.

MDQueryEnableUpdates

Enables updates to the query result list.

MDQueryIsGatheringComplete

Returns true if the first phase of a query, the initial result gathering, has finished.

Getting Query Result Values

MDQueryCopyValuesOfAttribute

Returns the list of values from the results of the query for the specified attribute.

MDQueryGetAttributeValueOfResultAtIndex

Returns the value of the named attribute for the result at the given index.

MDQueryGetCountOfResultsWithAttributeValue

Returns the number of results which have the given attribute and attribute value.

MDQueryGetIndexOfResult

Returns the current index of the given result.

MDQueryGetResultAtIndex

Returns the current result at the given index.

MDQueryGetResultCount

Returns the number of results currently collected by the query.

MDQuerySetSortComparatorBlock

Sets the block used to sort the results of an MDQuery.

Getting the Type Identifier

MDQueryGetTypeID

Returns the type identifier of all MDQuery instances

Callbacks

MDQuerySortComparatorFunction

Callback function used to sort the results of a query.

MDQueryCreateResultFunction

Callback function used to create the result objects stored and returned by a query.

MDQueryCreateValueFunction

Callback function used to create the value objects stored and returned by a query.

Batching Parameters

MDQueryBatchingParams

Structure containing the progress notification batching parameters of a MDQuery.

Miscellaneous

MDQueryRef

A reference to a MDQuery object.

Query Option Flags

MDQueryOptionFlags

Specify the execution mode for a query.

Notifications

kMDQueryDidFinishNotification

Indicates that a query has finished with the initial result-gathering phase.

kMDQueryDidUpdateNotification

Indicates that a query’s results list has change during the live-update phase of a query.

kMDQueryProgressNotification

Indicates that a query’s results list has change during the initial result-gathering phase of a query.

Notification Info Keys

Query Result Change Keys

Specify the items that have changed in the query results.

Query Search Scope Keys

Specify the scope of a query’s search.

Result Relevance Sorting Key

Key used in a user notification’s description dictionary that indicates the relevance of a result.