Skip to content

Commit

Permalink
Merge pull request #175 from esmero/ISSUE-174
Browse files Browse the repository at this point in the history
ISSUE-174: adds a fixed "10" rows limit while previewing any Entity Reference Search API (solr) views
  • Loading branch information
DiegoPino authored May 21, 2024
2 parents 612861d + 16a0888 commit 796a51f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Plugin/views/display/EntityReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ public function query() {
$search_api_query = $this->view->query;

$this->id_field_alias = $this->view->query->addField($id_table, $id_field);
if (!empty($this->view->live_preview)) {
// We hate blind Views on the UI. Give it a starting Match so we can
// see the logic happening
}


// Make sure the id field is included in the results.
$id_field = $this->view->storage->get('base_field');
Expand All @@ -185,7 +182,13 @@ public function query() {
'limit' => 0,
'ids_solr' => NULL,
];

$options += $default_options;
if (!empty($this->view->live_preview)) {
// Reduce the limit bc if Search API Server (solr) has a higher limit, e.g 10K for VBO
// the the preview will fail
if (!$options['limit' ]) { $options['limit' ] = 10; }
}

// Restrict the autocomplete options based on what's been typed already.
if (isset($options['match_solr']) && !empty($options['match_solr'])) {
Expand Down Expand Up @@ -215,7 +218,10 @@ public function query() {
if (!empty($options['ids_solr'])) {
$search_api_query->addWhere(0, $id_field, $options['ids_solr'], 'IN');
}
$this->view->setItemsPerPage($options['limit']);
// If someone programaticall already set (e.g Open API) a limit, don't set 0 as limit
if (!$this->view->getItemsPerPage()) {
$this->view->setItemsPerPage($options['limit']);
}
}

/**
Expand Down

0 comments on commit 796a51f

Please # to comment.