View source
<?php
namespace Drupal\search_api_solr_legacy\Plugin\SolrConnector;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase;
use Solarium\Core\Client\Endpoint;
use Solarium\QueryType\Select\Query\Query;
class Solr36Connector extends SolrConnectorPluginBase {
public function defaultConfiguration() {
return [
'scheme' => 'http',
'host' => '',
'port' => 8983,
'path' => '/',
'core' => '.',
'skip_schema_check' => TRUE,
] + parent::defaultConfiguration();
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['core'] = [
'#type' => 'value',
'#value' => '.',
];
$form['path'] = [
'#type' => 'value',
'#value' => '/',
];
$form['workarounds']['skip_schema_check'] = [
'#type' => 'value',
'#value' => TRUE,
];
$form['advanced']['jts'] = [
'#type' => 'value',
'#value' => FALSE,
];
return $form;
}
public function search(Query $query, ?Endpoint $endpoint = NULL) {
$params = $query
->getParams();
if (!isset($params['q.op'])) {
$query
->addParam('q.op', 'OR');
}
return parent::search($query, $endpoint);
}
public function pingServer() {
return $this
->pingCore();
}
public function getServerInfo($reset = FALSE) {
return $this
->getCoreInfo($reset);
}
public function reloadCore() {
return FALSE;
}
public function coreRestGet($path, ?Endpoint $endpoint = NULL) {
if (preg_match('@^schema/([^/]+)@', $path, $matches)) {
if ('fieldtypes' === $matches[1]) {
return [
'fieldTypes' => [
'name' => 'Solr 3.6',
],
];
}
}
return [];
}
public function coreRestPost($path, $command_json = '', ?Endpoint $endpoint = NULL) {
return [];
}
public function serverRestGet($path) {
return [];
}
public function serverRestPost($path, $command_json = '') {
return [];
}
public function alterConfigFiles(array &$files, string $lucene_match_version, string $server_id = '') {
parent::alterConfigFiles($files, $lucene_match_version, $server_id);
if (version_compare($lucene_match_version, '4', '<')) {
if (isset($files['solrconfig.xml'])) {
$files['solrconfig.xml'] = str_replace('SEARCH_API_SOLR_SOLRCONFIG_INDEX', $files['solrconfig_index.xml'] ?? '', $files['solrconfig.xml']);
$files['solrconfig.xml'] = str_replace('SEARCH_API_SOLR_SOLRCONFIG_EXTRA', $files['solrconfig_extra.xml'] ?? '', $files['solrconfig.xml']);
unset($files['solrconfig_index.xml']);
unset($files['solrconfig_extra.xml']);
}
if (isset($files['schema.xml'])) {
$files['schema.xml'] = str_replace('SEARCH_API_SOLR_SCHEMA_EXTRA_FIELDS', $files['schema_extra_fields.xml'] ?? '', $files['schema.xml']);
$files['schema.xml'] = str_replace('SEARCH_API_SOLR_SCHEMA_EXTRA_TYPES', $files['schema_extra_types.xml'] ?? '', $files['schema.xml']);
unset($files['schema_extra_types.xml']);
unset($files['schema_extra_fields.xml']);
}
}
}
}