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.
|
||||
if (!settings.advanced_search_form.redirect) {
|
||||
$form.submit(function (e) {
|
||||
//e.preventDefault();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
let inputs = $form.serializeArray();
|
||||
//console.log(inputs);
|
||||
//let inputs = originalInputs.filter(function(el) {
|
||||
//inputs = inputs.filter(function(el) {
|
||||
// return !el.name.match(/terms\[\d+\]\[entity\]/);
|
||||
//});
|
||||
|
||||
//inputs = originalInputs;
|
||||
console.log(inputs);
|
||||
//console.log(inputs);
|
||||
|
||||
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.
|
||||
$q[] = $this->negativeQuery($terms) ? "*:*" : "";
|
||||
}
|
||||
|
||||
$q[] = '(';
|
||||
$term = array_shift($terms);
|
||||
$q[] = $term->toSolrQuery($field_mapping);
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ class AdvancedSearchQuery {
|
|||
|
||||
// For multiple conditions.
|
||||
foreach ($terms as $term) {
|
||||
$q[] = $term->getConjunction();
|
||||
$q[] = ')' . $term->getConjunction() . '(';
|
||||
$q[] = $term->toSolrQuery($field_mapping);
|
||||
|
||||
// New.
|
||||
|
|
@ -193,6 +193,8 @@ class AdvancedSearchQuery {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
$q[] = ')';
|
||||
$q = implode(' ', $q);
|
||||
|
||||
// Limit extra processing if Luncene Search is enable.
|
||||
|
|
@ -257,7 +259,7 @@ class AdvancedSearchQuery {
|
|||
foreach ($index->getFields() as $field_id => $field) {
|
||||
$boostedFields[$field_id] = $field->getBoost();
|
||||
}
|
||||
|
||||
|
||||
$str_fields_with_boost = "";
|
||||
// Adding a boost number for each field)
|
||||
foreach($query_fields as $solr_field) {
|
||||
|
|
@ -291,7 +293,7 @@ class AdvancedSearchQuery {
|
|||
// make this field non-empty.
|
||||
//$search_api_query->keys("advanced search");
|
||||
}
|
||||
|
||||
dpm($q, "q");
|
||||
$solarium_query->setQuery($q);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class AdvancedSearchQueryTerm {
|
|||
|
||||
// Used for serializing / deserializing query parameters.
|
||||
// These are also hard-coded in advanced_search.form.js.
|
||||
const ENTITY_QUERY_PARAMETER = 'e';
|
||||
const CONJUNCTION_QUERY_PARAMETER = 'c';
|
||||
const FIELD_QUERY_PARAMETER = 'f';
|
||||
const INCLUDE_QUERY_PARAMETER = 'i';
|
||||
|
|
@ -284,7 +285,7 @@ class AdvancedSearchQueryTerm {
|
|||
public function toSolrQuery(array $solr_field_mapping) {
|
||||
$terms = [];
|
||||
$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);
|
||||
$isDismax = $config->get(SettingsForm::EDISMAX_SEARCH_FLAG);
|
||||
|
|
@ -345,7 +346,7 @@ class AdvancedSearchQueryTerm {
|
|||
foreach ($keys as $key) {
|
||||
|
||||
if ($i != count($keys) - 1) {
|
||||
$str .= $field . ':"' . $key . '" AND ';
|
||||
$str .= $field . ':"' . $key . '" AND ';
|
||||
}
|
||||
else {
|
||||
$str .= $field . ':"' . $key . '")';
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class AdvancedSearchForm extends FormBase {
|
|||
const OR_OP = 'OR';
|
||||
|
||||
// These are also hard-coded in advanced_search.form.js.
|
||||
const ENTITY_FORM_FIELD = 'entity';
|
||||
const CONJUNCTION_FORM_FIELD = 'conjunction';
|
||||
const SEARCH_FORM_FIELD = 'search';
|
||||
const INCLUDE_FORM_FIELD = 'include';
|
||||
|
|
@ -172,6 +173,7 @@ class AdvancedSearchForm extends FormBase {
|
|||
*/
|
||||
protected function defaultTermValues(array $options) {
|
||||
return [
|
||||
self::ENTITY_FORM_FIELD => 'ueberall',
|
||||
self::CONJUNCTION_FORM_FIELD => self::AND_OP,
|
||||
// First item in list is default.
|
||||
self::SEARCH_FORM_FIELD => key($options),
|
||||
|
|
@ -266,6 +268,7 @@ class AdvancedSearchForm extends FormBase {
|
|||
'query_parameter' => AdvancedSearchQuery::getQueryParameter(),
|
||||
'recurse_parameter' => AdvancedSearchQuery::getRecurseParameter(),
|
||||
'mapping' => [
|
||||
self::ENTITY_FORM_FIELD => AdvancedSearchQueryTerm::ENTITY_QUERY_PARAMETER,
|
||||
self::CONJUNCTION_FORM_FIELD => AdvancedSearchQueryTerm::CONJUNCTION_QUERY_PARAMETER,
|
||||
self::SEARCH_FORM_FIELD => AdvancedSearchQueryTerm::FIELD_QUERY_PARAMETER,
|
||||
self::INCLUDE_FORM_FIELD => AdvancedSearchQueryTerm::INCLUDE_QUERY_PARAMETER,
|
||||
|
|
@ -285,6 +288,7 @@ class AdvancedSearchForm extends FormBase {
|
|||
$first = $i == 0;
|
||||
$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];
|
||||
$entity = $term_value[self::ENTITY_FORM_FIELD] ?? $term_default_values[self::ENTITY_FORM_FIELD];
|
||||
$term_elements[] = [
|
||||
// Only show on terms after the first.
|
||||
self::CONJUNCTION_FORM_FIELD => $first ? NULL : [
|
||||
|
|
@ -299,7 +303,7 @@ class AdvancedSearchForm extends FormBase {
|
|||
'#default_value' => $conjunction,
|
||||
'#theme_wrappers' => [],
|
||||
],
|
||||
'entity' => [
|
||||
self::ENTITY_FORM_FIELD => [
|
||||
'#type' => 'select',
|
||||
'#attributes' => [
|
||||
'aria-label' => $this->t("Select Entity"),
|
||||
|
|
@ -312,7 +316,7 @@ class AdvancedSearchForm extends FormBase {
|
|||
'ba419826c9014f40126565bf413f7a59' => $this->t('Auktion'),
|
||||
'b65c3a85d16724d84a5eb0d2268629a6' => $this->t('Objekt'),
|
||||
],
|
||||
//'#default_value' => 'alles',
|
||||
'#default_value' => $entity,
|
||||
],
|
||||
self::SEARCH_FORM_FIELD => [
|
||||
'#type' => 'select',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue