SS 4.0 - Upgrade search variants

This commit is contained in:
Brett Tasker 2017-04-26 23:16:32 +12:00
parent 022575fadb
commit 59c3ad2ded
4 changed files with 31 additions and 7 deletions

View File

@ -2,7 +2,11 @@
namespace SilverStripe\FullTextSearch\Search\Variants; namespace SilverStripe\FullTextSearch\Search\Variants;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Utils\CombinationsArrayIterator;
use ReflectionClass;
/** /**
* 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
@ -79,7 +83,7 @@ abstract class SearchVariant
{ {
if (!$class) { if (!$class) {
if (self::$variants === null) { if (self::$variants === null) {
$classes = ClassInfo::subclassesFor('SearchVariant'); $classes = ClassInfo::subclassesFor(static::class);
$concrete = array(); $concrete = array();
foreach ($classes as $variantclass) { foreach ($classes as $variantclass) {

View File

@ -2,6 +2,11 @@
namespace SilverStripe\FullTextSearch\Search\Variants; namespace SilverStripe\FullTextSearch\Search\Variants;
use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\FullTextSearch\Search\SearchIntrospection;
if (!class_exists('Subsite') || !class_exists('SubsitePolyhome')) {
return;
}
class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant
{ {
@ -51,7 +56,7 @@ class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant
'name' => '_subsite', 'name' => '_subsite',
'field' => '_subsite', 'field' => '_subsite',
'fullfield' => '_subsite', 'fullfield' => '_subsite',
'base' => ClassInfo::baseDataClass($class), 'base' => DataObject::getSchema()->baseDataClass($class),
'origin' => $class, 'origin' => $class,
'type' => 'Int', 'type' => 'Int',
'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState')) 'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))

View File

@ -3,6 +3,14 @@
namespace SilverStripe\FullTextSearch\Search\Variants; namespace SilverStripe\FullTextSearch\Search\Variants;
use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\FullTextSearch\Search\SearchIntrospection;
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;
if (!class_exists('Subsite')) {
return;
}
class SearchVariantSubsites extends SearchVariant class SearchVariantSubsites extends SearchVariant
{ {
@ -57,7 +65,7 @@ class SearchVariantSubsites extends SearchVariant
'name' => '_subsite', 'name' => '_subsite',
'field' => '_subsite', 'field' => '_subsite',
'fullfield' => '_subsite', 'fullfield' => '_subsite',
'base' => ClassInfo::baseDataClass($class), 'base' => DataObject::getSchema()->baseDataClass($class),
'origin' => $class, 'origin' => $class,
'type' => 'Int', 'type' => 'Int',
'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState')) 'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))

View File

@ -1,6 +1,13 @@
<?php <?php
namespace SilverStripe\FullTextSearch\Search\Variants; namespace SilverStripe\FullTextSearch\Search\Variants;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Search\SearchIntrospection;
use SilverStripe\Versioned\Versioned;
use SilverStripe\FullTextSearch\Search\Queries\SearchQuery;
class SearchVariantVersioned extends SearchVariant class SearchVariantVersioned extends SearchVariant
{ {
public function appliesTo($class, $includeSubclasses) public function appliesTo($class, $includeSubclasses)
@ -10,7 +17,7 @@ class SearchVariantVersioned extends SearchVariant
public function currentState() public function currentState()
{ {
return Versioned::current_stage(); return Versioned::get_stage();
} }
public function reindexStates() public function reindexStates()
{ {
@ -18,7 +25,7 @@ class SearchVariantVersioned extends SearchVariant
} }
public function activateState($state) public function activateState($state)
{ {
Versioned::reading_stage($state); Versioned::set_stage($state);
} }
public function alterDefinition($class, $index) public function alterDefinition($class, $index)
@ -29,7 +36,7 @@ class SearchVariantVersioned extends SearchVariant
'name' => '_versionedstage', 'name' => '_versionedstage',
'field' => '_versionedstage', 'field' => '_versionedstage',
'fullfield' => '_versionedstage', 'fullfield' => '_versionedstage',
'base' => ClassInfo::baseDataClass($class), 'base' => DataObject::getSchema()->baseDataClass($class),
'origin' => $class, 'origin' => $class,
'type' => 'String', 'type' => 'String',
'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState')) 'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))
@ -38,7 +45,7 @@ class SearchVariantVersioned extends SearchVariant
public function alterQuery($query, $index) public function alterQuery($query, $index)
{ {
$stage = Versioned::current_stage(); $stage = $this->currentState();
$query->filter('_versionedstage', array($stage, SearchQuery::$missing)); $query->filter('_versionedstage', array($stage, SearchQuery::$missing));
} }