Enabled edismax for field search as well

Change wording in configiration view
This commit is contained in:
Kyle Huynh 2023-01-31 11:20:28 -05:00
parent 083add1792
commit d8a87ce0da
4 changed files with 128 additions and 59 deletions

View file

@ -103,14 +103,24 @@ class AdvancedSearchForm extends FormBase {
return self::getConfig(SettingsForm::SEARCH_REMOVE_OPERATOR, self::DEFAULT_REMOVE_OP);
}
/**
* Get if Lucene Search checkbox is enabled or disable
/**
* Get if Edismax Search checkbox is enabled or disable
*
* @return boolean
*
*/
public static function getLuceneSearch() {
return self::getConfig(SettingsForm::LUCENE_SEARCH_FLAG, 0);
public static function getSearchAllFields() {
return self::getConfig(SettingsForm::SEARCH_ALL_FIELDS_FLAG, 0);
}
/**
* Get if Edismax Search checkbox is enabled or disable
*
* @return boolean
*
*/
public static function getEdismaxSearch() {
return self::getConfig(SettingsForm::EDISMAX_SEARCH_FLAG, 0);
}
/**
@ -119,8 +129,8 @@ class AdvancedSearchForm extends FormBase {
* @return string
* The character to use for removing an facet to the query.
*/
public static function getLuceneSearchLabel() {
return self::getConfig(SettingsForm::LUCENE_SEARCH_LABEL, "All");
public static function getEdismaxSearchLabel() {
return self::getConfig(SettingsForm::EDISMAX_SEARCH_LABEL, "All");
}
/**
@ -263,7 +273,7 @@ class AdvancedSearchForm extends FormBase {
],
];
$options = (self::getLuceneSearch()) ? ["all" => self::getLuceneSearchLabel()] + $this->fieldOptions($fields) : $this->fieldOptions($fields);
$options = (self::getEdismaxSearch() && self::getSearchAllFields()) ? ["all" => self::getEdismaxSearchLabel()] + $this->fieldOptions($fields) : $this->fieldOptions($fields);
$term_default_values = $this->defaultTermValues($options);
list($recursive, $term_values) = $this->processInput($form_state, $term_default_values);
$i = 0;

View file

@ -23,8 +23,9 @@ class SettingsForm extends ConfigFormBase {
const SEARCH_REMOVE_OPERATOR = 'search_remove_operator';
const FACET_TRUNCATE = 'facet_truncate';
const SOLR_CASE_INSENSITIVE_FIELD_PREFIX = "case_insensitive_solr_field_prefix";
const LUCENE_SEARCH_FLAG = 'lucene_on_off';
const LUCENE_SEARCH_LABEL = 'lucene_label';
const EDISMAX_SEARCH_FLAG = 'lucene_on_off';
const EDISMAX_SEARCH_LABEL = 'lucene_label';
const SEARCH_ALL_FIELDS_FLAG = 'all_fields_on_off';
/**
* Constructs a \Drupal\system\ConfigFormBase object.
@ -115,34 +116,42 @@ class SettingsForm extends ConfigFormBase {
],
];
$form['lucene'] = [
$form['edismax'] = [
'#type' => 'fieldset',
'#title' => $this->t(" Solr's Standard Query parser (also known as 'lucene')"),
'#title' => $this->t("Extended DisMax Query"),
];
$form['lucene'][self::LUCENE_SEARCH_FLAG] = [
$form['edismax'][self::EDISMAX_SEARCH_FLAG] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Lucene Search.'),
'#default_value' => self::getConfig(self::LUCENE_SEARCH_FLAG, 0),
->t('Enable Extended DisMax Query.'),
'#default_value' => self::getConfig(self::EDISMAX_SEARCH_FLAG, 0),
'#ajax' => [
'callback' => '::LuceneSearchEnableDisableCallback',
'wrapper' => 'lucene-container',
'wrapper' => 'edismax-container',
'effect' => 'fade',
],
];
$form['lucene']['textfields_container'] = [
$form['edismax']['textfields_container'] = [
'#type' => 'container',
'#attributes' => ['id' => 'lucene-container'],
'#attributes' => ['id' => 'edismax-container'],
];
if (self::getConfig(self::LUCENE_SEARCH_FLAG, "All") === 1
|| $form_state->getValue(self::LUCENE_SEARCH_FLAG) === 1) {
$form['lucene']['textfields_container'][self::LUCENE_SEARCH_LABEL] = [
if (self::getConfig(self::EDISMAX_SEARCH_FLAG, "All") === 1
|| $form_state->getValue(self::EDISMAX_SEARCH_FLAG) === 1) {
$form['edismax']['textfields_container'][self::SEARCH_ALL_FIELDS_FLAG] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable searching all fields'),
'#default_value' => self::getConfig(self::SEARCH_ALL_FIELDS_FLAG, 0),
];
$form['edismax']['textfields_container'][self::EDISMAX_SEARCH_LABEL] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#title' => $this->t('If enabled, set the label for the option of searching all fields'),
'#description' => $this->t('This label will be appear in Search Terms dropdown of Advanced Search form block if Lucene Search is enabled.'),
'#default_value' => self::getConfig(self::LUCENE_SEARCH_LABEL, "All"),
'#default_value' => self::getConfig(self::EDISMAX_SEARCH_LABEL, "All"),
];
}
@ -161,9 +170,9 @@ class SettingsForm extends ConfigFormBase {
->set(self::SEARCH_REMOVE_OPERATOR, $form_state->getValue(self::SEARCH_REMOVE_OPERATOR))
->set(self::FACET_TRUNCATE, $form_state->getValue(self::FACET_TRUNCATE))
->set(self::SOLR_CASE_INSENSITIVE_FIELD_PREFIX, $form_state->getValue(self::SOLR_CASE_INSENSITIVE_FIELD_PREFIX))
->set(self::LUCENE_SEARCH_FLAG, $form_state->getValue(self::LUCENE_SEARCH_FLAG))
->set(self::LUCENE_SEARCH_LABEL, $form_state->getValue(self::LUCENE_SEARCH_LABEL))
->set(self::EDISMAX_SEARCH_FLAG, $form_state->getValue(self::EDISMAX_SEARCH_FLAG))
->set(self::EDISMAX_SEARCH_LABEL, $form_state->getValue(self::EDISMAX_SEARCH_LABEL))
->set(self::SEARCH_ALL_FIELDS_FLAG, $form_state->getValue(self::SEARCH_ALL_FIELDS_FLAG))
->save();
parent::submitForm($form, $form_state);
}
@ -175,6 +184,6 @@ class SettingsForm extends ConfigFormBase {
* returns it as a form (renderable array).
*/
public function LuceneSearchEnableDisableCallback($form, FormStateInterface $form_state) {
return $form['lucene']['textfields_container'];
return $form['edismax']['textfields_container'];
}
}