diff options
author | daita <maxence@pontapreta.net> | 2016-11-26 14:38:22 +0300 |
---|---|---|
committer | daita <maxence@pontapreta.net> | 2016-11-26 14:38:22 +0300 |
commit | aaa9881b2507600cda4b2a18b99aa30210aa411f (patch) | |
tree | 829ee776c8a2409184ee0c83fb82bc97aac7df76 | |
parent | c04b4481f37185741cca36bebc34bc9ecf7d3b00 (diff) |
#83 - resource_level
-rw-r--r-- | js/settings.admin.js | 7 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 7 | ||||
-rw-r--r-- | lib/Service/ConfigService.php | 16 | ||||
-rw-r--r-- | lib/Service/SolrService.php | 45 | ||||
-rw-r--r-- | templates/settings.admin.php | 17 |
5 files changed, 73 insertions, 19 deletions
diff --git a/js/settings.admin.js b/js/settings.admin.js index 85ea57e..a525cad 100644 --- a/js/settings.admin.js +++ b/js/settings.admin.js @@ -175,6 +175,7 @@ $(document) force_index = 1; var data = { + resource_level : $('#solr_resource_level').val(), index_live : ($('#solr_index_live') .is(':checked')) ? 1 : 0, index_delay : $('#solr_index_delay').val(), @@ -293,6 +294,8 @@ $(document) else $('#solr_sub_bookmarks').hide(delay); + $('#solr_resource_level').val( + response.resource_level); $('#solr_index_live').prop('checked', (response.index_live == 1)); $('#solr_index_live_queuekey').val( @@ -682,6 +685,10 @@ $(document) nextantSettings.savesuboptions_status('force_index'); }); + $('#solr_resource_level').on('change', function() { + nextantSettings.savesuboptions_status(); + }); + $('#solr_index_live').mousedown(function() { nextantSettings.savesuboptions_status('index_live'); }); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 9580001..199d470 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -85,7 +85,7 @@ class SettingsController extends Controller } public function updateSubOptions($instant, $source = '') - { + { $response = array( 'instant' => $instant, 'configured' => $this->configService->getAppValue('configured'), @@ -114,6 +114,7 @@ class SettingsController extends Controller 'bookmarks_app_enabled' => (\OCP\App::isEnabled('bookmarks')), 'index_bookmarks' => $this->configService->getAppValue('index_bookmarks'), 'index_bookmarks_needed' => $this->configService->getAppValue('index_bookmarks_needed'), + 'resource_level' => $this->configService->getAppValue('resource_level'), 'index_live' => $this->configService->getAppValue('index_live'), 'index_live_queuekey' => $this->configService->getAppValue('index_live_queuekey'), 'index_delay' => $this->configService->getAppValue('index_delay'), @@ -163,8 +164,10 @@ class SettingsController extends Controller return $this->updateSubOptions(false, 'bookmarks'); } - public function setOptionsStatus($index_live, $index_delay, $force_index) + public function setOptionsStatus($resource_level, $index_live, $index_delay, $force_index) { + $this->configService->setAppValue('resource_level', $resource_level); + if ($index_live === '1' && $this->configService->getAppValue('index_live') !== '1') $this->configService->setAppValue('index_live_queuekey', rand(20000, 990000)); diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index b909353..9fee3b3 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -36,12 +36,23 @@ class ConfigService const SEARCH_DISPLAY_FILES = 2; + const RESOURCE_LEVEL_LOWER = '1'; + + const RESOURCE_LEVEL_LOW = '2'; + + const RESOURCE_LEVEL_MID = '3'; + + const RESOURCE_LEVEL_HIGH = '4'; + + const RESOURCE_LEVEL_HIGHER = '5'; + private $defaults = [ 'configured' => '0', 'solr_url' => 'http://127.0.0.1:8983/solr/', 'solr_core' => 'nextant', 'solr_timeout' => '30', + 'resource_level' => '4', 'index_live' => '1', 'index_live_queuekey' => '19375', 'index_delay' => '2', @@ -182,6 +193,11 @@ class ConfigService return false; } + public function resourceLevel() + { + return $this->getAppValue('resource_level'); + } + /** * Get a value by key * diff --git a/lib/Service/SolrService.php b/lib/Service/SolrService.php index dc222c8..70f276b 100644 --- a/lib/Service/SolrService.php +++ b/lib/Service/SolrService.php @@ -522,20 +522,35 @@ class SolrService // if (key_exists('current_directory', $options)) // $query->setQuery('nextant_path:' . $helper->escapePhrase($options['current_directory'])); - $hl = $query->getHighlighting(); - $hl->setSimplePrefix('<span class="nextant_hl">'); - $hl->setSimplePostfix('</span>'); - $hl->setSnippets(4); - // $hl->setAlternateField('nextant_path'); - $hl->setFragSize(70); - $hl->setMaxAnalyzedChars(100000); - $hl->setFields(array( - 'text' - )); - // 'nextant_path' + $hl = null; + if ($this->configService->resourceLevel() > ConfigService::RESOURCE_LEVEL_LOWER) { + $hl = $query->getHighlighting(); + $hl->setSimplePrefix('<span class="nextant_hl">'); + $hl->setSimplePostfix('</span>'); + // $hl->setAlternateField('nextant_path'); + $hl->setFragSize(70); + + switch ($this->configService->resourceLevel()) { + case ConfigService::RESOURCE_LEVEL_LOW: + $hl->setSnippets(2); + $hl->setFragSize(100); + $hl->setMaxAnalyzedChars(50000); + break; + + case ConfigService::RESOURCE_LEVEL_HIGH: + $hl->setSnippets(4); + $hl->setMaxAnalyzedChars(100000); + break; + } + + $hl->setFields(array( + 'text' + )); + } $resultset = $client->select($query); - $highlighting = $resultset->getHighlighting(); + if ($hl !== null) + $highlighting = $resultset->getHighlighting(); $return = array(); foreach ($resultset as $document) { @@ -544,8 +559,10 @@ class SolrService $item->shared(($document->nextant_owner != $this->owner)); // highlighting - $hlDoc = $highlighting->getResult($document->id); - $item->setHighlighting($hlDoc->getField('text')); + if ($hl !== null) { + $hlDoc = $highlighting->getResult($document->id); + $item->setHighlighting($hlDoc->getField('text')); + } $return[] = $item; } diff --git a/templates/settings.admin.php b/templates/settings.admin.php index 6962383..72a2c1d 100644 --- a/templates/settings.admin.php +++ b/templates/settings.admin.php @@ -133,7 +133,6 @@ style('nextant', 'admin'); id="solr_index_files_federated" value="1" style="margin: 10px;"></td> </tr> - <tr style="height: 30px;"> <td class="nextant_admin_left"> <?php p($l->t('Index External Storage :')) ?></td> @@ -142,8 +141,6 @@ style('nextant', 'admin'); value="1" style="margin: 10px;"></td> </tr> - - <tr style="height: 30px;"> <td class="nextant_admin_left"> <?php p($l->t('Index Encrypted Files :')) ?></td> @@ -209,6 +206,20 @@ style('nextant', 'admin'); <tr style="height: 30px;"> <td class="nextant_admin_left"> + <?php p($l->t('Resource Level :')); ?> + </td> + <td colspan="2"><select name="solr_resource_level" + id="solr_resource_level"> + <!-- <option value="5">Higher Level</option> --> + <option value="4">High Level</option> + <!-- <option value="3">Mid level</option> --> + <option value="2">Low level</option> + <option value="1">Lower level</option> + </select></td> + </tr> + + <tr style="height: 30px;"> + <td class="nextant_admin_left"> <?php p($l->t('Live Index :')); ?> </td> <td colspan="2"><input type="checkbox" name="solr_index_live" |