Skip to content
Snippets Groups Projects
Commit 6a408eb3 authored by Demian Katz's avatar Demian Katz
Browse files

Make hl.fl setting configurable via searches.ini.

parent 25316285
No related merge requests found
...@@ -48,6 +48,10 @@ default_noresults_recommend[] = SwitchQuery ...@@ -48,6 +48,10 @@ default_noresults_recommend[] = SwitchQuery
; appear in fields displayed in search results. ; appear in fields displayed in search results.
highlighting = true highlighting = true
; Set this to restrict the list of fields that will be highlighted (the hl.fl
; Solr parameter); default = '*' for all fields:
;highlighting_fields = *
; Set this to true in order to include a text snippet in the search results when ; Set this to true in order to include a text snippet in the search results when
; a keyword match is found in a field that is not normally displayed as part of ; a keyword match is found in a field that is not normally displayed as part of
; the listing. For finer control over which fields are used for snippets, see ; the listing. For finer control over which fields are used for snippets, see
......
...@@ -43,6 +43,8 @@ use VuFindSearch\Backend\Solr\HandlerMap; ...@@ -43,6 +43,8 @@ use VuFindSearch\Backend\Solr\HandlerMap;
use VuFindSearch\Backend\Solr\Connector; use VuFindSearch\Backend\Solr\Connector;
use VuFindSearch\Backend\Solr\Backend; use VuFindSearch\Backend\Solr\Backend;
use Zend\Config\Config;
use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\FactoryInterface;
...@@ -161,11 +163,14 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -161,11 +163,14 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
{ {
$events = $this->serviceLocator->get('SharedEventManager'); $events = $this->serviceLocator->get('SharedEventManager');
// Load configurations:
$config = $this->config->get('config');
$search = $this->config->get($this->searchConfig);
// Highlighting // Highlighting
$this->getInjectHighlightingListener($backend)->attach($events); $this->getInjectHighlightingListener($backend, $search)->attach($events);
// Spellcheck // Spellcheck
$config = $this->config->get('config');
if (isset($config->Spelling->enabled) && $config->Spelling->enabled) { if (isset($config->Spelling->enabled) && $config->Spelling->enabled) {
if (isset($config->Spelling->simple) && $config->Spelling->simple) { if (isset($config->Spelling->simple) && $config->Spelling->simple) {
$dictionaries = array('basicSpell'); $dictionaries = array('basicSpell');
...@@ -177,7 +182,6 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -177,7 +182,6 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
} }
// Apply field stripping if applicable: // Apply field stripping if applicable:
$search = $this->config->get($this->searchConfig);
if (isset($search->StripFields) && isset($search->IndexShards)) { if (isset($search->StripFields) && isset($search->IndexShards)) {
$strip = $search->StripFields->toArray(); $strip = $search->StripFields->toArray();
foreach ($strip as $k => $v) { foreach ($strip as $k => $v) {
...@@ -344,11 +348,15 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface ...@@ -344,11 +348,15 @@ abstract class AbstractSolrBackendFactory implements FactoryInterface
* Get a highlighting listener for the backend * Get a highlighting listener for the backend
* *
* @param BackendInterface $backend Search backend * @param BackendInterface $backend Search backend
* @param Config $search Search configuration
* *
* @return InjectHighlightingListener * @return InjectHighlightingListener
*/ */
protected function getInjectHighlightingListener(BackendInterface $backend) protected function getInjectHighlightingListener(BackendInterface $backend,
{ Config $search
return new InjectHighlightingListener($backend); ) {
$fl = isset($search->General->highlighting_fields)
? $search->General->highlighting_fields : '*';
return new InjectHighlightingListener($backend, $fl);
} }
} }
\ No newline at end of file
...@@ -59,16 +59,25 @@ class InjectHighlightingListener ...@@ -59,16 +59,25 @@ class InjectHighlightingListener
*/ */
protected $active = false; protected $active = false;
/**
* Fields to highlight when active.
*
* @var string
*/
protected $fieldList;
/** /**
* Constructor. * Constructor.
* *
* @param BackendInterface $backend Backend * @param BackendInterface $backend Backend
* @param string $fieldList Field(s) to highlight (hl.fl param)
* *
* @return void * @return void
*/ */
public function __construct(BackendInterface $backend) public function __construct(BackendInterface $backend, $fieldList = '*')
{ {
$this->backend = $backend; $this->backend = $backend;
$this->fieldList = $fieldList;
} }
/** /**
...@@ -102,7 +111,7 @@ class InjectHighlightingListener ...@@ -102,7 +111,7 @@ class InjectHighlightingListener
if (!isset($hl[0]) || $hl[0] != 'false') { if (!isset($hl[0]) || $hl[0] != 'false') {
$this->active = true; $this->active = true;
$params->set('hl', 'true'); $params->set('hl', 'true');
$params->set('hl.fl', '*'); $params->set('hl.fl', $this->fieldList);
$params->set('hl.simple.pre', '{{{{START_HILITE}}}}'); $params->set('hl.simple.pre', '{{{{START_HILITE}}}}');
$params->set('hl.simple.post', '{{{{END_HILITE}}}}'); $params->set('hl.simple.post', '{{{{END_HILITE}}}}');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment