break out search components with multiple classes into individual files and change namespaces

This commit is contained in:
elliot sawyer 2017-04-21 13:26:24 +12:00
parent 2c653daa9d
commit 13bef6eb0d
14 changed files with 174 additions and 147 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Indexes;
use SilverStripe\View\ViewableData;
use SilverStripe\ORM\DataObject;

View File

@ -1,8 +1,8 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Indexes;
use SilverStripe\FullTextSearch\Search\SearchIndex;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex;
/**
* A search index that does nothing. Useful for testing

View File

@ -1,8 +1,8 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Indexes;
use SilverStripe\FullTextSearch\Search\SearchIndex;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex;
/**
* A search index that just records actions. Useful for testing

View File

@ -1,5 +1,5 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Indexes;
/**
* Represents a search query
*
@ -121,33 +121,4 @@ class SearchQuery extends ViewableData
}
}
/**
* Create one of these and pass as one of the values in filter or exclude to filter or exclude by a (possibly
* open ended) range
*/
class SearchQuery_Range
{
public $start = null;
public $end = null;
public function __construct($start = null, $end = null)
{
$this->start = $start;
$this->end = $end;
}
public function start($start)
{
$this->start = $start;
}
public function end($end)
{
$this->end = $end;
}
public function isfiltered()
{
return $this->start !== null || $this->end !== null;
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace SilverStripe\FullTextSearch\Search\Queries;
/**
* Create one of these and pass as one of the values in filter or exclude to filter or exclude by a (possibly
* open ended) range
*/
class SearchQuery_Range
{
public $start = null;
public $end = null;
public function __construct($start = null, $end = null)
{
$this->start = $start;
$this->end = $end;
}
public function start($start)
{
$this->start = $start;
}
public function end($end)
{
$this->end = $end;
}
public function isfiltered()
{
return $this->start !== null || $this->end !== null;
}
}

View File

@ -1,5 +1,5 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Updaters;
/**
* This class is responsible for capturing changes to DataObjects and triggering index updates of the resulting dirty index
* items.
@ -13,11 +13,6 @@ namespace SilverStripe\FullTextSearch\Search;
* TODO: The way we bind in is awful hacky.
*/
use SilverStripe\Core\Object;
use SilverStripe\Control\RequestFilter;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\ORM\DataModel;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\ORM\DataExtension;
class SearchUpdater extends Object
@ -212,78 +207,5 @@ class SearchUpdater extends Object
}
}
class SearchUpdater_BindManipulationCaptureFilter implements RequestFilter
{
public function preRequest(HTTPRequest $request, Session $session, DataModel $model)
{
SearchUpdater::bind_manipulation_capture();
}
public function postRequest(HTTPRequest $request, HTTPResponse $response, DataModel $model)
{
/* NOP */
}
}
/**
* Delete operations do not use database manipulations.
*
* If a delete has been requested, force a write on objects that should be
* indexed. This causes the object to be marked for deletion from the index.
*/
class SearchUpdater_ObjectHandler extends DataExtension
{
public function onAfterDelete()
{
// Calling delete() on empty objects does nothing
if (!$this->owner->ID) {
return;
}
// Force SearchUpdater to mark this record as dirty
$manipulation = array(
$this->owner->ClassName => array(
'fields' => array(),
'id' => $this->owner->ID,
'command' => 'update'
)
);
$this->owner->extend('augmentWrite', $manipulation);
SearchUpdater::handle_manipulation($manipulation);
}
/**
* Forces this object to trigger a re-index in the current state
*/
public function triggerReindex()
{
if (!$this->owner->ID) {
return;
}
$id = $this->owner->ID;
$class = $this->owner->ClassName;
$state = SearchVariant::current_state($class);
$base = ClassInfo::baseDataClass($class);
$key = "$id:$base:".serialize($state);
$statefulids = array(array(
'id' => $id,
'state' => $state
));
$writes = array(
$key => array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'fields' => array()
)
);
SearchUpdater::process_writes($writes);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace SilverStripe\FullTextSearch\Search\Updaters;
use SilverStripe\Control\RequestFilter;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\ORM\DataModel;
use SilverStripe\Control\HTTPResponse;
class SearchUpdater_BindManipulationCaptureFilter implements RequestFilter
{
public function preRequest(HTTPRequest $request, Session $session, DataModel $model)
{
SearchUpdater::bind_manipulation_capture();
}
public function postRequest(HTTPRequest $request, HTTPResponse $response, DataModel $model)
{
/* NOP */
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace SilverStripe\FullTextSearch\Search\Updaters;
use SilverStripe\ORM\DataExtension;
/**
* Delete operations do not use database manipulations.
*
* If a delete has been requested, force a write on objects that should be
* indexed. This causes the object to be marked for deletion from the index.
*/
class SearchUpdater_ObjectHandler extends DataExtension
{
public function onAfterDelete()
{
// Calling delete() on empty objects does nothing
if (!$this->owner->ID) {
return;
}
// Force SearchUpdater to mark this record as dirty
$manipulation = array(
$this->owner->ClassName => array(
'fields' => array(),
'id' => $this->owner->ID,
'command' => 'update'
)
);
$this->owner->extend('augmentWrite', $manipulation);
SearchUpdater::handle_manipulation($manipulation);
}
/**
* Forces this object to trigger a re-index in the current state
*/
public function triggerReindex()
{
if (!$this->owner->ID) {
return;
}
$id = $this->owner->ID;
$class = $this->owner->ClassName;
$state = SearchVariant::current_state($class);
$base = ClassInfo::baseDataClass($class);
$key = "$id:$base:".serialize($state);
$statefulids = array(array(
'id' => $id,
'state' => $state
));
$writes = array(
$key => array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'fields' => array()
)
);
SearchUpdater::process_writes($writes);
}
}

View File

@ -1,5 +1,5 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Variants;
use SilverStripe\Core\ClassInfo;
/**
* A Search Variant handles decorators and other situations where the items to reindex or search through are modified
@ -253,31 +253,3 @@ abstract class SearchVariant
}
}
/**
* Internal utility class used to hold the state of the SearchVariant::with call
*/
class SearchVariant_Caller
{
protected $variants = null;
public function __construct($variants)
{
$this->variants = $variants;
}
public function call($method, &$a1=null, &$a2=null, &$a3=null, &$a4=null, &$a5=null, &$a6=null, &$a7=null)
{
$values = array();
foreach ($this->variants as $variant) {
if (method_exists($variant, $method)) {
$value = $variant->$method($a1, $a2, $a3, $a4, $a5, $a6, $a7);
if ($value !== null) {
$values[] = $value;
}
}
}
return $values;
}
}

View File

@ -1,5 +1,5 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Variants;
class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant
{

View File

@ -1,5 +1,5 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Variants;
class SearchVariantSubsites extends SearchVariant
{
public function appliesToEnvironment()

View File

@ -1,5 +1,6 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
namespace SilverStripe\FullTextSearch\Search\Variants;
class SearchVariantVersioned extends SearchVariant
{
public function appliesToEnvironment()

View File

@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: elliot
* Date: 21/04/17
* Time: 1:13 PM
*/
namespace SilverStripe\FullTextSearch\Search\Variants;
/**
* Internal utility class used to hold the state of the SearchVariant::with call
*/
class SearchVariant_Caller
{
protected $variants = null;
public function __construct($variants)
{
$this->variants = $variants;
}
public function call($method, &$a1=null, &$a2=null, &$a3=null, &$a4=null, &$a5=null, &$a6=null, &$a7=null)
{
$values = array();
foreach ($this->variants as $variant) {
if (method_exists($variant, $method)) {
$value = $variant->$method($a1, $a2, $a3, $a4, $a5, $a6, $a7);
if ($value !== null) {
$values[] = $value;
}
}
}
return $values;
}
}

View File

@ -3,7 +3,7 @@ namespace SilverStripe\FullTextSearch\Solr;
Solr::include_client_api();
use SilverStripe\Control\Director;
use SilverStripe\FulltextSearch\Search\SearchIndex;
use SilverStripe\FulltextSearch\Search\Indexes\SearchIndex;
abstract class SolrIndex extends SearchIndex
{