mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
Merge branch '3'
This commit is contained in:
commit
ff33fcfb60
@ -13,3 +13,7 @@ SilverStripe\Core\Injector\Injector:
|
||||
SilverStripe\FullTextSearch\Search\Queries\SearchQuery:
|
||||
calls:
|
||||
- [ setHandler, [ %$SilverStripe\FullTextSearch\Search\Adapters\SolrSearchAdapter ]]
|
||||
|
||||
SilverStripe\Dev\Tasks\MigrateFileTask:
|
||||
extensions:
|
||||
- SilverStripe\FullTextSearch\Search\Extensions\DisableIndexingOnFileMigration
|
||||
|
0
bin/fulltextsearch_quickstart
Normal file → Executable file
0
bin/fulltextsearch_quickstart
Normal file → Executable file
@ -39,7 +39,7 @@ configured and running) that each connector deals with itself, in a way best sui
|
||||
If you are running on a Linux-based system, you can get up and running quickly with the quickstart script, like so:
|
||||
|
||||
```bash
|
||||
composer require silverstripe/fulltextsearch && vendor/bin/fulltextsearch_quickstart
|
||||
composer require silverstripe/fulltextsearch --prefer-source && vendor/bin/fulltextsearch_quickstart
|
||||
```
|
||||
|
||||
This will:
|
||||
|
37
src/Search/Extensions/DisableIndexingOnFileMigration.php
Normal file
37
src/Search/Extensions/DisableIndexingOnFileMigration.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Search\Extensions;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||
|
||||
/**
|
||||
* This extension can be applied to `SilverStripe\Dev\Tasks\MigrateFileTask` to avoid constantly re-indexing files
|
||||
* while the file migration is running.
|
||||
*/
|
||||
class DisableIndexingOnFileMigration extends Extension
|
||||
{
|
||||
private static $dependencies = [
|
||||
'logger' => '%$' . LoggerInterface::class . '.quiet',
|
||||
];
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function preFileMigration()
|
||||
{
|
||||
if (SearchUpdater::config()->get('enabled')) {
|
||||
$this->logger->info('Disabling fulltext search re-indexing for this request only');
|
||||
SearchUpdater::config()->set('enabled', false);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,10 +2,8 @@
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Solr\Services;
|
||||
|
||||
use Apache_Solr_Response;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\FullTextSearch\Solr\Solr;
|
||||
use SilverStripe\FullTextSearch\Solr\SolrIndex;
|
||||
use Silverstripe\Core\ClassInfo;
|
||||
|
||||
/**
|
||||
* The API for accessing the primary Solr installation, which includes both SolrService_Core,
|
||||
@ -18,18 +16,24 @@ class SolrService extends SolrService_Core
|
||||
|
||||
/**
|
||||
* Handle encoding the GET parameters and making the HTTP call to execute a core command
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $core
|
||||
* @param array $params
|
||||
* @return Apache_Solr_Response
|
||||
*/
|
||||
protected function coreCommand($command, $core, $params = array())
|
||||
{
|
||||
$command = strtoupper($command);
|
||||
$params = array_merge($params, array('action' => $command, 'wt' => 'json'));
|
||||
$params[$command == 'CREATE' ? 'name' : 'core'] = $core;
|
||||
$params[$command === 'CREATE' ? 'name' : 'core'] = $core;
|
||||
|
||||
return $this->_sendRawGet($this->_constructUrl('admin/cores', $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the passed core active?
|
||||
*
|
||||
* @param string $core The name of the core (an encoded class name)
|
||||
* @return boolean True if that core exists & is active
|
||||
*/
|
||||
@ -42,11 +46,12 @@ class SolrService extends SolrService_Core
|
||||
|
||||
/**
|
||||
* Create a new core
|
||||
* @param $core string - The name of the core
|
||||
* @param $instancedir string - The base path of the core on the server
|
||||
* @param $config string - The filename of solrconfig.xml on the server. Default is $instancedir/solrconfig.xml
|
||||
* @param $schema string - The filename of schema.xml on the server. Default is $instancedir/schema.xml
|
||||
* @param $datadir string - The path to store data for this core on the server. Default depends on solrconfig.xml
|
||||
*
|
||||
* @param string $core The name of the core
|
||||
* @param string $instancedir The base path of the core on the server
|
||||
* @param string $config The filename of solrconfig.xml on the server. Default is $instancedir/solrconfig.xml
|
||||
* @param string $schema The filename of schema.xml on the server. Default is $instancedir/schema.xml
|
||||
* @param string $datadir The path to store data for this core on the server. Default depends on solrconfig.xml
|
||||
* @return Apache_Solr_Response
|
||||
*/
|
||||
public function coreCreate($core, $instancedir, $config = null, $schema = null, $datadir = null)
|
||||
@ -67,7 +72,8 @@ class SolrService extends SolrService_Core
|
||||
|
||||
/**
|
||||
* Reload a core
|
||||
* @param $core string - The name of the core
|
||||
*
|
||||
* @param string $core The name of the core
|
||||
* @return Apache_Solr_Response
|
||||
*/
|
||||
public function coreReload($core)
|
||||
@ -77,7 +83,8 @@ class SolrService extends SolrService_Core
|
||||
|
||||
/**
|
||||
* Create a new Solr4Service_Core instance for the passed core
|
||||
* @param $core string - The name of the core
|
||||
*
|
||||
* @param string $core The name of the core
|
||||
* @return Solr4Service_Core
|
||||
*/
|
||||
public function serviceForCore($core)
|
||||
|
24
tests/DisableIndexingOnFileMigrationTest.php
Normal file
24
tests/DisableIndexingOnFileMigrationTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\FullTextSearch\Tests\SolrReindexTest;
|
||||
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\FullTextSearch\Search\Extensions\DisableIndexingOnFileMigration;
|
||||
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||
|
||||
/**
|
||||
* Logger for recording messages for later retrieval
|
||||
*/
|
||||
class DisableIndexingOnFileMigrationTest extends SapphireTest
|
||||
{
|
||||
|
||||
public function testPreFileMigration()
|
||||
{
|
||||
$this->assertTrue(SearchUpdater::config()->get('enabled'));
|
||||
|
||||
Injector::inst()->get(DisableIndexingOnFileMigration::class)->preFileMigration();
|
||||
|
||||
$this->assertFalse(SearchUpdater::config()->get('enabled'));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user