SilverStripe Search

BaseQuery
in package
Uses GetterSetterTrait, BaseQueryTrait, Injectable

Class BaseQuery is the base of every query executed.

Build a query to execute agains Solr. Uses as simle as possible an interface.

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] ]
$boostedFields  : array<string|int, mixed>
Sets boosting at _index_ time or _query_ time. Depending on the usage of this trait [ 'FieldName' => 2, ]
$class  : array<string|int, mixed>
$exclude  : array<string|int, mixed>
$facetFields  : array<string|int, mixed>
Format: SiteTree::class => [ 'BaseClass' => SiteTree::class, 'Field' => 'ChannelID', 'Title' => 'Channel' ], Object::class => [ 'BaseClass' => Object::class, 'Field' => 'Relation.ID', 'Title' => 'Relation' ],
$facetsMinCount  : int
$fields  : array<string|int, mixed>
$filter  : array<string|int, mixed>
$followSpellcheck  : bool
$highlight  : 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] ]
$rows  : int
$sort  : array<string|int, mixed>
$spellcheck  : bool
$start  : int
$terms  : array<string|int, mixed>

Methods

addAndFacetFilter()  : $this
Stub for addFacetFilter to add an AND filter
addBoostedField()  : $this
Add a boosted field to be boosted at query time
addClass()  : $this
Add a class to index or query $options is not used anymore, added for backward compatibility
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
addHighlight()  : $this
Add a highlight parameter
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);
getAndFacetFilter()  : array<string|int, mixed>
Stub for AND facets to be get
getBoostedFields()  : array<string|int, mixed>
Get the boosted fields
getClasses()  : array<string|int, mixed>
Get classes
getExclude()  : array<string|int, mixed>
Get the excludes
getFacetFields()  : array<string|int, mixed>
Get the facet fields
getFacetFilter()  : array<string|int, mixed>
Get the AND facet filtering
getFacetsMinCount()  : int
Get the facet count minimum to use
getFields()  : array<string|int, mixed>
Get the fields to return
getFilter()  : array<string|int, mixed>
Get the filters
getHighlight()  : array<string|int, mixed>
Get the highlight parameters
getOrFacetFilter()  : array<string|int, mixed>
Get the OR based facet filtering
getRows()  : int
Get the rows to return
getSort()  : array<string|int, mixed>
Get the sort fields
getStart()  : int
Get the offset to start
getTerms()  : array<string|int, mixed>
Get the search terms
hasSpellcheck()  : bool
Do we have spellchecking
setAndFacetFilter()  : BaseQuery
Stub for AND facets to be set
setBoostedFields()  : $this
Boosted fields are used at index time, not at query time
setClasses()  : $this
Set the classes
setExclude()  : $this
Set the query excludes
setFacetFields()  : $this
Set the facet fields
setFacetFilter()  : BaseQuery
Set the AND based facet filtering
setFacetsMinCount()  : $this
Set the minimum count of facets to be returned
setFields()  : $this
Set fields to be returned
setFilter()  : $this
Set the query filters
setFollowSpellcheck()  : BaseQuery
Set if we should follow spellchecking
setHighlight()  : $this
Set the highlight parameters
setOrFacetFilter()  : BaseQuery
Set the OR based facet filtering
setRows()  : $this
Set the rows to return
setSort()  : $this
Set the sort fields
setSpellcheck()  : self
Set the spellchecking on this query
setStart()  : $this
Set the offset to start
setTerms()  : $this
Set the search tearms
shouldFollowSpellcheck()  : bool
Should spellcheck suggestions be followed

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 = []

$boostedFields

Sets boosting at _index_ time or _query_ time. Depending on the usage of this trait [ 'FieldName' => 2, ]

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

$exclude

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

Fields to exclude

$facetFields

Format: SiteTree::class => [ 'BaseClass' => SiteTree::class, 'Field' => 'ChannelID', 'Title' => 'Channel' ], Object::class => [ 'BaseClass' => Object::class, 'Field' => 'Relation.ID', 'Title' => 'Relation' ],

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

The facets will be applied as a single "AND" query. e.g. SiteTree_ChannelID:1 with Object_Relation_ID:5 will not be found, if the facet filter requires the SiteTree_ChannelID to be 1 AND Object_Relation_ID to be 3 or 6

$facetsMinCount

protected int $facetsMinCount = 1

Minimum results a facet query has to have

$fields

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

Always get the ID. If you don't, you need to implement your own solution

$filter

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

Fields to filter

$followSpellcheck

protected bool $followSpellcheck = false

Follow spellchecking if there are no results

$highlight

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

Highlighted items

$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 = []

$rows

protected int $rows = 10

Total rows to display

$sort

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

Sorting settings

$spellcheck

protected bool $spellcheck = true

Enable spellchecking?

$start

protected int $start = 0

Pagination start

$terms

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

Search terms

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

addBoostedField()

Add a boosted field to be boosted at query time

public addBoostedField(string $field[, array<string|int, mixed>|int $options = [] ][, int|null $boost = null ]) : $this

This method is out of place in a way, but it's a shared method between Index and Query, thus needs to be here.

Parameters
$field : string
$options : array<string|int, mixed>|int = []
$boost : int|null = null
Return values
$this

addClass()

Add a class to index or query $options is not used anymore, added for backward compatibility

public addClass( $class[, array<string|int, mixed> $options = [] ]) : $this
Parameters
$class :
$options : array<string|int, mixed> = []

unused

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

addHighlight()

Add a highlight parameter

public addHighlight( $field) : $this
Parameters
$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

getAndFacetFilter()

Stub for AND facets to be get

public getAndFacetFilter() : array<string|int, mixed>
Return values
array<string|int, mixed>

getBoostedFields()

Get the boosted fields

public getBoostedFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getClasses()

Get classes

public getClasses() : array<string|int, mixed>
Return values
array<string|int, mixed>

getExclude()

Get the excludes

public getExclude() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFacetFields()

Get the facet fields

public getFacetFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFacetFilter()

Get the AND facet filtering

public getFacetFilter() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFacetsMinCount()

Get the facet count minimum to use

public getFacetsMinCount() : int
Return values
int

getFields()

Get the fields to return

public getFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFilter()

Get the filters

public getFilter() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHighlight()

Get the highlight parameters

public getHighlight() : array<string|int, mixed>
Return values
array<string|int, mixed>

getOrFacetFilter()

Get the OR based facet filtering

public getOrFacetFilter() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRows()

Get the rows to return

public getRows() : int
Return values
int

getSort()

Get the sort fields

public getSort() : array<string|int, mixed>
Return values
array<string|int, mixed>

getStart()

Get the offset to start

public getStart() : int
Return values
int

getTerms()

Get the search terms

public getTerms() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasSpellcheck()

Do we have spellchecking

public hasSpellcheck() : bool
Return values
bool

setAndFacetFilter()

Stub for AND facets to be set

public setAndFacetFilter(array<string|int, mixed> $facetFilter) : BaseQuery
Parameters
$facetFilter : array<string|int, mixed>
Return values
BaseQuery

setBoostedFields()

Boosted fields are used at index time, not at query time

public setBoostedFields(array<string|int, mixed> $boostedFields) : $this
Parameters
$boostedFields : array<string|int, mixed>
Return values
$this

setClasses()

Set the classes

public setClasses(array<string|int, mixed> $class) : $this
Parameters
$class : array<string|int, mixed>
Return values
$this

setExclude()

Set the query excludes

public setExclude(array<string|int, mixed> $exclude) : $this
Parameters
$exclude : array<string|int, mixed>
Return values
$this

setFacetFields()

Set the facet fields

public setFacetFields(array<string|int, mixed> $facetFields) : $this
Parameters
$facetFields : array<string|int, mixed>
Return values
$this

setFacetFilter()

Set the AND based facet filtering

public setFacetFilter(array<string|int, mixed> $facetFilter) : BaseQuery
Parameters
$facetFilter : array<string|int, mixed>
Return values
BaseQuery

setFacetsMinCount()

Set the minimum count of facets to be returned

public setFacetsMinCount(mixed $facetsMinCount) : $this
Parameters
$facetsMinCount : mixed
Return values
$this

setFields()

Set fields to be returned

public setFields(array<string|int, mixed> $fields) : $this
Parameters
$fields : array<string|int, mixed>
Return values
$this

setFilter()

Set the query filters

public setFilter(array<string|int, mixed> $filter) : $this
Parameters
$filter : array<string|int, mixed>
Return values
$this

setFollowSpellcheck()

Set if we should follow spellchecking

public setFollowSpellcheck(bool $followSpellcheck) : BaseQuery
Parameters
$followSpellcheck : bool
Return values
BaseQuery

setHighlight()

Set the highlight parameters

public setHighlight(array<string|int, mixed> $highlight) : $this
Parameters
$highlight : array<string|int, mixed>
Return values
$this

setOrFacetFilter()

Set the OR based facet filtering

public setOrFacetFilter(array<string|int, mixed> $facetFilter) : BaseQuery
Parameters
$facetFilter : array<string|int, mixed>
Return values
BaseQuery

setRows()

Set the rows to return

public setRows(int $rows) : $this
Parameters
$rows : int
Return values
$this

setSort()

Set the sort fields

public setSort(array<string|int, mixed> $sort) : $this
Parameters
$sort : array<string|int, mixed>
Return values
$this

setSpellcheck()

Set the spellchecking on this query

public setSpellcheck(bool $spellcheck) : self
Parameters
$spellcheck : bool
Return values
self

setStart()

Set the offset to start

public setStart(int $start) : $this
Parameters
$start : int
Return values
$this

setTerms()

Set the search tearms

public setTerms(array<string|int, mixed> $terms) : $this
Parameters
$terms : array<string|int, mixed>
Return values
$this

shouldFollowSpellcheck()

Should spellcheck suggestions be followed

public shouldFollowSpellcheck() : bool
Return values
bool

        
On this page

Search results