githubEdit Page

Base Filter

Base filters are used to filter the resultset on a dashboard or a search modal. They can be visible (displayFilter) or invisible (all other types). Base filters are used in different places and have a common format to construct the filter query.

Filter Query Format

There are different places, where one can define base filter:

At all this places, one can use the same query format, e.g.

{type: 'documentType', value: 'article'}

The query format always has a type and most of the time a value. You can see some examples in the next section.

Filter Query Types

This are all available queryTypes which can be used to form a filter query.

// documentType {type: 'string', value: string || array}
{type: 'documentType', value: 'article'}
{type: 'documentType', value: ['article', 'page']}

// locale
{type: 'locale', value: 'de-DE'}

// channelHandle
{type: 'channelHandle', value: 'web'}

// contentType {type: 'string', value: string || array}
{type: 'contentType', value: 'regular'}
{type: 'contentType', value: ['regular', 'news']}

// notContentType{type: 'string', value: string || array}
{type: 'notContentType', value: 'regular'}
{type: 'notContentType', value: ['regular', 'news']}

// ownerId
{type: 'ownerId', value: 1}

// channelId
{type: 'channelId', value: 2}

// dateRange
const from = new Date('2016-01-23T15:00')
const to = new Date('2015-04-05T20:00')
{type: 'dateRange', key: 'created_at', from, to}

// documentState (value: 'published', 'unpublished', 'deleted', 'draft', 'publishedWithDraft')
{type: 'documentState', value: 'published'}

// metadata (multiple key, value combinations possible)
{type: 'metadata', key: 'foo', value: 'bar'}
{type: 'metadata', key: 'foo', value: {exists: true}}
{type: 'metadata', key: 'foo.bar.id', value: 42}

const from = new Date('2016-01-23T15:00')
const to = new Date('2015-04-05T20:00')
{type: 'metadata', key: 'publicationDate', value: {dateFilter: {from, to}}}

// task (multiple taskName and taskValue combinations possible)
// taskValue: 'todo', 'doing', 'done'
{type: 'task', taskName: 'proofreading', taskValue: 'pending'},
{type: 'task', taskName: 'review', taskValue: 'done'}

// sortBy (multiple values possible)
{type: 'sortBy', value: '-created_at'},
{type: 'sortBy', value: 'title'}

// media Index base filter for metadata
{type: 'metadata', key: 'foo', value: 'bar', dataType: 'keyword'}
{type: 'metadata', key: 'transformed', value: true, dataType: 'boolean'}
// metadata plugin with a set key in the index_behavior
{type: 'metadata', key: 'googleVision.labels', value: 'Vogel', dataType: 'keyword'}

Filter Query Examples

Example 1 - filter by documentType

baseFilters: [
  {type: 'documentType', value: 'article'}
]

This would reduce the search to only articles (no pages).

Example 2 - filter by metadata with key/value

baseFilters: [
  {type: 'metadata', key: 'foo', value: 'bar'}
]

This would filter for only documents that have the value bar in the metadata field foo. You have to make sure that foo is an indexed metadata field.

Example 3 - filter by metadata with objects

defaultQueries: [
  {type: 'metadata', key: 'author.reference.id', value: 42}
]

More complex metadata fields are indexed as an object (instead of key/value). In this case one can filter based on subproperties.

// This is how the metadata field has been indexed into the search index
{
  metadata: {
    author: {
      reference: {
        id: 42
      }
    }
  }
}

This example would filter documents that have the value 42 in the metadata field author with propreties reference.id. You have to make sure that author is an indexed metadata field.

Example 4 - filter by task

defaultQueries: [
  {type: 'task', taskName: 'proofreading', taskValue: 'done'}
]

This would filter for only documents that have had a successful proofreading. The core only exposes the proofreading task, but you can define your own custom tasks. The values are todo, doing, done for the 3 states that a task can have.

Example 5 - filter by metadata with dataType keyword for mediaIndex

baseFilters: [
  {type: 'metadata', key: 'transformed', value: true, dataType: 'boolean'}
]

This would filter for only transformed assets.