SilverStripe Search

SolrIndexTask extends BuildTask
in package
Uses LoggerTrait, SolrIndexTrait

Class SolrIndexTask

Tags
description

Index items to Solr through a tasks

Table of Contents

Properties

$currentStates  : array<string|int, mixed>
Store the current states for all instances of SiteState
$batchLength  : int
Default batch length
$cores  : int
$debug  : bool
Debug mode enabled, default false
$description  : string
What do I do?
$index  : BaseIndex
$logger  : LoggerInterface
The logger to use
$service  : SolrCoreService
Singleton of {@link SolrCoreService}
$title  : string
My name
$segment  : string
URLSegment of this task

Methods

__construct()  : mixed
SolrIndexTask constructor. Sets up the document factory
clearIndex()  : mixed
Clear the given index if a full re-index is needed
getBatchLength()  : int
Get the length of a single batch
getCores()  : int
Get the amount of CPU Cores configured
getIndex()  : BaseIndex
Get the Index class.
getLogger()  : LoggerInterface
Get the logger
isDebug()  : bool
Is this Index in debug mode
run()  : int|bool
Implement this method in the task subclass to execute via the TaskRunner
setBatchLength()  : void
Set the length of a single batch
setCores()  : void
Set the amount of CPU Cores to use
setDebug()  : self
Set the debug mode
setIndex()  : void
Set the index class
setLogger()  : void
Set the logger if needed
setService()  : self
Set the {@link SolrCoreService}
getClasses()  : bool|array<string|int, mixed>
get the classes to run for this task execution
indexClassForIndex()  : int|bool
Index the classes for a specific index
taskSetup()  : array<string|int, mixed>
Set up the requirements for this task
doReindex()  : mixed
Reindex the given group, for each state
getGroupSettings()  : array<string|int, mixed>
Check the amount of groups and the total against the isGroup check.
hasPCNTL()  : bool
Check if PCNTL is available and/or useable.
indexClass()  : int|bool
Index a single class for a given index. {@link static::indexClassForIndex()}
indexStateClass()  : void
Index a group of a class for a specific state and index
logException()  : void
Log an exception if it happens. Most are catched, these logs are for the developers to identify problems and fix them.
runChild()  : void
Ren a single child index operation
runForkedChild()  : void
Create a fork and run the child
spawnChildren()  : int
For each core, spawn a child process that will handle a separate group.
updateIndex()  : void
Execute the update on the client

Properties

$currentStates

Store the current states for all instances of SiteState

public array<string|int, mixed> $currentStates

$batchLength

Default batch length

protected int $batchLength = 500

$debug

Debug mode enabled, default false

protected bool $debug = false

$description

What do I do?

protected string $description = 'Add or update documents to an existing Solr core.'

$logger

The logger to use

protected LoggerInterface $logger

$title

My name

protected string $title = 'Solr Index update'

$segment

URLSegment of this task

private static string $segment = 'SolrIndexTask'

Methods

__construct()

SolrIndexTask constructor. Sets up the document factory

public __construct() : mixed
Tags
throws
ReflectionException

clearIndex()

Clear the given index if a full re-index is needed

public clearIndex(array<string|int, mixed> $vars) : mixed
Parameters
$vars : array<string|int, mixed>

URL GET Parameters

Tags
throws
Exception

getBatchLength()

Get the length of a single batch

public getBatchLength() : int
Return values
int

getCores()

Get the amount of CPU Cores configured

public getCores() : int
Return values
int

getLogger()

Get the logger

public getLogger() : LoggerInterface
Return values
LoggerInterface

isDebug()

Is this Index in debug mode

public isDebug() : bool
Return values
bool

run()

Implement this method in the task subclass to execute via the TaskRunner

public run(HTTPRequest $request) : int|bool
Parameters
$request : HTTPRequest

Current request

Tags
throws
Exception
throws
HTTPException
Return values
int|bool

setBatchLength()

Set the length of a single batch

public setBatchLength(int $batchLength) : void
Parameters
$batchLength : int

setCores()

Set the amount of CPU Cores to use

public setCores(int $cores) : void
Parameters
$cores : int

setDebug()

Set the debug mode

public setDebug(bool $debug[, bool $force = false ]) : self
Parameters
$debug : bool

Set the task in debug mode

$force : bool = false

Force a task in debug mode, despite e.g. being Live and not CLI

Return values
self

setLogger()

Set the logger if needed

public setLogger(LoggerInterface $logger) : void
Parameters
$logger : LoggerInterface

getClasses()

get the classes to run for this task execution

protected getClasses(array<string|int, mixed> $vars, array<string|int, mixed> $classes) : bool|array<string|int, mixed>
Parameters
$vars : array<string|int, mixed>

URL GET Parameters

$classes : array<string|int, mixed>

Classes to index

Return values
bool|array<string|int, mixed>

indexClassForIndex()

Index the classes for a specific index

protected indexClassForIndex(array<string|int, mixed> $classes, bool $isGroup, int $group) : int|bool
Parameters
$classes : array<string|int, mixed>

Classes that need indexing

$isGroup : bool

Indexing a specific group?

$group : int

Group to index

Tags
throws
Exception
throws
HTTPException
Return values
int|bool

taskSetup()

Set up the requirements for this task

protected taskSetup(HTTPRequest $request) : array<string|int, mixed>
Parameters
$request : HTTPRequest

Current request

Return values
array<string|int, mixed>

doReindex()

Reindex the given group, for each state

private doReindex(int $group, string $class[, bool|int $pid = false ]) : mixed
Parameters
$group : int

Group to index

$class : string

Class to index

$pid : bool|int = false

Are we a child process or not

Tags
throws
Exception

getGroupSettings()

Check the amount of groups and the total against the isGroup check.

private getGroupSettings(bool $isGroup, string $class, int $group) : array<string|int, mixed>
Parameters
$isGroup : bool

Is it a specific group

$class : string

Class to check

$group : int

Current group to index

Return values
array<string|int, mixed>

hasPCNTL()

Check if PCNTL is available and/or useable.

private hasPCNTL() : bool

The unittest param is from phpunit.xml.dist, meant to bypass the exit(0) call The pcntl parameter check is for unit tests, but PHPUnit does not support PCNTL (yet)

Return values
bool

indexClass()

Index a single class for a given index. {@link static::indexClassForIndex()}

private indexClass(bool $isGroup, string $class, int $group) : int|bool
Parameters
$isGroup : bool

Is a specific group indexed

$class : string

Class to index

$group : int

Group to index

Tags
throws
HTTPException
throws
ValidationException
Return values
int|bool

indexStateClass()

Index a group of a class for a specific state and index

private indexStateClass(string $group, string $class) : void
Parameters
$group : string

Group to index

$class : string

Class to index

Tags
throws
Exception

logException()

Log an exception if it happens. Most are catched, these logs are for the developers to identify problems and fix them.

private logException(string $index, int $group, Exception $exception) : void
Parameters
$index : string

Index that is currently running

$group : int

Group currently attempted to index

$exception : Exception

Exception that's been thrown

Tags
codeCoverageIgnore

This is actually tested through reflection

throws
HTTPException
throws
ValidationException

runChild()

Ren a single child index operation

private runChild(string $class, int $pid, int $start) : void
Parameters
$class : string

Class to index

$pid : int

PID of the child

$start : int

Position to start

Tags
codeCoverageIgnore

Can't be tested because PCNTL is not available

throws
HTTPException
throws
ValidationException
throws
Exception

runForkedChild()

Create a fork and run the child

private runForkedChild(string $class, array<string|int, mixed> &$pids, int $start) : void
Parameters
$class : string

Class to index

$pids : array<string|int, mixed>

Array of all the child Process IDs

$start : int

Start point for the objects

Tags
codeCoverageIgnore

Can't be tested because PCNTL is not available

throws
HTTPException
throws
ValidationException

spawnChildren()

For each core, spawn a child process that will handle a separate group.

private spawnChildren(string $class, int $group, int $groups) : int

This speeds up indexing through CLI massively.

Parameters
$class : string

Class to index

$group : int

Group to index

$groups : int

Total amount of groups

Tags
codeCoverageIgnore

Can't be tested because PCNTL is not available

throws
Exception
throws
HTTPException
Return values
int

Last group indexed

updateIndex()

Execute the update on the client

private updateIndex(SS_List $items) : void
Parameters
$items : SS_List

Items to index

Tags
throws
Exception

        
On this page

Search results