---
title: MDQuery
framework: coreservices
role: collectionGroup
role_heading: API Collection
path: coreservices/file_metadata/mdquery
---

# MDQuery

## Overview

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 filemetadata.  An MDQuery normally executes asynchronously and posts progressnotifications as the results are collected. During the gatheringphase the query results conform to the specified value lists andsorting. MDQuery gathers results and processes updates only while thecurrent thread's run loop is running. For functions that take an MDQueryRef parameter, if this parameteris not a valid MDQueryRef, the behavior is undefined. NULL isnot a valid MDQueryRef.  For functions that take CF*Ref parameters, such as CFStringRefand CFArrayRef, if this parameter is not a valid CF object of thecorrect type, the behavior is undefined. NULL isnot a valid CF*Ref.

## Topics

### Creating Queries

- [MDQueryCreate(_:_:_:_:)](coreservices/1413029-mdquerycreate.md)
- [MDQueryCreateSubset(_:_:_:_:_:)](coreservices/1413027-mdquerycreatesubset.md)
- [MDQuerySetSearchScope(_:_:_:)](coreservices/1413048-mdquerysetsearchscope.md)
- [MDQuerySetDispatchQueue(_:_:)](coreservices/1413019-mdquerysetdispatchqueue.md)

### Getting and Setting Query Parameters

- [MDQuerySetMaxCount(_:_:)](coreservices/1413085-mdquerysetmaxcount.md)
- [MDQueryGetBatchingParameters(_:)](coreservices/1413006-mdquerygetbatchingparameters.md)
- [MDQuerySetBatchingParameters(_:_:)](coreservices/1413103-mdquerysetbatchingparameters.md)
- [MDQueryCopyValueListAttributes(_:)](coreservices/1413071-mdquerycopyvaluelistattributes.md)
- [MDQueryCopySortingAttributes(_:)](coreservices/1413059-mdquerycopysortingattributes.md)
- [MDQueryCopyQueryString(_:)](coreservices/1413004-mdquerycopyquerystring.md)

### Setting Callback Functions

- [MDQuerySetCreateResultFunction(_:_:_:_:)](coreservices/1413064-mdquerysetcreateresultfunction.md)
- [MDQuerySetSortComparator(_:_:_:)](coreservices/1413087-mdquerysetsortcomparator.md)
- [MDQuerySetCreateValueFunction(_:_:_:_:)](coreservices/1413017-mdquerysetcreatevaluefunction.md)

### Starting, Stopping and Pausing Queries

- [MDQueryExecute(_:_:)](coreservices/1413099-mdqueryexecute.md)
- [MDQueryStop(_:)](coreservices/1413077-mdquerystop.md)
- [MDQueryDisableUpdates(_:)](coreservices/1413041-mdquerydisableupdates.md)
- [MDQueryEnableUpdates(_:)](coreservices/1413066-mdqueryenableupdates.md)
- [MDQueryIsGatheringComplete(_:)](coreservices/1413032-mdqueryisgatheringcomplete.md)

### Getting Query Result Values

- [MDQueryCopyValuesOfAttribute(_:_:)](coreservices/1413105-mdquerycopyvaluesofattribute.md)
- [MDQueryGetAttributeValueOfResultAtIndex(_:_:_:)](coreservices/1413046-mdquerygetattributevalueofresult.md)
- [MDQueryGetCountOfResultsWithAttributeValue(_:_:_:)](coreservices/1413009-mdquerygetcountofresultswithattr.md)
- [MDQueryGetIndexOfResult(_:_:)](coreservices/1413093-mdquerygetindexofresult.md)
- [MDQueryGetResultAtIndex(_:_:)](coreservices/1413055-mdquerygetresultatindex.md)
- [MDQueryGetResultCount(_:)](coreservices/1413008-mdquerygetresultcount.md)
- [MDQuerySetSortComparatorBlock(_:_:)](coreservices/1413021-mdquerysetsortcomparatorblock.md)

### Getting the Type Identifier

- [MDQueryGetTypeID()](coreservices/1413037-mdquerygettypeid.md)

### Callbacks

- [MDQuerySortComparatorFunction](coreservices/mdquerysortcomparatorfunction.md)
- [MDQueryCreateResultFunction](coreservices/mdquerycreateresultfunction.md)
- [MDQueryCreateValueFunction](coreservices/mdquerycreatevaluefunction.md)

### Batching Parameters

- [MDQueryBatchingParams](coreservices/mdquerybatchingparams.md)

### Miscellaneous

- [MDQuery](coreservices/mdquery.md)

### Query Option Flags

- [MDQueryOptionFlags](coreservices/mdqueryoptionflags.md)

### Notifications

- [kMDQueryDidFinishNotification](coreservices/file_metadata/mdquery/kmdquerydidfinishnotification.md)
- [kMDQueryDidUpdateNotification](coreservices/file_metadata/mdquery/kmdquerydidupdatenotification.md)
- [kMDQueryProgressNotification](coreservices/file_metadata/mdquery/kmdqueryprogressnotification.md)

### Notification Info Keys

- [Query Result Change Keys](coreservices/file_metadata/mdquery/query_result_change_keys.md)
- [Query Search Scope Keys](coreservices/file_metadata/mdquery/query_search_scope_keys.md)
- [Result Relevance Sorting Key](coreservices/file_metadata/mdquery/result_relevance_sorting_key.md)

## See Also

### Related Documentation

- [Spotlight Overview](apple-archive/documentation/Carbon/Conceptual/MetadataIntro.md)
- [File Metadata Search Programming Guide](apple-archive/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/Introduction.html.md)
