From 1c47278ae5fd7f3e29bab780d906aa4751f2030b Mon Sep 17 00:00:00 2001 From: bach Date: Mon, 15 Aug 2022 17:30:59 +0200 Subject: [PATCH] fix #1816 solr too many boolean clauses --- .../materio_sapi/src/Controller/Base.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/web/modules/custom/materio_sapi/src/Controller/Base.php b/web/modules/custom/materio_sapi/src/Controller/Base.php index fda542a0..d413e578 100644 --- a/web/modules/custom/materio_sapi/src/Controller/Base.php +++ b/web/modules/custom/materio_sapi/src/Controller/Base.php @@ -169,12 +169,13 @@ class Base extends ControllerBase { $this->or_query->keys(implode(' ', $this->keys)); } - // exclude results from and_query - $exclude_and_results_conditions = $this->or_query->createConditionGroup('AND'); - foreach ($this->results['nids'] as $nid) { - $exclude_and_results_conditions->addCondition('nid', $nid, '<>'); - } - $this->or_query->addConditionGroup($exclude_and_results_conditions); + // // exclude results from previous and_query + // !! trigering solr "too many boolean clauses" error + // $exclude_and_results_conditions = $this->or_query->createConditionGroup('AND'); + // foreach ($this->results['nids'] as $nid) { + // $exclude_and_results_conditions->addCondition('nid', $nid, '<>'); + // } + // $this->or_query->addConditionGroup($exclude_and_results_conditions); if (preg_match_all('/[WTRPCMFGSO]\d{4}/i', implode(' ', $this->keys), $matches)) { // in case we search for material references like W0117 @@ -226,8 +227,12 @@ class Base extends ControllerBase { $or_results = $this->or_query->execute(); foreach ($or_results as $result) { - $this->results['uuids'][] = $result->getField('uuid')->getValues()[0]; - $this->results['nids'][] = $result->getField('nid')->getValues()[0]; + $nid = $result->getField('nid')->getValues()[0]; + // !! have to remove duplicates instead of $exclude_and_results_conditions (solr too many boolean clauses) + if ( !in_array($nid, $this->results['nids']) ) { + $this->results['uuids'][] = $result->getField('uuid')->getValues()[0]; + $this->results['nids'][] = $nid; + } } // todo you may like / more like this