improved sapi_solr query condition on field_reference for multiple references
This commit is contained in:
parent
5dfb746132
commit
9f0b257c62
|
@ -23,6 +23,7 @@ class Base extends ControllerBase {
|
||||||
private $offset = 0;
|
private $offset = 0;
|
||||||
|
|
||||||
private function sapiQuery(){
|
private function sapiQuery(){
|
||||||
|
// https://www.drupal.org/docs/8/modules/search-api/developer-documentation/executing-a-search-in-code
|
||||||
$this->index = Index::load('database');
|
$this->index = Index::load('database');
|
||||||
$this->query = $this->index->query();
|
$this->query = $this->index->query();
|
||||||
|
|
||||||
|
@ -37,9 +38,13 @@ class Base extends ControllerBase {
|
||||||
// $this->query->setFulltextFields(['field_reference']);
|
// $this->query->setFulltextFields(['field_reference']);
|
||||||
|
|
||||||
// Set additional conditions.
|
// Set additional conditions.
|
||||||
// in case we search for material reference like W0117
|
// in case we search for material references like W0117
|
||||||
if (preg_match('/^[WTRPCMFGSO]\d{4}$/i', $this->keys, $matches)) {
|
if (preg_match_all('/[WTRPCMFGSO]\d{4}/i', $this->keys, $matches)) {
|
||||||
$this->query->addCondition('field_reference', $this->keys);
|
$conditions = $this->query->createConditionGroup('OR');
|
||||||
|
foreach ($matches[0] as $key => $value) {
|
||||||
|
$conditions->addCondition('field_reference', $value);
|
||||||
|
}
|
||||||
|
$this->query->addConditionGroup($conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restrict the search to specific languages.
|
// Restrict the search to specific languages.
|
||||||
|
|
Loading…
Reference in New Issue