mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
Merge branch 'compat/4' into compat4/btasker
This commit is contained in:
commit
db096ebf7d
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
namespace SilverStripe\FullTextSearch\Search\Indexes;
|
||||
|
||||
use SilverStripe\View\ViewableData;
|
||||
use SilverStripe\ORM\DataObject;
|
@ -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
|
@ -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
|
@ -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;
|
||||
}
|
||||
}
|
34
code/search/queries/SearchQuery_Range.php
Normal file
34
code/search/queries/SearchQuery_Range.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 */
|
||||
}
|
||||
}
|
66
code/search/updaters/SearchUpdater_ObjectHandler.php
Normal file
66
code/search/updaters/SearchUpdater_ObjectHandler.php
Normal 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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
namespace SilverStripe\FullTextSearch\Search\Variants;
|
||||
|
||||
class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant
|
||||
{
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
namespace SilverStripe\FullTextSearch\Search\Variants;
|
||||
class SearchVariantSubsites extends SearchVariant
|
||||
{
|
||||
public function appliesToEnvironment()
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace SilverStripe\FullTextSearch\Search;
|
||||
namespace SilverStripe\FullTextSearch\Search\Variants;
|
||||
|
||||
class SearchVariantVersioned extends SearchVariant
|
||||
{
|
||||
public function appliesToEnvironment()
|
38
code/search/variants/SearchVariant_Caller.php
Normal file
38
code/search/variants/SearchVariant_Caller.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user