Created
October 22, 2018 04:16
-
-
Save nyeholt/e3f4b1745b9af2cc3265df0e548d2b7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git vendor/heyday/silverstripe-elastica/src/ResultList.php vendor/heyday/silverstripe-elastica/src/ResultList.php | |
index a178198..13b9f65 100644 | |
--- vendor/heyday/silverstripe-elastica/src/ResultList.php | |
+++ vendor/heyday/silverstripe-elastica/src/ResultList.php | |
@@ -41,11 +41,19 @@ class ResultList extends ViewableData implements SS_List | |
'_type' | |
)); | |
+ $query->setSource([ | |
+ 'ID', | |
+ 'ClassName' | |
+ ]); | |
+ | |
//If we are in live reading mode, only return published documents | |
if (Versioned::get_reading_mode() == Versioned::DEFAULT_MODE) { | |
- $publishedFilter = new Query\BoolQuery(); | |
- $publishedFilter->addMust(new Query\Term([Searchable::$published_field => 'true'])); | |
- $query->setPostFilter($publishedFilter); | |
+ $publishedFilter = $query->hasParam('post_filter') ? $query->getParam('post_filter') : null; | |
+ if (!$publishedFilter) { | |
+ $publishedFilter = new Query\BoolQuery(); | |
+ } else if (!($publishedFilter instanceof Query\BoolQuery)) { | |
+ throw new \RuntimeException("Please use a bool query for your post_filter"); | |
+ } | |
} | |
$this->index = $index; | |
@@ -108,6 +116,8 @@ class ResultList extends ViewableData implements SS_List | |
} catch (\Exception $e) { | |
if ($this->logger) { | |
$this->logger->critical($e->getMessage()); | |
+ } else { | |
+ throw $e; | |
} | |
} | |
} | |
@@ -171,13 +181,19 @@ class ResultList extends ViewableData implements SS_List | |
if (is_array($found) || $found instanceof \ArrayAccess) { | |
foreach ($found as $item) { | |
- $type = $item->getType(); | |
- | |
+ $data = $item->getData(); | |
+ | |
+ // note(Marcus) 2018-01-24: | |
+ // Swapped to using the ClassName and ID fields introduced elsewhere | |
+ // due to _type being deprecated | |
+ // https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-type-field.html | |
+ $type = isset($data['ClassName']) ? $data['ClassName'] : $item->getType(); | |
+ $id = isset($data['ID']) ? $data['ID'] : $item->getId(); | |
if (!array_key_exists($type, $needed)) { | |
- $needed[$type] = array($item->getId()); | |
+ $needed[$type] = array($id); | |
$retrieved[$type] = array(); | |
} else { | |
- $needed[$type][] = $item->getId(); | |
+ $needed[$type][] = $id; | |
} | |
} | |
@@ -188,9 +204,12 @@ class ResultList extends ViewableData implements SS_List | |
} | |
foreach ($found as $item) { | |
+ $data = $item->getData(); | |
+ $type = isset($data['ClassName']) ? $data['ClassName'] : $item->getType(); | |
+ $id = isset($data['ID']) ? $data['ID'] : $item->getId(); | |
// Safeguards against indexed items which might no longer be in the DB | |
- if (array_key_exists($item->getId(), $retrieved[$item->getType()])) { | |
- $this->resultsArray[] = $retrieved[$item->getType()][$item->getId()]; | |
+ if (array_key_exists($id, $retrieved[$type])) { | |
+ $this->resultsArray[] = $retrieved[$type][$id]; | |
} | |
} | |
} | |
diff --git vendor/heyday/silverstripe-elastica/src/Searchable.php vendor/heyday/silverstripe-elastica/src/Searchable.php | |
index 449af97..4ae84e1 100644 | |
--- vendor/heyday/silverstripe-elastica/src/Searchable.php | |
+++ vendor/heyday/silverstripe-elastica/src/Searchable.php | |
@@ -144,7 +144,10 @@ class Searchable extends DataExtension | |
*/ | |
protected function getSearchableFields() | |
{ | |
- $result = array(); | |
+ $result = array( | |
+ 'ID' => ['type' => 'long'], | |
+ 'ClassName' => ['type' => 'string'] | |
+ ); | |
$fields = array_merge($this->owner->inheritedDatabaseFields(), $this->owner->config()->get('fixed_fields')); | |
@@ -305,7 +308,8 @@ class Searchable extends DataExtension | |
public function getElasticaDocument() | |
{ | |
$ownerConfig = $this->owner->config(); | |
- $document = new Document($this->owner->ID); | |
+ $id = str_replace('\\', '_', $this->owner->getElasticaType()) . '_' . $this->owner->ID; | |
+ $document = new Document($id); | |
$this->setPublishedStatus($document); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment