Skip to content

Commit

Permalink
Merge pull request #10 from daita/0.3.x
Browse files Browse the repository at this point in the history
* Managing Solr Schema from Administration page or using ./occ nextant:check 
* bugfixes:
  - result being displayed twice.
  - escape few queries to Solr
  • Loading branch information
ArtificialOwl committed Sep 13, 2016
2 parents eff1617 + 0b79699 commit bb488a7
Show file tree
Hide file tree
Showing 12 changed files with 400 additions and 157 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
**v0.3.0**
* Managing Solr Schema from Administration page or using ./occ nextant:check
* bugfixes:
- result being displayed twice.
- escape few queries to Solr

**v0.2.0**
* New format: opendocument, office, rtf, html, epub, ...
* Search within shared file,
Expand Down
2 changes: 2 additions & 0 deletions appinfo/app.php
Expand Up @@ -29,6 +29,8 @@
require_once __DIR__ . '/autoload.php';

$app = new \OCA\Nextant\AppInfo\Application();

// $app->registerNavigation();
$app->registerFilesHooks();
$app->registerSettingsAdmin();
$app->registerSearchProvider();
13 changes: 4 additions & 9 deletions appinfo/info.xml
Expand Up @@ -5,18 +5,13 @@
<name>Nextant</name>
<summary>Navigate through your cloud using Solr</summary>
<description>
One to enable a full text search within your cloud.
One to enable a Full-Text Search within your cloud.

- When uploaded to the cloud, text and pdf file are extracted to the Solr Server.

- It add an owner filter to solr documents so each user search in its own library.

- Use the Solr server when using the searchbox in the files App of your nextcloud.

- You can also extract your current files using ./occ nextant:scan
Index your own files and your shared documents and perform fast and precise search using a Solr Servlet.

Recognized file format: text, rtf, pdf, html, openoffice, office, ...
</description>
<version>0.2.0</version>
<version>0.3.0</version>
<licence>agpl</licence>
<author mail="maxence@pontapreta.net">Maxence Lange</author>
<types>
Expand Down
4 changes: 2 additions & 2 deletions appinfo/register_command.php
Expand Up @@ -27,8 +27,8 @@
$app = new \OCA\Nextant\AppInfo\Application();
$c = $app->getContainer();

$application->add(new OCA\Nextant\Command\Check($c->query('SolrService'), $c->query('SolrAdminService')));
$application->add(new OCA\Nextant\Command\Clear($c->query('SolrService'), $c->query('SolrAdminService')));
$application->add(new OCA\Nextant\Command\Scan(OC::$server->getUserManager(), $c->query('UserFolder'), $c->query('SolrService'), $c->query('FileService')));
$application->add(new OCA\Nextant\Command\Clear($c->query('SolrService')));
$application->add(new OCA\Nextant\Command\Check($c->query('SolrService')));


13 changes: 13 additions & 0 deletions js/settings.admin.js
Expand Up @@ -55,6 +55,12 @@ $(document)
'Ping querying your Solr Server'));
break;

case 'schema':
OC.msg.startAction('#nextant-admin-msg',
t('nextant',
'Verifying Schema integrity'));
break;

case 'extract':
OC.msg.startAction('#nextant-admin-msg', t(
'nextant',
Expand Down Expand Up @@ -98,6 +104,13 @@ $(document)
response);
switch (response.command) {
case 'ping':
if (response.status == 'success')
nextantSettings.test_standby('schema');
else
nextantSettings.reset();
break;

case 'schema':
if (response.status == 'success')
nextantSettings.test_standby('extract');
else
Expand Down
26 changes: 16 additions & 10 deletions lib/AppInfo/Application.php
Expand Up @@ -35,6 +35,7 @@
use \OCA\Nextant\Service\MiscService;
use \OCA\Nextant\Service\FileService;
use \OCA\Nextant\Service\SolrService;
use \OCA\Nextant\Service\SolrAdminService;
use OCP\AppFramework\App;
use OCP\Util;
use Solarium\Solarium;
Expand Down Expand Up @@ -72,6 +73,10 @@ public function __construct(array $params = array())
return new SolrService($c->query('SolariumClient'), $c->query('ConfigService'), $c->query('MiscService'));
});

$container->registerService('SolrAdminService', function ($c) {
return new SolrAdminService($c->query('SolariumClient'), $c->query('ConfigService'), $c->query('MiscService'));
});

$container->registerService('IndexMapper', function ($c) {
return new IndexMapper($c->query('ServerContainer')
->getDb());
Expand All @@ -89,7 +94,7 @@ public function __construct(array $params = array())
// });

$container->registerService('SettingsController', function ($c) {
return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('ConfigService'), $c->query('SolrService'), $c->query('MiscService'));
return new SettingsController($c->query('AppName'), $c->query('Request'), $c->query('ConfigService'), $c->query('SolrService'), $c->query('SolrAdminService'), $c->query('MiscService'));
});

/**
Expand Down Expand Up @@ -136,15 +141,6 @@ public function __construct(array $params = array())
->getValue('datadirectory', \OC::$SERVERROOT . '/data');
});

/**
* Solr / Search Engines
*/
\OC::$server->getSearch()->registerProvider('OCA\Nextant\Provider\SearchProvider', array(
'apps' => array(
'files'
)
));

$this->getContainer()->registerService('SolariumClient', function ($c) {
$toS = $c->query('ConfigService')
->toSolarium();
Expand All @@ -166,6 +162,16 @@ public function registerFilesHooks()
Util::connectHook('OCP\Share', 'post_unshare', '\OCA\Nextant\Hooks\FilesHooks', 'fileUnshared');
}

public function registerSearchProvider()
{
\OC::$server->getSearch()->registerProvider('\OCA\Nextant\Provider\SearchProvider', array(
'apps' => array(
'files'
)
)
);
}

public function registerSettingsAdmin()
{
\OCP\App::registerAdmin($this->getContainer()->query('AppName'), 'settings/admin');
Expand Down
27 changes: 19 additions & 8 deletions lib/Command/Check.php
Expand Up @@ -35,30 +35,41 @@
class Check extends Base
{

private $solrService;
private $solrClient;

public function __construct($solrService)
private $solrAdmin;

public function __construct($solrClient, $solrAdmin)
{
parent::__construct();
$this->solrService = $solrService;
$this->solrClient = $solrClient;
$this->solrAdmin = $solrAdmin;
}

protected function configure()
{
parent::configure();
$this->setName('nextant:check')->setDescription('check your current Solr configuration');
$this->setName('nextant:check')->setDescription('check, fix and optimise your current Solr configuration');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->solrAdmin->setOutput($output);

$output->write('Ping: ');
if ($this->solrService->ping())
if ($this->solrAdmin->ping())
$output->writeln('ok');
else {
$output->writeln('fail');
return false;}

$output->writeln('Your solr contains ' . $this->solrService->count() . ' documents');
return false;
}

if (! $this->solrAdmin->checkSchema(true, $error)) {
$output->writeln('Error: ' . $error);
return false;
}

$output->writeln('Your solr contains ' . $this->solrAdmin->count() . ' documents');
}
}

Expand Down
7 changes: 5 additions & 2 deletions lib/Command/Clear.php
Expand Up @@ -37,10 +37,13 @@ class Clear extends Base

private $solrService;

public function __construct($solrService)
private $solrAdmin;

public function __construct($solrService, $solrAdmin)
{
parent::__construct();
$this->solrService = $solrService;
$this->solrAdmin = $solrAdmin;
}

protected function configure()
Expand All @@ -51,7 +54,7 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->solrService->clear();
$this->solrAdmin->clear();
}
}

Expand Down
61 changes: 29 additions & 32 deletions lib/Controller/SettingsController.php
Expand Up @@ -26,11 +26,11 @@
*/
namespace OCA\Nextant\Controller;

use \OCA\Nextant\Service\ConfigService;
use \OCA\Nextant\Service\SolrService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IRequest;
use \OCA\Nextant\Service\ConfigService;
use \OCA\Nextant\Service\SolrService;

class SettingsController extends Controller
{
Expand All @@ -41,15 +41,18 @@ class SettingsController extends Controller

private $solrService;

private $solrAdmin;

private $solr_url;

private $solr_core;

public function __construct($appName, IRequest $request, ConfigService $configService, $solrService, $miscService)
public function __construct($appName, IRequest $request, ConfigService $configService, $solrService, $solrAdmin, $miscService)
{
parent::__construct($appName, $request);
$this->configService = $configService;
$this->solrService = $solrService;
$this->solrAdmin = $solrAdmin;
$this->miscService = $miscService;
}

Expand All @@ -58,7 +61,7 @@ public function __construct($appName, IRequest $request, ConfigService $configSe
*/
public function index()
{
$documentsCount = $this->solrService->count($error);
$documentsCount = $this->solrAdmin->count($error);

$params = [
'current_docs' => $documentsCount,
Expand Down Expand Up @@ -94,6 +97,10 @@ public function setSettings($solr_url, $solr_core, $command)
$result = $this->test_ping($message);
break;

case 'schema':
$result = $this->test_schema($message);
break;

case 'extract':
$result = $this->test_extract($message);
break;
Expand Down Expand Up @@ -131,7 +138,7 @@ public function setSettings($solr_url, $solr_core, $command)
// Wiki Error 9
private function test_ping(&$message)
{
if ($this->solrService->ping($error)) {
if ($this->solrAdmin->ping($error)) {
$message = 'Apache Solr is up, running and responding to our ping query';
return true;
}
Expand All @@ -140,6 +147,17 @@ private function test_ping(&$message)
return false;
}

private function test_schema(&$message)
{
if ($this->solrAdmin->checkSchema(true, $error)) {
$message = 'Schema is fine';
return true;
}

$message = 'Were not able to verify/fix your schema integrity (Error #' . $error . ')';
return false;
}

private function test_extract(&$message)
{
$testFile = __DIR__ . '/../../LICENSE';
Expand All @@ -155,42 +173,21 @@ private function test_extract(&$message)

private function test_update(&$message)
{
$testShareUsers = array(
$testUpdate = array(
'id' => '__nextant_test',
'share_users' => array(
'__nextant_test_owner'
)
);
$testShareGroups = array(
'id' => '__nextant_test',
),
'share_groups' => array(
'__nextant_share_group'
)
);

$testDeleted = array(
'id' => '__nextant_test',
'deleted' => true
),
'deleted' => false
);

if (! $this->solrService->updateDocuments(array(
$testShareUsers
), $error)) {
$message = 'Error Updating user sharing flag (Error #' . $error . ')';
return false;
}

if (! $this->solrService->updateDocuments(array(
$testShareGroups
), $error)) {
$message = 'Updating group sharing (Error #' . $error . ')';
return false;
}

if (! $this->solrService->updateDocuments(array(
$testDeleted
$testUpdate
), $error)) {
$message = 'Updating trashbin flag (Error #' . $error . ')';
$message = 'Error Updating field (Error #' . $error . ')';
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Provider/SearchProvider.php
Expand Up @@ -77,7 +77,7 @@ public function search($query)

if ($query !== null) {

$solrResult = $this->solrService->search($query);
$solrResult = $this->solrService->search($query);
if ($solrResult == false)
return $results;

Expand Down

0 comments on commit bb488a7

Please sign in to comment.