Baloo::Query Class

The Query class is the central class to query to search for files from the Index. More...

Header: #include <Baloo/Query>
CMake: find_package(KF6 REQUIRED COMPONENTS Baloo)
target_link_libraries(mytarget PRIVATE KF6::Baloo)

Public Types

enum SortingOption { SortNone, SortAuto }

Public Functions

Query()
int dayFilter() const
Baloo::ResultIterator exec()
QString includeFolder() const
uint limit() const
int monthFilter() const
uint offset() const
(since 6.32) QStringList searchScopes() const
QString searchString() const
void setDateFilter(int year, int month = 0, int day = 0)
void setIncludeFolder(const QString &folder)
void setLimit(uint limit)
void setOffset(uint offset)
(since 6.32) void setSearchScopes(const QStringList &scopes)
void setSearchString(const QString &str)
void setSortingOption(Baloo::Query::SortingOption option)
void setTypes(const QStringList &types)
Baloo::Query::SortingOption sortingOption() const
QByteArray toJSON()
QUrl toSearchUrl(const QString &title = QString())
QStringList types() const
int yearFilter() const

Static Public Members

Baloo::Query fromJSON(const QByteArray &arr)
Baloo::Query fromSearchUrl(const QUrl &url)
QString titleFromQueryUrl(const QUrl &url)

Detailed Description

This class has an inbuilt parser which recognizes words along with AND / OR and parenthesis and specific properties. This can be used with the setSearchString method

Examples:

"Fire" -> Looks for all files which contain the word "Fire"

"Fire OR water" -> Looks for files which contain either "Fire" or "Water". The capitalization of the words doesn't matter as that will be ignored internally. However, OR and AND have to be in upper case.

"artist:Coldplay" -> Look for any files with the artist "Coldplay"

"(artist:Coldplay OR artist:Maroon5) power" -> Look for files with the artist Coldplay or Maroon5 and the word "power"

"artist:'Noah and the Whale'" -> Look for files with the artist "Noah and the Whale"

"type:Audio title:Fix" -> Look for Audio files which contains the title "Fix" in its title.

The Query Parser recognizes a large number of properties. These property names can be looked up in KFileMetaData::Property::Property. The type of the file can mentioned with the property 'type' or 'kind'.

Member Type Documentation

enum Query::SortingOption

ConstantValueDescription
Baloo::Query::SortNone0The results are returned in the most efficient order. They can be returned in any order.
Baloo::Query::SortAuto1The results are returned in the order Baloo decides should be ideal. This criteria is based on the mtime of the file. This is the default sorting mechanism.

Member Function Documentation

Query::Query()

int Query::dayFilter() const

Baloo::ResultIterator Query::exec()

[static] Baloo::Query Query::fromJSON(const QByteArray &arr)

[static] Baloo::Query Query::fromSearchUrl(const QUrl &url)

QString Query::includeFolder() const

See also setIncludeFolder().

uint Query::limit() const

See also setLimit().

int Query::monthFilter() const

uint Query::offset() const

See also setOffset().

[since 6.32] QStringList Query::searchScopes() const

This function was introduced in 6.32.

See also setSearchScopes().

QString Query::searchString() const

See also setSearchString().

void Query::setDateFilter(int year, int month = 0, int day = 0)

Filter the results in the specified date range.

The year/month/day may be set to 0 in order to ignore it.

void Query::setIncludeFolder(const QString &folder)

Only files in this folder will be returned

See also includeFolder().

void Query::setLimit(uint limit)

Only a maximum of limit results will be returned.

The default limit value of std::numeric_limits<uint>::max() will be treated as unlimited.

See also limit().

void Query::setOffset(uint offset)

See also offset().

[since 6.32] void Query::setSearchScopes(const QStringList &scopes)

Limit where to look for a match

By default (empty scopes), terms are matched with the filename, plain text content, and any string like property from the file metadata (e.g. Album or Artist name).

Search terms with an explicit property name are not affected by the search scope value.

If multiple scopes are provided, each is checked and the results are combined. Invalid/unknown scopes are ignored. Scope names are case insensitive.

ConstantValue
FileName
Content
Metadata

This function was introduced in 6.32.

See also searchScopes().

void Query::setSearchString(const QString &str)

Set some text which should be used to search for Items. This contain a single word or an entire sentence.

See also searchString().

void Query::setSortingOption(Baloo::Query::SortingOption option)

See also sortingOption().

void Query::setTypes(const QStringList &types)

Set a filter to limit the query results to specific file types.

Every file has a high level type such as "Audio", "Video", "Image", "Document", etc.

Please note that the types are ANDed together. So searching for "Image" and "Video" will probably never return any results. Have a look at KFileMetaData::TypeInfo for a list of type names.

Use an empty list to clear the type filter.

See also types().

Baloo::Query::SortingOption Query::sortingOption() const

See also setSortingOption().

[static] QString Query::titleFromQueryUrl(const QUrl &url)

QByteArray Query::toJSON()

QUrl Query::toSearchUrl(const QString &title = QString())

QStringList Query::types() const

See also setTypes().

int Query::yearFilter() const