Enable Edismax mode by default

Remove the case insensitive field config
This commit is contained in:
Kyle Huynh 2023-02-01 17:07:08 -05:00
parent 06cb1dc03d
commit df34155e27
3 changed files with 9 additions and 37 deletions

View file

@ -153,13 +153,14 @@ class AdvancedSearchQuery {
//$q[] = "{!boost b=boost_document}";
// create a flag for active/inactive dismax
$isDismax = false;
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
if (!isset($isDismax))
$isDismax = true;
$isSearchAllFields = false;
$fields_list = [];
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
// To support negative queries we must first bring in all documents.
$q[] = $this->negativeQuery($terms) ? "*:*" : "";
$term = array_shift($terms);
@ -194,7 +195,6 @@ class AdvancedSearchQuery {
// Limit extra processing if Luncene Search is enable
if ($isDismax) {
$case_insensitive_field = $this::getConfig(SettingsForm::SOLR_CASE_INSENSITIVE_FIELD_PREFIX, '');
if ((strpos($q, "*") !== false || strpos($q, "?") !== false)) {
// if the query string contain '*', '?', OR is a single world, enable wildcard
@ -210,16 +210,6 @@ class AdvancedSearchQuery {
|| (strpos($item, "ss_") === 0)
)){
array_push($query_fields, '('.$item. ':'. $tmp .')');
// Add case insensitive fields in the query search fields
if ($case_insensitive_field !== '') {
$item_prefix = substr($item, 0, 3);
if ($item_prefix == "ss_" || $item_prefix == "sm_") {
$case_insensitive_item = str_replace($item_prefix,$case_insensitive_field, $item);
array_push($query_fields, '('.$case_insensitive_item. ':'. $tmp .')');
}
}
}
}
}
@ -240,14 +230,6 @@ class AdvancedSearchQuery {
// bs_ are boolean fields, do not work well with text search
if (substr($item, 0, 3) !== "bs_") {
array_push($query_fields, $item);
if ($case_insensitive_field !== '') {
$item_prefix = substr($item, 0, 3);
if ($item_prefix == "ss_" || $item_prefix == "sm_") {
$case_insensitive_item = str_replace($item_prefix,$case_insensitive_field, $item);
array_push($query_fields, $case_insensitive_item);
}
}
}
}
}

View file

@ -287,6 +287,9 @@ class AdvancedSearchQueryTerm {
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
if (!isset($isDismax)){
$isDismax = true;
}
if ($isDismax || $this->field === "all") {

View file

@ -22,7 +22,6 @@ class SettingsForm extends ConfigFormBase {
const SEARCH_ADD_OPERATOR = 'search_add_operator';
const SEARCH_REMOVE_OPERATOR = 'search_remove_operator';
const FACET_TRUNCATE = 'facet_truncate';
const SOLR_CASE_INSENSITIVE_FIELD_PREFIX = "case_insensitive_solr_field_prefix";
const EDISMAX_SEARCH_FLAG = 'lucene_on_off';
const EDISMAX_SEARCH_LABEL = 'lucene_label';
const SEARCH_ALL_FIELDS_FLAG = 'all_fields_on_off';
@ -104,16 +103,6 @@ class SettingsForm extends ConfigFormBase {
'#min' => 1,
],
],
'solr_case_insensitive_field_prefix' => [
'#type' => 'fieldset',
'#title' => $this->t('Case Insensitive Search'),
self::SOLR_CASE_INSENSITIVE_FIELD_PREFIX => [
'#type' => 'textfield',
'#title' => $this->t('Prefix for Solr Case Insensitive Field'),
'#description' => $this->t('If you have configured case insenstive fields, please specify the prefix here (i.e sss_lowercase_)'),
'#default_value' => self::getConfig(self::SOLR_CASE_INSENSITIVE_FIELD_PREFIX, ""),
],
],
];
$form['edismax'] = [
@ -125,7 +114,7 @@ class SettingsForm extends ConfigFormBase {
'#type' => 'checkbox',
'#title' => $this
->t('Enable Extended DisMax Query.'),
'#default_value' => self::getConfig(self::EDISMAX_SEARCH_FLAG, 0),
'#default_value' => self::getConfig(self::EDISMAX_SEARCH_FLAG, 1),
'#ajax' => [
'callback' => '::LuceneSearchEnableDisableCallback',
'wrapper' => 'edismax-container',
@ -138,7 +127,6 @@ class SettingsForm extends ConfigFormBase {
'#attributes' => ['id' => 'edismax-container'],
];
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] = [
@ -169,7 +157,6 @@ class SettingsForm extends ConfigFormBase {
->set(self::SEARCH_ADD_OPERATOR, $form_state->getValue(self::SEARCH_ADD_OPERATOR))
->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::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))