From 13bef6eb0d7d02d5558520171c5d32ee79b2c282 Mon Sep 17 00:00:00 2001 From: elliot sawyer Date: Fri, 21 Apr 2017 13:26:24 +1200 Subject: [PATCH] break out search components with multiple classes into individual files and change namespaces --- code/search/{ => indexes}/SearchIndex.php | 2 +- .../search/{ => indexes}/SearchIndex_Null.php | 4 +- .../{ => indexes}/SearchIndex_Recording.php | 4 +- code/search/{ => queries}/SearchQuery.php | 31 +------ code/search/queries/SearchQuery_Range.php | 34 ++++++++ code/search/{ => updaters}/SearchUpdater.php | 80 +------------------ ...hUpdater_BindManipulationCaptureFilter.php | 23 ++++++ .../updaters/SearchUpdater_ObjectHandler.php | 66 +++++++++++++++ code/search/{ => variants}/SearchVariant.php | 30 +------ .../SearchVariantSiteTreeSubsitesPolyhome.php | 2 +- .../{ => variants}/SearchVariantSubsites.php | 2 +- .../{ => variants}/SearchVariantVersioned.php | 3 +- code/search/variants/SearchVariant_Caller.php | 38 +++++++++ code/solr/SolrIndex.php | 2 +- 14 files changed, 174 insertions(+), 147 deletions(-) rename code/search/{ => indexes}/SearchIndex.php (99%) rename code/search/{ => indexes}/SearchIndex_Null.php (70%) rename code/search/{ => indexes}/SearchIndex_Recording.php (93%) rename code/search/{ => queries}/SearchQuery.php (85%) create mode 100644 code/search/queries/SearchQuery_Range.php rename code/search/{ => updaters}/SearchUpdater.php (77%) create mode 100644 code/search/updaters/SearchUpdater_BindManipulationCaptureFilter.php create mode 100644 code/search/updaters/SearchUpdater_ObjectHandler.php rename code/search/{ => variants}/SearchVariant.php (91%) rename code/search/{ => variants}/SearchVariantSiteTreeSubsitesPolyhome.php (98%) rename code/search/{ => variants}/SearchVariantSubsites.php (98%) rename code/search/{ => variants}/SearchVariantVersioned.php (97%) create mode 100644 code/search/variants/SearchVariant_Caller.php diff --git a/code/search/SearchIndex.php b/code/search/indexes/SearchIndex.php similarity index 99% rename from code/search/SearchIndex.php rename to code/search/indexes/SearchIndex.php index f4dc86a..04d3136 100644 --- a/code/search/SearchIndex.php +++ b/code/search/indexes/SearchIndex.php @@ -1,6 +1,6 @@ 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; - } -} diff --git a/code/search/queries/SearchQuery_Range.php b/code/search/queries/SearchQuery_Range.php new file mode 100644 index 0000000..33b35e5 --- /dev/null +++ b/code/search/queries/SearchQuery_Range.php @@ -0,0 +1,34 @@ +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; + } +} \ No newline at end of file diff --git a/code/search/SearchUpdater.php b/code/search/updaters/SearchUpdater.php similarity index 77% rename from code/search/SearchUpdater.php rename to code/search/updaters/SearchUpdater.php index b1fa58d..90a1500 100644 --- a/code/search/SearchUpdater.php +++ b/code/search/updaters/SearchUpdater.php @@ -1,5 +1,5 @@ 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); - } -} diff --git a/code/search/updaters/SearchUpdater_BindManipulationCaptureFilter.php b/code/search/updaters/SearchUpdater_BindManipulationCaptureFilter.php new file mode 100644 index 0000000..e6b4e05 --- /dev/null +++ b/code/search/updaters/SearchUpdater_BindManipulationCaptureFilter.php @@ -0,0 +1,23 @@ +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); + } +} \ No newline at end of file diff --git a/code/search/SearchVariant.php b/code/search/variants/SearchVariant.php similarity index 91% rename from code/search/SearchVariant.php rename to code/search/variants/SearchVariant.php index f8a68ad..57f6479 100644 --- a/code/search/SearchVariant.php +++ b/code/search/variants/SearchVariant.php @@ -1,5 +1,5 @@ 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; - } -} diff --git a/code/search/SearchVariantSiteTreeSubsitesPolyhome.php b/code/search/variants/SearchVariantSiteTreeSubsitesPolyhome.php similarity index 98% rename from code/search/SearchVariantSiteTreeSubsitesPolyhome.php rename to code/search/variants/SearchVariantSiteTreeSubsitesPolyhome.php index 100788a..5101dd1 100644 --- a/code/search/SearchVariantSiteTreeSubsitesPolyhome.php +++ b/code/search/variants/SearchVariantSiteTreeSubsitesPolyhome.php @@ -1,5 +1,5 @@ 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; + } +} \ No newline at end of file diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index 2a7f655..76842a2 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -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 {