Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First update on refactoring based on SearchBackend #270

Open
wants to merge 6 commits into
base: primary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM brettt89/silverstripe-web:7.1-platform
FROM brettt89/silverstripe-web:8.1-apache-bullseye

LABEL maintainer="Marco Hermo"

ENV DEBIAN_FRONTEND=noninteractive

# Debian Jessie Archive sources
RUN echo "deb http://deb.debian.org/debian/ jessie main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://deb.debian.org/debian/ jessie main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/ jessie/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/ jessie/updates main contrib non-free" >> /etc/apt/sources.list
RUN echo "deb http://deb.debian.org/debian/ bullseye main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://deb.debian.org/debian/ bullseye main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/ jessbullseyeie/updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/ bullseye/updates main contrib non-free" >> /etc/apt/sources.list

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
Expand Down
3 changes: 0 additions & 3 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
SilverStripe\ORM\DataObject:
extensions:
- Firesphere\SolrSearch\Extensions\DataObjectExtension
SilverStripe\Forms\GridField\GridField:
extensions:
- Firesphere\SolrSearch\Extensions\GridFieldExtension
63 changes: 0 additions & 63 deletions _config/typemap.yml

This file was deleted.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"guzzlehttp/guzzle": "^6.3|^7",
"http-interop/http-factory-guzzle": "^1",
"symfony/event-dispatcher": "^5.4",
"php-http/guzzle7-adapter": "^1.0.0"
"php-http/guzzle7-adapter": "^1.0.0",
"firesphere/searchbackend": "dev-main"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
Expand Down
60 changes: 0 additions & 60 deletions src/Admins/SearchAdmin.php

This file was deleted.

5 changes: 1 addition & 4 deletions src/Extensions/DataObjectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
namespace Firesphere\SolrSearch\Extensions;

use Exception;
use Firesphere\SolrSearch\Helpers\SolrLogger;
use Firesphere\SolrSearch\Models\DirtyClass;
use Firesphere\SearchBackend\Models\DirtyClass;
use Firesphere\SolrSearch\Services\SolrCoreService;
use Firesphere\SolrSearch\Tests\DataObjectExtensionTest;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -191,8 +190,6 @@ protected function registerException(array $ids, DirtyClass $record, Exception $
$owner->ID
)
);
$solrLogger = new SolrLogger();
$solrLogger->saveSolrLog('Index');

$logger->error($error->getMessage());
}
Expand Down
42 changes: 0 additions & 42 deletions src/Extensions/GridFieldExtension.php

This file was deleted.

100 changes: 9 additions & 91 deletions src/Factories/DocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
namespace Firesphere\SolrSearch\Factories;

use Exception;
use Firesphere\SearchBackend\Factories\DocumentCoreFactory;
use Firesphere\SearchBackend\Helpers\DataResolver;
use Firesphere\SearchBackend\Helpers\Statics;
use Firesphere\SearchBackend\Queries\BaseQuery;
use Firesphere\SearchBackend\Traits\LoggerTrait;
use Firesphere\SolrSearch\Extensions\DataObjectExtension;
use Firesphere\SolrSearch\Helpers\DataResolver;
use Firesphere\SolrSearch\Helpers\FieldResolver;
use Firesphere\SolrSearch\Helpers\Statics;
use Firesphere\SolrSearch\Indexes\BaseIndex;
use Firesphere\SolrSearch\Services\SolrCoreService;
use Firesphere\SolrSearch\Traits\DocumentFactoryTrait;
use Firesphere\SolrSearch\Traits\LoggerTrait;
use Psr\Container\NotFoundExceptionInterface;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Extensible;
Expand All @@ -34,12 +36,10 @@
*
* @package Firesphere\Solr\Search
*/
class DocumentFactory
class DocumentFactory extends DocumentCoreFactory
{
use Configurable;
use Extensible;
use DocumentFactoryTrait;
use LoggerTrait;

/**
* @var array Numeral types in Solr
Expand All @@ -49,18 +49,6 @@ class DocumentFactory
'tfloat',
'tdouble',
];
/**
* @var bool Debug this build
*/
protected $debug = false;

/**
* DocumentFactory constructor, sets up the field resolver
*/
public function __construct()
{
$this->fieldResolver = Injector::inst()->get(FieldResolver::class);
}

/**
* Note, it can only take one type of class at a time!
Expand All @@ -72,7 +60,7 @@ public function __construct()
* @return array Documents to be pushed
* @throws Exception
*/
public function buildItems($fields, $index, $update): array
public function buildItems($fields, $index, $update = null): array
{
$this->getFieldResolver()->setIndex($index);
$boostFields = $index->getBoostedFields();
Expand Down Expand Up @@ -100,30 +88,13 @@ public function buildItems($fields, $index, $update): array
return $docs;
}

/**
* Show the message about what is being indexed
*
* @param BaseIndex $index
*/
protected function indexGroupMessage(BaseIndex $index): void
{
$debugString = sprintf(
'Indexing %s on %s (%s items)%s',
$this->getClass(),
$index->getIndexName(),
$this->getItems()->count(),
PHP_EOL
);
$this->getLogger()->info($debugString);
}

/**
* Add fields that should always be included
*
* @param Document $doc Solr Document
* @param DataObject|DataObjectExtension $item Item to get the data from
*/
protected function addDefaultFields(Document $doc, DataObject $item)
protected function addDefaultFields($doc, $item)
{
$doc->setKey(SolrCoreService::ID_FIELD, $item->ClassName . '-' . $item->ID);
$doc->addField(SolrCoreService::CLASS_ID_FIELD, $item->ID);
Expand Down Expand Up @@ -184,59 +155,6 @@ protected function addField($doc, $object, $options): void
}
}

/**
* Determine if the given object is one of the given type
*
* @param string|DataObject $class Class to compare
* @param array|string $base Class or list of base classes
* @return bool
*/
protected function classIs($class, $base): bool
{
$base = is_array($base) ? $base : [$base];

foreach ($base as $nextBase) {
if ($this->classEquals($class, $nextBase)) {
return true;
}
}

return false;
}

/**
* Check if a base class is an instance of the expected base group
*
* @param string|DataObject $class Class to compare
* @param string $base Base class
* @return bool
*/
protected function classEquals($class, $base): bool
{
return $class === $base || ($class instanceof $base);
}

/**
* Use the DataResolver to find the value(s) for a field.
* Returns an array of values, and if it's multiple, it becomes a long array
*
* @param DataObject $object Object to resolve
* @param array $options Customised options
* @return array
*/
protected function getValuesForField($object, $options): array
{
try {
$valuesForField = [DataResolver::identify($object, $options['fullfield'])];
} catch (Exception $error) {
// @codeCoverageIgnoreStart
$valuesForField = [];
// @codeCoverageIgnoreEnd
}

return $valuesForField;
}

/**
* Push field to a document
*
Expand Down
Loading