fixed AND problem
This commit is contained in:
parent
f5dae80cc6
commit
27c044f040
4 changed files with 18 additions and 11 deletions
|
|
@ -135,16 +135,16 @@
|
||||||
// normal submit which will redirect to the appropriate page.
|
// normal submit which will redirect to the appropriate page.
|
||||||
if (!settings.advanced_search_form.redirect) {
|
if (!settings.advanced_search_form.redirect) {
|
||||||
$form.submit(function (e) {
|
$form.submit(function (e) {
|
||||||
//e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
let inputs = $form.serializeArray();
|
let inputs = $form.serializeArray();
|
||||||
//console.log(inputs);
|
//console.log(inputs);
|
||||||
//let inputs = originalInputs.filter(function(el) {
|
//inputs = inputs.filter(function(el) {
|
||||||
// return !el.name.match(/terms\[\d+\]\[entity\]/);
|
// return !el.name.match(/terms\[\d+\]\[entity\]/);
|
||||||
//});
|
//});
|
||||||
|
|
||||||
//inputs = originalInputs;
|
//inputs = originalInputs;
|
||||||
console.log(inputs);
|
//console.log(inputs);
|
||||||
|
|
||||||
const href = url(inputs, settings.advanced_search_form);
|
const href = url(inputs, settings.advanced_search_form);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ class AdvancedSearchQuery {
|
||||||
// To support negative queries we must first bring in all documents.
|
// To support negative queries we must first bring in all documents.
|
||||||
$q[] = $this->negativeQuery($terms) ? "*:*" : "";
|
$q[] = $this->negativeQuery($terms) ? "*:*" : "";
|
||||||
}
|
}
|
||||||
|
$q[] = '(';
|
||||||
$term = array_shift($terms);
|
$term = array_shift($terms);
|
||||||
$q[] = $term->toSolrQuery($field_mapping);
|
$q[] = $term->toSolrQuery($field_mapping);
|
||||||
|
|
||||||
|
|
@ -180,7 +180,7 @@ class AdvancedSearchQuery {
|
||||||
|
|
||||||
// For multiple conditions.
|
// For multiple conditions.
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
$q[] = $term->getConjunction();
|
$q[] = ')' . $term->getConjunction() . '(';
|
||||||
$q[] = $term->toSolrQuery($field_mapping);
|
$q[] = $term->toSolrQuery($field_mapping);
|
||||||
|
|
||||||
// New.
|
// New.
|
||||||
|
|
@ -193,6 +193,8 @@ class AdvancedSearchQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$q[] = ')';
|
||||||
$q = implode(' ', $q);
|
$q = implode(' ', $q);
|
||||||
|
|
||||||
// Limit extra processing if Luncene Search is enable.
|
// Limit extra processing if Luncene Search is enable.
|
||||||
|
|
@ -291,7 +293,7 @@ class AdvancedSearchQuery {
|
||||||
// make this field non-empty.
|
// make this field non-empty.
|
||||||
//$search_api_query->keys("advanced search");
|
//$search_api_query->keys("advanced search");
|
||||||
}
|
}
|
||||||
|
dpm($q, "q");
|
||||||
$solarium_query->setQuery($q);
|
$solarium_query->setQuery($q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ class AdvancedSearchQueryTerm {
|
||||||
|
|
||||||
// Used for serializing / deserializing query parameters.
|
// Used for serializing / deserializing query parameters.
|
||||||
// These are also hard-coded in advanced_search.form.js.
|
// These are also hard-coded in advanced_search.form.js.
|
||||||
|
const ENTITY_QUERY_PARAMETER = 'e';
|
||||||
const CONJUNCTION_QUERY_PARAMETER = 'c';
|
const CONJUNCTION_QUERY_PARAMETER = 'c';
|
||||||
const FIELD_QUERY_PARAMETER = 'f';
|
const FIELD_QUERY_PARAMETER = 'f';
|
||||||
const INCLUDE_QUERY_PARAMETER = 'i';
|
const INCLUDE_QUERY_PARAMETER = 'i';
|
||||||
|
|
@ -284,7 +285,7 @@ class AdvancedSearchQueryTerm {
|
||||||
public function toSolrQuery(array $solr_field_mapping) {
|
public function toSolrQuery(array $solr_field_mapping) {
|
||||||
$terms = [];
|
$terms = [];
|
||||||
$query_helper = \Drupal::service('solarium.query_helper');
|
$query_helper = \Drupal::service('solarium.query_helper');
|
||||||
$value = $query_helper->escapePhrase(trim($this->value));
|
$value = $query_helper->escapePhrase($this->value);
|
||||||
|
|
||||||
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
|
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
|
||||||
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
|
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ class AdvancedSearchForm extends FormBase {
|
||||||
const OR_OP = 'OR';
|
const OR_OP = 'OR';
|
||||||
|
|
||||||
// These are also hard-coded in advanced_search.form.js.
|
// These are also hard-coded in advanced_search.form.js.
|
||||||
|
const ENTITY_FORM_FIELD = 'entity';
|
||||||
const CONJUNCTION_FORM_FIELD = 'conjunction';
|
const CONJUNCTION_FORM_FIELD = 'conjunction';
|
||||||
const SEARCH_FORM_FIELD = 'search';
|
const SEARCH_FORM_FIELD = 'search';
|
||||||
const INCLUDE_FORM_FIELD = 'include';
|
const INCLUDE_FORM_FIELD = 'include';
|
||||||
|
|
@ -172,6 +173,7 @@ class AdvancedSearchForm extends FormBase {
|
||||||
*/
|
*/
|
||||||
protected function defaultTermValues(array $options) {
|
protected function defaultTermValues(array $options) {
|
||||||
return [
|
return [
|
||||||
|
self::ENTITY_FORM_FIELD => 'ueberall',
|
||||||
self::CONJUNCTION_FORM_FIELD => self::AND_OP,
|
self::CONJUNCTION_FORM_FIELD => self::AND_OP,
|
||||||
// First item in list is default.
|
// First item in list is default.
|
||||||
self::SEARCH_FORM_FIELD => key($options),
|
self::SEARCH_FORM_FIELD => key($options),
|
||||||
|
|
@ -266,6 +268,7 @@ class AdvancedSearchForm extends FormBase {
|
||||||
'query_parameter' => AdvancedSearchQuery::getQueryParameter(),
|
'query_parameter' => AdvancedSearchQuery::getQueryParameter(),
|
||||||
'recurse_parameter' => AdvancedSearchQuery::getRecurseParameter(),
|
'recurse_parameter' => AdvancedSearchQuery::getRecurseParameter(),
|
||||||
'mapping' => [
|
'mapping' => [
|
||||||
|
self::ENTITY_FORM_FIELD => AdvancedSearchQueryTerm::ENTITY_QUERY_PARAMETER,
|
||||||
self::CONJUNCTION_FORM_FIELD => AdvancedSearchQueryTerm::CONJUNCTION_QUERY_PARAMETER,
|
self::CONJUNCTION_FORM_FIELD => AdvancedSearchQueryTerm::CONJUNCTION_QUERY_PARAMETER,
|
||||||
self::SEARCH_FORM_FIELD => AdvancedSearchQueryTerm::FIELD_QUERY_PARAMETER,
|
self::SEARCH_FORM_FIELD => AdvancedSearchQueryTerm::FIELD_QUERY_PARAMETER,
|
||||||
self::INCLUDE_FORM_FIELD => AdvancedSearchQueryTerm::INCLUDE_QUERY_PARAMETER,
|
self::INCLUDE_FORM_FIELD => AdvancedSearchQueryTerm::INCLUDE_QUERY_PARAMETER,
|
||||||
|
|
@ -285,6 +288,7 @@ class AdvancedSearchForm extends FormBase {
|
||||||
$first = $i == 0;
|
$first = $i == 0;
|
||||||
$term_value = !empty($term_values) ? array_shift($term_values) : $term_default_values;
|
$term_value = !empty($term_values) ? array_shift($term_values) : $term_default_values;
|
||||||
$conjunction = $term_value[self::CONJUNCTION_FORM_FIELD] ?? $term_default_values[self::CONJUNCTION_FORM_FIELD];
|
$conjunction = $term_value[self::CONJUNCTION_FORM_FIELD] ?? $term_default_values[self::CONJUNCTION_FORM_FIELD];
|
||||||
|
$entity = $term_value[self::ENTITY_FORM_FIELD] ?? $term_default_values[self::ENTITY_FORM_FIELD];
|
||||||
$term_elements[] = [
|
$term_elements[] = [
|
||||||
// Only show on terms after the first.
|
// Only show on terms after the first.
|
||||||
self::CONJUNCTION_FORM_FIELD => $first ? NULL : [
|
self::CONJUNCTION_FORM_FIELD => $first ? NULL : [
|
||||||
|
|
@ -299,7 +303,7 @@ class AdvancedSearchForm extends FormBase {
|
||||||
'#default_value' => $conjunction,
|
'#default_value' => $conjunction,
|
||||||
'#theme_wrappers' => [],
|
'#theme_wrappers' => [],
|
||||||
],
|
],
|
||||||
'entity' => [
|
self::ENTITY_FORM_FIELD => [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
'#attributes' => [
|
'#attributes' => [
|
||||||
'aria-label' => $this->t("Select Entity"),
|
'aria-label' => $this->t("Select Entity"),
|
||||||
|
|
@ -312,7 +316,7 @@ class AdvancedSearchForm extends FormBase {
|
||||||
'ba419826c9014f40126565bf413f7a59' => $this->t('Auktion'),
|
'ba419826c9014f40126565bf413f7a59' => $this->t('Auktion'),
|
||||||
'b65c3a85d16724d84a5eb0d2268629a6' => $this->t('Objekt'),
|
'b65c3a85d16724d84a5eb0d2268629a6' => $this->t('Objekt'),
|
||||||
],
|
],
|
||||||
//'#default_value' => 'alles',
|
'#default_value' => $entity,
|
||||||
],
|
],
|
||||||
self::SEARCH_FORM_FIELD => [
|
self::SEARCH_FORM_FIELD => [
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue