for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SilverStripe\Elastica;
/**
* Defines and refreshes the elastic search index.
*/
class SearchIndexTask extends \BuildTask {
protected $title = 'Elastic Search Reindex';
protected $description = 'Searches the elastic search index';
* @var ElasticaService
private $service;
public function __construct(ElasticaService $service) {
$this->service = $service;
}
public function run($request) {
$message = ElasticaUtil::getPrinter();
$locales = array();
if ($this->locale == null) {
if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) {
$this->locale = \Translatable::get_current_locale();
locale
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
} else {
foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) {
array_push($locales, $code);
// search SiteTree showing highlights
$query = $request->getVar('q');
$es = new \ElasticSearcher();
$es->setStart(0);
$es->setPageLength(20);
$es->addFilter('IsInSiteTree', true);
$results = $es->search($query);
foreach ($results as $result) {
$title = '['.$result->ClassName.', '.$result->ID.'] ';
$title .= $result->Title;
$message($title);
if ($result->SearchHighlightsByField->Content) {
foreach ($result->SearchHighlightsByField->Content as $highlight) {
$message("- ".$highlight->Snippet);
echo "\n\n";
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: