BaseIndex
in package
Uses
Extensible, Configurable, Injectable, GetterSetterTrait, BaseIndexTrait
Base for creating a new Solr core.
Base index settings and methods. Should be extended with at least a name for the index. This is an abstract class that can not be instantiated on it's own
Table of Contents
Properties
- $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>
- $client : Client
- $clientQuery : Query
- $copyFields : array<string|int, mixed>
- $defaultField : string
- $facetFields : array<string|int, mixed>
- $filterFields : array<string|int, mixed>
- $fulltextFields : array<string|int, mixed>
- $queryFactory : QueryComponentFactory
- {@link QueryComponentFactory}
- $queryTerms : array<string|int, mixed>
- $schemaFactory : SchemaFactory
- {@link SchemaFactory}
- $sortFields : array<string|int, mixed>
- $storedFields : array<string|int, mixed>
- $usedAllFields : bool
- usedAllFields is used to determine if the addAllFields method has been called This is to prevent a notice if there is no yml.
- $fieldTypes : mixed
- Field types that can be added Used in init to call build methods from configuration yml
- $retry : bool
Methods
- __construct() : mixed
- BaseIndex constructor.
- addAllDateFields() : mixed
- Add all date-type fields to the given index
- addAllFulltextFields() : mixed
- Add all text-type fields to the given index
- addBoostedField() : mixed
- Add an abstract for the add Boosted Field to keep things consistent
- addClass() : $this
- Add a class to index or query $options is not used anymore, added for backward compatibility
- addCopyField() : $this
- Add a copy field
- addFacetField() : $this
- Add a facet field
- addFilterField() : $this
- Add a filterable field
- addFulltextField() : $this
- Add a single Fulltext field
- addSortField() : $this
- Add a field to sort on
- addStoredField() : BaseIndex
- Add a stored/fulltext field
- buildSolrQuery() : Query
- From the given BaseQuery, generate a Solarium ClientQuery object
- doSearch() : SearchResult|ArrayData|mixed
- Default returns a SearchResult. It can return an ArrayData if FTS Compat is enabled
- getBoostedFields() : array<string|int, mixed>
- Get the boosted fields
- getClasses() : array<string|int, mixed>
- This trait requires classes to be set, so getClasses can be called.
- getClient() : Client
- Get the client
- getClientQuery() : Query
- Retrieve the Solarium client Query object for this index operation
- getConfig() : array<string|int, mixed>
- Build a full config for all given endpoints This is to add the current index to e.g. an index or select
- getCopyFields() : array<string|int, mixed>
- Return the copy fields
- getDefaultField() : string
- Return the default field for this index
- getFacetFields() : array<string|int, mixed>
- Get the facet fields
- getFieldsForIndexing() : array<string|int, mixed>
- Get all fields that are required for indexing in a unique way
- getFilterFields() : array<string|int, mixed>
- Get the filter fields
- getFulltextFields() : array<string|int, mixed>
- Get the fulltext fields
- getIndexName() : string
- Name of this index.
- getQueryFactory() : QueryComponentFactory
- Get the QueryComponentFactory. {@link QueryComponentFactory}
- getQueryTerms() : array<string|int, mixed>
- Get the final, generated terms
- getSortFields() : array<string|int, mixed>
- Get the sortable fields
- getStoredFields() : array<string|int, mixed>
- Get the stored field list
- getSynonyms() : string
- Add synonyms. Public to be extendable
- init() : mixed
- Required to initialise the fields.
- isRetry() : bool
- setBoostedFields() : $this
- Boosted fields are used at index time, not at query time
- setClasses() : $this
- Set the classes
- setClient() : $this
- Set/override the client
- setCopyFields() : $this
- Set the copy fields
- setDefaultField() : $this
- Set the default field for this index
- setFacetFields() : $this
- Set the facet fields
- setFilterFields() : $this
- Set the filter fields
- setFulltextFields() : $this
- Set the fulltext fields
- setSortFields() : $this
- Set/override the sortable fields
- setStoredFields() : BaseIndex
- Set/override the stored field list
- uploadConfig() : void
- Upload config for this index to the given store
- addAllFieldsByType() : void
- Add all database-backed text fields as fulltext searchable fields.
- addFulltextFieldsForClass() : void
- Add all fields of a given type to the index
- buildFactory() : QueryComponentFactory|mixed
- Build a factory to use in the SolrQuery building. {@link static::buildSolrQuery()}
- doRetry() : bool
- Check if the query should be retried with spellchecking Conditions are: It is not already a retry with spellchecking Spellchecking is enabled If spellchecking is enabled and nothing is found OR it should follow spellchecking none the less There is a spellcheck output
- initFromConfig() : void
- Generate the config from yml if possible
- spellcheckRetry() : SearchResult|mixed|ArrayData
- Retry the query with the first collated spellcheck found.
Properties
$boostedFields
Sets boosting at _index_ time or _query_ time. Depending on the usage of this trait [ 'FieldName' => 2, ]
protected
array<string|int, mixed>
$boostedFields
= []
$class
protected
array<string|int, mixed>
$class
= []
Classes to use
$client
protected
Client
$client
Query client
$clientQuery
protected
Query
$clientQuery
Query that will hit the client
$copyFields
protected
array<string|int, mixed>
$copyFields
= ['_text' => ['*']]
Fields to copy to the default fields
$defaultField
protected
string
$defaultField
= '_text'
Default search field
$facetFields
protected
array<string|int, mixed>
$facetFields
= []
Facet fields
$filterFields
protected
array<string|int, mixed>
$filterFields
= []
Filterable fields
$fulltextFields
protected
array<string|int, mixed>
$fulltextFields
= []
Fulltext fields
$queryFactory
{@link QueryComponentFactory}
protected
QueryComponentFactory
$queryFactory
Generator for all components
$queryTerms
protected
array<string|int, mixed>
$queryTerms
= []
The query terms as an array
$schemaFactory
{@link SchemaFactory}
protected
SchemaFactory
$schemaFactory
Schema factory for generating the schema
$sortFields
protected
array<string|int, mixed>
$sortFields
= []
Sortable fields
$storedFields
protected
array<string|int, mixed>
$storedFields
= []
Stored fields
$usedAllFields
usedAllFields is used to determine if the addAllFields method has been called This is to prevent a notice if there is no yml.
protected
bool
$usedAllFields
= false
$fieldTypes
Field types that can be added Used in init to call build methods from configuration yml
private
static mixed
$fieldTypes
= ['FulltextFields', 'SortFields', 'FilterFields', 'BoostedFields', 'CopyFields', 'DefaultField', 'FacetFields', 'StoredFields']
Tags
$retry
private
bool
$retry
= false
Signify if a retry should occur if nothing was found and there are suggestions to follow
Methods
__construct()
BaseIndex constructor.
public
__construct() : mixed
addAllDateFields()
Add all date-type fields to the given index
public
addAllDateFields() : mixed
Tags
addAllFulltextFields()
Add all text-type fields to the given index
public
addAllFulltextFields() : mixed
Tags
addBoostedField()
Add an abstract for the add Boosted Field to keep things consistent
public
abstract addBoostedField(string $field[, array<string|int, mixed>|int $options = [] ][, null|int $boost = null ]) : mixed
Parameters
- $field : string
- $options : array<string|int, mixed>|int = []
- $boost : null|int = null
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
Return values
$thisaddCopyField()
Add a copy field
public
addCopyField(string $field, array<string|int, mixed> $options) : $this
Parameters
- $field : string
-
Name of the copyfield
- $options : array<string|int, mixed>
-
Array of all fields that should be copied to this copyfield
Return values
$thisaddFacetField()
Add a facet field
public
addFacetField( $field, array<string|int, mixed> $options) : $this
Parameters
Return values
$thisaddFilterField()
Add a filterable field
public
addFilterField( $filterField) : $this
Parameters
Return values
$thisaddFulltextField()
Add a single Fulltext field
public
addFulltextField(string $fulltextField[, null|string $forceType = null ][, array<string|int, mixed> $options = [] ]) : $this
Parameters
- $fulltextField : string
- $forceType : null|string = null
- $options : array<string|int, mixed> = []
Return values
$thisaddSortField()
Add a field to sort on
public
addSortField( $sortField) : $this
Parameters
Return values
$thisaddStoredField()
Add a stored/fulltext field
public
addStoredField(string $field[, null|string $forceType = null ][, array<string|int, mixed> $extraOptions = [] ]) : BaseIndex
Parameters
- $field : string
- $forceType : null|string = null
- $extraOptions : array<string|int, mixed> = []
Return values
BaseIndexbuildSolrQuery()
From the given BaseQuery, generate a Solarium ClientQuery object
public
buildSolrQuery(BaseQuery $query) : Query
Parameters
- $query : BaseQuery
Return values
QuerydoSearch()
Default returns a SearchResult. It can return an ArrayData if FTS Compat is enabled
public
doSearch(BaseQuery $query) : SearchResult|ArrayData|mixed
Parameters
- $query : BaseQuery
Tags
Return values
SearchResult|ArrayData|mixedgetBoostedFields()
Get the boosted fields
public
getBoostedFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getClasses()
This trait requires classes to be set, so getClasses can be called.
public
abstract getClasses() : array<string|int, mixed>
Return values
array<string|int, mixed>getClient()
Get the client
public
getClient() : Client
Return values
ClientgetClientQuery()
Retrieve the Solarium client Query object for this index operation
public
getClientQuery() : Query
Return values
QuerygetConfig()
Build a full config for all given endpoints This is to add the current index to e.g. an index or select
public
getConfig(array<string|int, mixed> $endpoints) : array<string|int, mixed>
Parameters
- $endpoints : array<string|int, mixed>
Return values
array<string|int, mixed>getCopyFields()
Return the copy fields
public
getCopyFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getDefaultField()
Return the default field for this index
public
getDefaultField() : string
Return values
stringgetFacetFields()
Get the facet fields
public
getFacetFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getFieldsForIndexing()
Get all fields that are required for indexing in a unique way
public
getFieldsForIndexing() : array<string|int, mixed>
Return values
array<string|int, mixed>getFilterFields()
Get the filter fields
public
getFilterFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getFulltextFields()
Get the fulltext fields
public
getFulltextFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getIndexName()
Name of this index.
public
abstract getIndexName() : string
Return values
stringgetQueryFactory()
Get the QueryComponentFactory. {@link QueryComponentFactory}
public
getQueryFactory() : QueryComponentFactory
Return values
QueryComponentFactorygetQueryTerms()
Get the final, generated terms
public
getQueryTerms() : array<string|int, mixed>
Return values
array<string|int, mixed>getSortFields()
Get the sortable fields
public
getSortFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getStoredFields()
Get the stored field list
public
getStoredFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getSynonyms()
Add synonyms. Public to be extendable
public
getSynonyms([ConfigStore $store = null ][, bool $defaults = true ]) : string
Parameters
- $store : ConfigStore = null
-
Store to use to write synonyms
- $defaults : bool = true
-
Include UK to US synonyms
Return values
stringinit()
Required to initialise the fields.
public
init() : mixed
It's loaded in to the non-static properties for backward compatibility with FTS Also, it's a tad easier to use this way, loading the other way around would be very memory intensive, as updating the config for each item is not efficient
isRetry()
public
isRetry() : bool
Return values
boolsetBoostedFields()
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
$thissetClasses()
Set the classes
public
setClasses(array<string|int, mixed> $class) : $this
Parameters
- $class : array<string|int, mixed>
Return values
$thissetClient()
Set/override the client
public
setClient(Client $client) : $this
Parameters
- $client : Client
Return values
$thissetCopyFields()
Set the copy fields
public
setCopyFields(array<string|int, mixed> $copyField) : $this
Parameters
- $copyField : array<string|int, mixed>
Return values
$thissetDefaultField()
Set the default field for this index
public
setDefaultField(string $defaultField) : $this
Parameters
- $defaultField : string
Return values
$thissetFacetFields()
Set the facet fields
public
setFacetFields(array<string|int, mixed> $facetFields) : $this
Parameters
- $facetFields : array<string|int, mixed>
Return values
$thissetFilterFields()
Set the filter fields
public
setFilterFields(array<string|int, mixed> $filterFields) : $this
Parameters
- $filterFields : array<string|int, mixed>
Return values
$thissetFulltextFields()
Set the fulltext fields
public
setFulltextFields(array<string|int, mixed> $fulltextFields) : $this
Parameters
- $fulltextFields : array<string|int, mixed>
Return values
$thissetSortFields()
Set/override the sortable fields
public
setSortFields(array<string|int, mixed> $sortFields) : $this
Parameters
- $sortFields : array<string|int, mixed>
Return values
$thissetStoredFields()
Set/override the stored field list
public
setStoredFields(array<string|int, mixed> $storedFields) : BaseIndex
Parameters
- $storedFields : array<string|int, mixed>
Return values
BaseIndexuploadConfig()
Upload config for this index to the given store
public
uploadConfig(ConfigStore $store) : void
Parameters
- $store : ConfigStore
addAllFieldsByType()
Add all database-backed text fields as fulltext searchable fields.
protected
addAllFieldsByType([string $dbType = DBString::class ]) : void
For every class included in the index, examines those classes and all parent looking for "DBText" database fields (Varchar, Text, HTMLText, etc) and adds them all as fulltext searchable fields.
Note, there is no check on boosting etc. That needs to be done manually.
Parameters
- $dbType : string = DBString::class
Tags
addFulltextFieldsForClass()
Add all fields of a given type to the index
protected
addFulltextFieldsForClass(array<string|int, mixed> $fields[, string $dbType = DBString::class ]) : void
Parameters
- $fields : array<string|int, mixed>
-
The fields on the DataObject
- $dbType : string = DBString::class
-
Class type the reflection should extend
Tags
buildFactory()
Build a factory to use in the SolrQuery building. {@link static::buildSolrQuery()}
protected
buildFactory(BaseQuery $query, Query $clientQuery) : QueryComponentFactory|mixed
Parameters
- $query : BaseQuery
- $clientQuery : Query
Return values
QueryComponentFactory|mixeddoRetry()
Check if the query should be retried with spellchecking Conditions are: It is not already a retry with spellchecking Spellchecking is enabled If spellchecking is enabled and nothing is found OR it should follow spellchecking none the less There is a spellcheck output
protected
doRetry(BaseQuery $query, Result $result, SearchResult $searchResult) : bool
Parameters
- $query : BaseQuery
- $result : Result
- $searchResult : SearchResult
Return values
boolinitFromConfig()
Generate the config from yml if possible
protected
initFromConfig(array<string|int, mixed>|null $config) : void
Parameters
- $config : array<string|int, mixed>|null
spellcheckRetry()
Retry the query with the first collated spellcheck found.
protected
spellcheckRetry(BaseQuery $query, SearchResult $searchResult) : SearchResult|mixed|ArrayData
Parameters
- $query : BaseQuery
- $searchResult : SearchResult