SilverStripe Search

BaseQueryTrait

Trait BaseQueryTrait Extraction from the BaseQuery class to keep things readable.

This trait adds the support for adding the basic field/filter/term/facet options

Table of Contents

Properties

$andFacetFilter  : array<string|int, mixed>
Key => value pairs of facets to apply in AND fashion [ 'FacetTitle' => [1, 2, 3], 'FacetTitle2' => [1, 2, 3] ]
$exclude  : array<string|int, mixed>
$fields  : array<string|int, mixed>
$filter  : array<string|int, mixed>
$orFacetFilter  : array<string|int, mixed>
Key => value pairs of facets to apply in OR fashion [ 'FacetTitle' => [1, 2, 3], 'FacetTitle2' => [1, 2, 3] ]
$sort  : array<string|int, mixed>
$terms  : array<string|int, mixed>

Methods

addAndFacetFilter()  : $this
Stub for addFacetFilter to add an AND filter
addExclude()  : $this
Exclude fields from the search action
addFacetFilter()  : $this
Add faceting fields that need to be faceted in an AND format
addField()  : $this
Add a field to be returned
addFilter()  : $this
Adds filters to filter on by value
addOrFacetFilter()  : $this
Add faceting that need to be faceted in an OR formats
addSort()  : $this
Add a field to sort on
addTerm()  : $this
Each boosted query needs a separate addition! e.g. $this->addTerm('test', ['MyField', 'MyOtherField'], 3) followed by $this->addTerm('otherTest', ['Title'], 5);

Properties

$andFacetFilter

Key => value pairs of facets to apply in AND fashion [ 'FacetTitle' => [1, 2, 3], 'FacetTitle2' => [1, 2, 3] ]

protected array<string|int, mixed> $andFacetFilter = []

$exclude

protected array<string|int, mixed> $exclude = []

Fields to exclude

$fields

protected array<string|int, mixed> $fields = []

Fields to search

$filter

protected array<string|int, mixed> $filter = []

Fields to filter

$orFacetFilter

Key => value pairs of facets to apply in OR fashion [ 'FacetTitle' => [1, 2, 3], 'FacetTitle2' => [1, 2, 3] ]

protected array<string|int, mixed> $orFacetFilter = []

$sort

protected array<string|int, mixed> $sort = []

Sorting order

$terms

protected array<string|int, mixed> $terms = []

Terms to search

Methods

addAndFacetFilter()

Stub for addFacetFilter to add an AND filter

public addAndFacetFilter(string $field, string|array<string|int, mixed> $value) : $this
Parameters
$field : string
$value : string|array<string|int, mixed>
Return values
$this

addExclude()

Exclude fields from the search action

public addExclude(string $field, string|array<string|int, mixed>|Criteria $value) : $this
Parameters
$field : string
$value : string|array<string|int, mixed>|Criteria
Return values
$this

addFacetFilter()

Add faceting fields that need to be faceted in an AND format

public addFacetFilter(string $field, string|array<string|int, mixed> $value) : $this
Parameters
$field : string

Field to facet

$value : string|array<string|int, mixed>

Value to facet

Return values
$this

addField()

Add a field to be returned

public addField(string $field) : $this
Parameters
$field : string

fieldname

Return values
$this

addFilter()

Adds filters to filter on by value

public addFilter(string $field, string|array<string|int, mixed>|Criteria $value) : $this
Parameters
$field : string

Field to filter on

$value : string|array<string|int, mixed>|Criteria

Value for this field

Return values
$this

addOrFacetFilter()

Add faceting that need to be faceted in an OR formats

public addOrFacetFilter(string $field, string|array<string|int, mixed> $value) : $this
Parameters
$field : string

Field to facet

$value : string|array<string|int, mixed>

Value to facet

Return values
$this

addSort()

Add a field to sort on

public addSort(string $field, string $direction) : $this
Parameters
$field : string
$direction : string
Return values
$this

addTerm()

Each boosted query needs a separate addition! e.g. $this->addTerm('test', ['MyField', 'MyOtherField'], 3) followed by $this->addTerm('otherTest', ['Title'], 5);

public addTerm(string $term[, array<string|int, mixed> $fields = [] ][, int $boost = 0 ][, bool|float $fuzzy = null ]) : $this

If you want a generic boost on all terms, use addTerm only once, but boost on each field

The fields parameter is used to boost on

For generic boosting, use @addBoostedField($field, $boost), this will add the boost at Index time

Parameters
$term : string

Term to search for

$fields : array<string|int, mixed> = []

fields to boost on

$boost : int = 0

Boost value

$fuzzy : bool|float = null

True or a value to the maximum amount of iterations

Return values
$this

        
On this page

Search results