Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/fulltextsearch.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Command/Index.php6
-rw-r--r--lib/Controller/SettingsController.php10
-rw-r--r--lib/Cron/BackgroundIndex.php2
-rw-r--r--lib/Service/FileService.php6
-rw-r--r--lib/Service/SolrAdminService.php20
-rw-r--r--lib/Service/SolrService.php19
-rw-r--r--lib/Service/SolrToolsService.php34
-rw-r--r--templates/settings.admin.php8
8 files changed, 74 insertions, 31 deletions
diff --git a/lib/Command/Index.php b/lib/Command/Index.php
index 519ca6f..9881dbf 100644
--- a/lib/Command/Index.php
+++ b/lib/Command/Index.php
@@ -80,8 +80,8 @@ class Index extends Base
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('<comment>nextant v' . $this->configService->getAppValue('installed_version') . ' (beta)</comment>');
-// $output->writeln('<comment>discussion thread:</comment> https://help.nextcloud.com/t/nextant-navigate-through-your-cloud-using-solr/2954/');
-// $output->writeln('');
+ // $output->writeln('<comment>discussion thread:</comment> https://help.nextcloud.com/t/nextant-navigate-through-your-cloud-using-solr/2954/');
+ // $output->writeln('');
if (! $this->solrService->configured()) {
$output->writeln('Nextant is not yet configured');
return;
@@ -381,7 +381,7 @@ class Index extends Base
throw new \Exception('ctrl-c');
}
- $ids = $this->solrTools->getAll($page, $lastPage, $error);
+ $ids = $this->solrTools->getAll('files', $page, $lastPage, $error);
if (! $ids)
return false;
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 7d52453..f4acc0d 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -203,7 +203,7 @@ class SettingsController extends Controller
{
$testFile = __DIR__ . '/../../LICENSE';
- if ($this->solrService->extractFile($testFile, '__nextant_test', '/LICENSE', 1234567890, $error)) {
+ if ($this->solrService->extractFile($testFile, 'test', 'nextant_test', '/LICENSE', 1234567890, $error)) {
$message = 'Text successfully extracted';
return true;
}
@@ -215,7 +215,7 @@ class SettingsController extends Controller
private function test_update(&$message)
{
$testUpdate = array(
- 'id' => '__nextant_test',
+ 'id' => 'nextant_test',
'path' => '/LICENSE2',
'share_users' => array(
'__nextant_test_owner'
@@ -226,7 +226,7 @@ class SettingsController extends Controller
'deleted' => false
);
- if (! $this->solrTools->updateDocuments(array(
+ if (! $this->solrTools->updateDocuments('test', array(
$testUpdate
), $error)) {
$message = 'Error Updating field (Error #' . $error . ')';
@@ -244,7 +244,7 @@ class SettingsController extends Controller
if (sizeof($result) > 0) {
foreach ($result as $doc) {
- if ($doc['id'] == '__nextant_test') {
+ if ($doc['id'] == 'nextant_test') {
$message = 'Found exactly what we were looking for';
return true;
}
@@ -264,7 +264,7 @@ class SettingsController extends Controller
private function test_delete(&$message)
{
- if ($this->solrTools->removeDocument('__nextant_test')) {
+ if ($this->solrTools->removeDocument('test', 'nextant_test')) {
$message = 'Test document deleted';
return true;
}
diff --git a/lib/Cron/BackgroundIndex.php b/lib/Cron/BackgroundIndex.php
index d3197ef..675db76 100644
--- a/lib/Cron/BackgroundIndex.php
+++ b/lib/Cron/BackgroundIndex.php
@@ -114,7 +114,7 @@ class BackgroundIndex extends \OC\BackgroundJob\TimedJob
$page = 0;
while (true) {
- $ids = $this->solrTools->getAll($page, $lastPage, $error);
+ $ids = $this->solrTools->getAll('files', $page, $lastPage, $error);
if (! $ids)
break;
diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php
index afa61b3..34475be 100644
--- a/lib/Service/FileService.php
+++ b/lib/Service/FileService.php
@@ -98,7 +98,7 @@ class FileService
if (! SolrService::extractableFile($fileInfo->getMimeType(), $path))
return false;
- if (! $forceExtract && $this->solrTools->isDocumentUpToDate($fileInfo->getId(), $fileInfo->getMTime())) {
+ if (! $forceExtract && $this->solrTools->isDocumentUpToDate('files', $fileInfo->getId(), $fileInfo->getMTime())) {
$this->miscService->debug('File is already known ' . $path);
return true;
}
@@ -108,7 +108,7 @@ class FileService
$storage = $fileInfo->getStorage();
$status = 1;
if ($storage->isLocal())
- $result = $this->solrService->extractFile($this->view->getLocalFile($path), $fileInfo->getId(), $path, $fileInfo->getMTime());
+ $result = $this->solrService->extractFile($this->view->getLocalFile($path), 'files', $fileInfo->getId(), $path, $fileInfo->getMTime());
else {
// create a temp file containing the remote file to send to solr
@@ -183,7 +183,7 @@ class FileService
if (! $isRoot)
return $pack;
- $count = $this->solrTools->updateDocuments($pack, $error);
+ $count = $this->solrTools->updateDocuments('files', $pack, $error);
if ($count === false)
$this->configService->needIndex(true);
diff --git a/lib/Service/SolrAdminService.php b/lib/Service/SolrAdminService.php
index 009918b..8709207 100644
--- a/lib/Service/SolrAdminService.php
+++ b/lib/Service/SolrAdminService.php
@@ -157,6 +157,26 @@ class SolrAdminService
'multiValued' => false
)
));
+ array_push($fields, array(
+ 'type' => 'field',
+ 'data' => array(
+ 'name' => 'nextant_source',
+ 'type' => 'string',
+ 'indexed' => true,
+ 'stored' => true,
+ 'multiValued' => false
+ )
+ ));
+ array_push($fields, array(
+ 'type' => 'field',
+ 'data' => array(
+ 'name' => 'nextant_ocr',
+ 'type' => 'int',
+ 'indexed' => true,
+ 'stored' => true,
+ 'multiValued' => false
+ )
+ ));
$this->solrService->message('Checking Solr schema fields');
diff --git a/lib/Service/SolrService.php b/lib/Service/SolrService.php
index cf64d35..64f2e0a 100644
--- a/lib/Service/SolrService.php
+++ b/lib/Service/SolrService.php
@@ -33,6 +33,9 @@ class SolrService
// Owner is not set - mostly a developper mistake
const ERROR_OWNER_NOT_SET = 4;
+
+ // Type of document is not set
+ const ERROR_TYPE_NOT_SET = 6;
const ERROR_TOOWIDE_SEARCH = 8;
@@ -202,11 +205,16 @@ class SolrService
* @param string $mimetype
* @return result
*/
- public function extractFile($absolutePath, $docid, $path, $mtime, &$error = '')
+ public function extractFile($absolutePath, $type, $docid, $path, $mtime, &$error = '')
{
if (! $this->configured())
return false;
+ if ($type == null || $type == '') {
+ $error = self::ERROR_TYPE_NOT_SET;
+ return false;
+ }
+
if ($this->owner == '') {
$error = self::ERROR_OWNER_NOT_SET;
return false;
@@ -241,7 +249,8 @@ class SolrService
// add document
$doc = $query->createDocument();
- $doc->id = $docid;
+ $doc->id = $type . '_' . $docid;
+ $doc->nextant_source = $type;
$doc->nextant_path = $path;
$doc->nextant_owner = $this->owner;
$doc->nextant_mtime = $mtime;
@@ -300,6 +309,7 @@ class SolrService
$query->setFields(array(
'id',
'nextant_deleted',
+ 'nextant_source',
'nextant_owner'
));
@@ -332,8 +342,11 @@ class SolrService
// highlight
$hlDoc = $highlighting->getResult($document->id);
+ list ($type, $docid) = explode('_', $document->id, 2);
array_push($return, array(
- 'id' => $document->id,
+ 'id' => $docid,
+ 'type' => $type,
+ 'source' => $document->nextant_source,
'deleted' => $document->nextant_deleted,
'owner' => $document->nextant_owner,
'highlight' => $hlDoc->getField('text'),
diff --git a/lib/Service/SolrToolsService.php b/lib/Service/SolrToolsService.php
index f863d90..1c24f3d 100644
--- a/lib/Service/SolrToolsService.php
+++ b/lib/Service/SolrToolsService.php
@@ -116,7 +116,7 @@ class SolrToolsService
* @param number $error
* @return boolean
*/
- public function updateDocuments($data, &$error = 0)
+ public function updateDocuments($type, $data, &$error = 0)
{
if (! $this->solrService || ! $this->solrService->configured() || ! $this->solrService->getClient())
return false;
@@ -133,7 +133,7 @@ class SolrToolsService
foreach ($batch as $entry)
array_push($docIds, $entry['id']);
- $currentStatus = $this->getDocumentsStatus($docIds, $error);
+ $currentStatus = $this->getDocumentsStatus($type, $docIds, $error);
if (! $currentStatus || sizeof($currentStatus) == 0)
continue;
@@ -149,7 +149,7 @@ class SolrToolsService
continue;
$doc = $query->createDocument();
- $doc->setKey('id', $upd['id']);
+ $doc->setKey('id', $type . '_' . $upd['id']);
$docStatus = $currentStatus[$upd['id']];
$edited = false;
@@ -247,7 +247,7 @@ class SolrToolsService
* @param string $error
* @return boolean|Solarium\Core\Query\Result[][]
*/
- private function getDocumentsStatus($docs, &$error = '')
+ private function getDocumentsStatus($type, $docs, &$error = '')
{
if (! $this->solrService || ! $this->solrService->configured() || ! $this->solrService->getClient())
return false;
@@ -272,11 +272,16 @@ class SolrToolsService
try {
$query = $client->createSelect();
- $query->setQuery('id:' . implode(' ', $docs));
+ $qstr = '';
+ foreach ($docs as $docId)
+ $qstr .= $type . '_' . $docId . ' ';
+
+ $query->setQuery('id:' . $qstr);
$query->setRows(sizeof($docs));
$query->setFields(array(
'id',
'nextant_owner',
+ 'nextant_source',
'nextant_path',
'nextant_share',
'nextant_sharegroup',
@@ -286,7 +291,9 @@ class SolrToolsService
$resultset = $client->select($query);
foreach ($resultset as $document) {
- $result[$document->id] = array(
+ list ($type, $docid) = explode('_', $document->id, 2);
+ $result[$docid] = array(
+ 'nextant_source' => $document->nextant_source,
'nextant_owner' => $document->nextant_owner,
'nextant_path' => $document->nextant_path,
'nextant_share' => $document->nextant_share,
@@ -315,7 +322,7 @@ class SolrToolsService
* @param number $error
* @return boolean
*/
- public function removeDocument($docid, &$error = 0)
+ public function removeDocument($type, $docid, &$error = 0)
{
if (! $this->solrService || ! $this->solrService->configured() || ! $this->solrService->getClient())
return false;
@@ -324,7 +331,7 @@ class SolrToolsService
$client = $this->solrService->getClient();
$update = $client->createUpdate();
- $update->addDeleteById($docid);
+ $update->addDeleteById($type . '_' . $docid);
$update->addCommit();
return $client->update($update);
@@ -348,7 +355,7 @@ class SolrToolsService
* @param number $error
* @return boolean
*/
- public function getAll($page, &$lastpage = false, &$error = 0)
+ public function getAll($type, $page, &$lastpage = false, &$error = 0)
{
if (! $this->solrService || ! $this->solrService->configured() || ! $this->solrService->getClient())
return false;
@@ -357,7 +364,7 @@ class SolrToolsService
try {
$query = $client->createSelect();
- $query->setQuery('id:*');
+ $query->setQuery('id:' . $type . '_*');
$query->addSort('id', $query::SORT_ASC);
$query->setStart($page);
$query->setRows(self::GETALL_ROWS);
@@ -369,7 +376,8 @@ class SolrToolsService
$ids = array();
foreach ($resultset as $document) {
- $docid = (int) $document->id;
+ list ($type, $docid) = explode('_', $document->id, 2);
+ $docid = (int) $docid;
array_push($ids, $docid);
}
@@ -397,7 +405,7 @@ class SolrToolsService
* @param number $error
* @return boolean
*/
- public function isDocumentUpToDate($docid, $mtime, &$error = 0)
+ public function isDocumentUpToDate($type, $docid, $mtime, &$error = 0)
{
if (intval($docid) == 0)
return false;
@@ -409,7 +417,7 @@ class SolrToolsService
try {
$query = $client->createSelect();
- $query->setQuery('id:' . $docid);
+ $query->setQuery('id:' . $type . '_' . $docid);
$query->setFields(array(
'nextant_mtime'
));
diff --git a/templates/settings.admin.php b/templates/settings.admin.php
index 56543a3..7dbd289 100644
--- a/templates/settings.admin.php
+++ b/templates/settings.admin.php
@@ -145,14 +145,16 @@ style('nextant', 'admin');
</div>
<button type="button" id="nextant_force_index"
style="width: 270px"><?php p($l->t('Force index')) ?></button>
- <div id="nextant_index_scheduled"><i>Index is scheduled within the
- next few hours (cron)</i></div>
+ <div id="nextant_index_scheduled">
+ <i>Index is scheduled within the next few hours (cron)</i>
+ </div>
</td>
</tr>
</table>
</td>
- <td style="padding-left: 30px; padding-top: 40px; vertical-align: top">
+ <td
+ style="padding-left: 30px; padding-top: 40px; vertical-align: top">
<div id="nextant-display">
<div id="ping" class="nextant-display-line">
<img id="icon_check" class="nextant_display_icon"