Skip to content
Closed
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
58 changes: 13 additions & 45 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,45 +1,13 @@
#--------------------------#
# Magento Default Files #
#--------------------------#

/PATCH_*.sh

/app/etc/local.xml

/media/*
!/media/.htaccess

!/media/customer
/media/customer/*
!/media/customer/.htaccess

!/media/dhl
/media/dhl/*
!/media/dhl/logo.jpg

!/media/downloadable
/media/downloadable/*
!/media/downloadable/.htaccess

!/media/xmlconnect
/media/xmlconnect/*

!/media/xmlconnect/custom
/media/xmlconnect/custom/*
!/media/xmlconnect/custom/ok.gif

!/media/xmlconnect/original
/media/xmlconnect/original/*
!/media/xmlconnect/original/ok.gif

!/media/xmlconnect/system
/media/xmlconnect/system/*
!/media/xmlconnect/system/ok.gif

/var/*
!/var/.htaccess

!/var/package
/var/package/*
!/var/package/*.xml

# Composer
/vendor/
.metadata
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.project
.buildpath
.idea/
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "develodesign/typesense",
"description": "A TypeSense adapter for Magento 2",
"type": "magento2-module",
"license": "OSL-3.0",
"require": {
"algolia/algoliasearch-magento-2": "^3.9",
"typesense/typesense-php": "^2.0"
},
"authors": [
{
"name": "Nathan McBride",
"email": "nathan@brideo.co.uk"
},
{
"name": "Luke Collymore",
"email": "luke@develodesign.co.uk"
}
],
"autoload": {
"psr-4": {
"Develo\\TypeSense": "src/"
}
}
}
43 changes: 43 additions & 0 deletions src/Adapter/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Develo\TypeSense\Adapter;

use Devloops\Typesence\Client as TypeSenseClient;

/**
* Class Client
*
* This class should replace the AlgoliaSearch\Client implementation
*
* @see \AlgoliaSearch\Client
* @package Develo\TypeSense\Service
*/
class Client extends \AlgoliaSearch\Client
{

/**
* @var TypeSenseClient
*/
public $typeSenseClient;

public function __construct(
$applicationID,
$apiKey,
TypeSenseClient $client, // @todo we need to inject a config class here
$hostsArray = null,
$options = array()
)
{
parent::__construct($applicationID, $apiKey, $hostsArray, $options);

$this->typeSenseClient = $client;
}

/**
* @inheirtDoc
*/
public function deleteIndex($indexName)
{
return $this->typeSenseClient->collections[$indexName]->delete();
}
}
74 changes: 74 additions & 0 deletions src/Adapter/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php


namespace Develo\TypeSense\Adapter;

use AlgoliaSearch\ClientContext;
use Devloops\Typesence\Client as TypeSenseClient;

/**
* Class Index
*
* @package Develo\TypeSense\Service
*
* @todo extend all methods used in Magento module and override.
*/
class Index extends \AlgoliaSearch\Index
{
/**
* @var string
*/
public $indexName;

/**
* @var Client
*/
private $client;

public function __construct(ClientContext $context, Client $client, $indexName)
{
parent::__construct($context, $client, $indexName);

$this->client = $client;
$this->indexName = $indexName;
}

public function addObject($content, $objectID = null)
{
if ($objectID) {
$content['id'] = $content;
}

return $this->getDocuments()->upsert($content);
}

public function addObjects($objects, $objectIDKeyLegacy = 'objectID')
{
return $this->getDocuments()->import($objects, ['action' => 'create']);
}

public function deleteObjects($objects)
{
$ids = 'id:='.json_encode($objects);

return $this->getDocuments()->delete(['filter_by' => $ids]);
}

/**
* @return TypeSenseClient
*/
private function getClient(): TypeSenseClient
{
return $this->client->typeSenseClient;
}

/**
* @todo none of the methods seem to be in this class but that is what is documented.
*
* @return \Devloops\Typesence\Documents
*/
private function getDocuments()
{
return $this->getClient()->collections[$this->indexName]->documents;
}
}
8 changes: 8 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<preference for="AlgoliaSearch\Client" type="Develo\TypeSense\Adapter\Client"/>
<preference for="AlgoliaSearch\Index" type="Develo\TypeSense\Adapter\Index"/>

</config>
8 changes: 8 additions & 0 deletions src/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Develo_TypeSense" setup_version="1.0.0">
<sequence>
<module name="Algolia_AlgoliaSearch"/>
</sequence>
</module>
</config>
5 changes: 5 additions & 0 deletions src/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Develo_TypeSense', __DIR__);