mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
WIP Silverstripe 4 compatibility fixes
This commit is contained in:
parent
6fbb25abb1
commit
bbdf79ea2b
@ -2,5 +2,3 @@
|
|||||||
|
|
||||||
global $databaseConfig;
|
global $databaseConfig;
|
||||||
if (isset($databaseConfig['type'])) SearchUpdater::bind_manipulation_capture();
|
if (isset($databaseConfig['type'])) SearchUpdater::bind_manipulation_capture();
|
||||||
|
|
||||||
Deprecation::notification_version('1.0.0', 'fulltextsearch');
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
/**
|
/**
|
||||||
* Base class to manage active search indexes.
|
* Base class to manage active search indexes.
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\View\ViewableData;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DataObjectSchema;
|
||||||
|
use SilverStripe\Core\Object;
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
/**
|
/**
|
||||||
* SearchIndex is the base index class. Each connector will provide a subclass of this that
|
* SearchIndex is the base index class. Each connector will provide a subclass of this that
|
||||||
* provides search engine specific behavior.
|
* provides search engine specific behavior.
|
||||||
@ -130,7 +135,7 @@ abstract class SearchIndex extends ViewableData
|
|||||||
$type = null;
|
$type = null;
|
||||||
$fieldoptions = $options;
|
$fieldoptions = $options;
|
||||||
|
|
||||||
$fields = DataObject::database_fields($dataclass);
|
$fields = DataObject::getSchema()->databaseFields($class);
|
||||||
|
|
||||||
if (isset($fields[$field])) {
|
if (isset($fields[$field])) {
|
||||||
$type = $fields[$field];
|
$type = $fields[$field];
|
||||||
@ -209,7 +214,7 @@ abstract class SearchIndex extends ViewableData
|
|||||||
throw new Exception('Can\'t add class to Index after fields have already been added');
|
throw new Exception('Can\'t add class to Index after fields have already been added');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DataObject::has_own_table($class)) {
|
if (!DataObject::getSchema()->classHasTable($class)) {
|
||||||
throw new InvalidArgumentException('Can\'t add classes which don\'t have data tables (no $db or $has_one set on the class)');
|
throw new InvalidArgumentException('Can\'t add classes which don\'t have data tables (no $db or $has_one set on the class)');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +291,7 @@ abstract class SearchIndex extends ViewableData
|
|||||||
{
|
{
|
||||||
foreach ($this->getClasses() as $class => $options) {
|
foreach ($this->getClasses() as $class => $options) {
|
||||||
foreach (SearchIntrospection::hierarchy($class, $includeSubclasses, true) as $dataclass) {
|
foreach (SearchIntrospection::hierarchy($class, $includeSubclasses, true) as $dataclass) {
|
||||||
$fields = DataObject::database_fields($dataclass);
|
$fields = DataObject::getSchema()->databaseFields($class);
|
||||||
|
|
||||||
foreach ($fields as $field => $type) {
|
foreach ($fields as $field => $type) {
|
||||||
if (preg_match('/^(\w+)\(/', $type, $match)) {
|
if (preg_match('/^(\w+)\(/', $type, $match)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
/**
|
/**
|
||||||
* Some additional introspection tools that are used often by the fulltext search code
|
* Some additional introspection tools that are used often by the fulltext search code
|
||||||
*/
|
*/
|
||||||
@ -45,14 +47,14 @@ class SearchIntrospection
|
|||||||
if ($idx !== false) {
|
if ($idx !== false) {
|
||||||
array_splice($classes, 0, $idx+1);
|
array_splice($classes, 0, $idx+1);
|
||||||
}
|
}
|
||||||
|
//@todo find another way to determine if a dataobject does not have a table
|
||||||
if ($dataOnly) {
|
// if ($dataOnly) {
|
||||||
foreach ($classes as $i => $class) {
|
// foreach ($classes as $i => $class) {
|
||||||
if (!DataObject::has_own_table($class)) {
|
// if (!DataObject::has_own_table($class)) {
|
||||||
unset($classes[$i]);
|
// unset($classes[$i]);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
self::$hierarchy[$key] = $classes;
|
self::$hierarchy[$key] = $classes;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
/**
|
/**
|
||||||
* A Search Variant handles decorators and other situations where the items to reindex or search through are modified
|
* A Search Variant handles decorators and other situations where the items to reindex or search through are modified
|
||||||
* from the default state - for instance, dealing with Versioned or Subsite
|
* from the default state - for instance, dealing with Versioned or Subsite
|
||||||
|
@ -4,6 +4,11 @@ use Monolog\Formatter\LineFormatter;
|
|||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use SilverStripe\Dev\BuildTask;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
|
use SilverStripe\Core\Object;
|
||||||
|
|
||||||
class Solr
|
class Solr
|
||||||
{
|
{
|
||||||
@ -179,7 +184,7 @@ class Solr_BuildTask extends BuildTask
|
|||||||
*/
|
*/
|
||||||
public function getLogger()
|
public function getLogger()
|
||||||
{
|
{
|
||||||
return $this->logger;
|
return Injector::inst()->get('Logger');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,7 +202,7 @@ class Solr_BuildTask extends BuildTask
|
|||||||
*/
|
*/
|
||||||
protected function getLoggerFactory()
|
protected function getLoggerFactory()
|
||||||
{
|
{
|
||||||
return Injector::inst()->get('SearchLogFactory');
|
// return Injector::inst()->get('SearchLogFactory');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,8 +217,9 @@ class Solr_BuildTask extends BuildTask
|
|||||||
|
|
||||||
// Set new logger
|
// Set new logger
|
||||||
$logger = $this
|
$logger = $this
|
||||||
->getLoggerFactory()
|
->getLoggerFactory();
|
||||||
->getOutputLogger($name, $verbose);
|
//@todo: Cannot instantiate interface SearchLogFactory
|
||||||
|
// ->getOutputLogger($name, $verbose);
|
||||||
$this->setLogger($logger);
|
$this->setLogger($logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,6 +235,7 @@ class Solr_Configure extends Solr_BuildTask
|
|||||||
|
|
||||||
// Find the IndexStore handler, which will handle uploading config files to Solr
|
// Find the IndexStore handler, which will handle uploading config files to Solr
|
||||||
$store = $this->getSolrConfigStore();
|
$store = $this->getSolrConfigStore();
|
||||||
|
|
||||||
$indexes = Solr::get_indexes();
|
$indexes = Solr::get_indexes();
|
||||||
foreach ($indexes as $instance) {
|
foreach ($indexes as $instance) {
|
||||||
try {
|
try {
|
||||||
@ -251,23 +258,23 @@ class Solr_Configure extends Solr_BuildTask
|
|||||||
protected function updateIndex($instance, $store)
|
protected function updateIndex($instance, $store)
|
||||||
{
|
{
|
||||||
$index = $instance->getIndexName();
|
$index = $instance->getIndexName();
|
||||||
$this->getLogger()->info("Configuring $index.");
|
$this->getLogger()->addInfo("Configuring $index.");
|
||||||
|
|
||||||
// Upload the config files for this index
|
// Upload the config files for this index
|
||||||
$this->getLogger()->info("Uploading configuration ...");
|
$this->getLogger()->addInfo("Uploading configuration ...");
|
||||||
$instance->uploadConfig($store);
|
$instance->uploadConfig($store);
|
||||||
|
|
||||||
// Then tell Solr to use those config files
|
// Then tell Solr to use those config files
|
||||||
$service = Solr::service();
|
$service = Solr::service();
|
||||||
if ($service->coreIsActive($index)) {
|
if ($service->coreIsActive($index)) {
|
||||||
$this->getLogger()->info("Reloading core ...");
|
$this->getLogger()->addInfo("Reloading core ...");
|
||||||
$service->coreReload($index);
|
$service->coreReload($index);
|
||||||
} else {
|
} else {
|
||||||
$this->getLogger()->info("Creating core ...");
|
$this->getLogger()->addInfo("Creating core ...");
|
||||||
$service->coreCreate($index, $store->instanceDir($index));
|
$service->coreCreate($index, $store->instanceDir($index));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getLogger()->info("Done");
|
$this->getLogger()->addInfo("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,7 +287,7 @@ class Solr_Configure extends Solr_BuildTask
|
|||||||
$options = Solr::solr_options();
|
$options = Solr::solr_options();
|
||||||
|
|
||||||
if (!isset($options['indexstore']) || !($indexstore = $options['indexstore'])) {
|
if (!isset($options['indexstore']) || !($indexstore = $options['indexstore'])) {
|
||||||
user_error('No index configuration for Solr provided', E_USER_ERROR);
|
throw new Exception('No index configuration for Solr provided', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the IndexStore handler, which will handle uploading config files to Solr
|
// Find the IndexStore handler, which will handle uploading config files to Solr
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Solr::include_client_api();
|
Solr::include_client_api();
|
||||||
|
|
||||||
|
use SilverStripe\Dev\BuildTask;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
abstract class SolrIndex extends SearchIndex
|
abstract class SolrIndex extends SearchIndex
|
||||||
{
|
{
|
||||||
public static $fulltextTypeMap = array(
|
public static $fulltextTypeMap = array(
|
||||||
|
Loading…
Reference in New Issue
Block a user