Problem/Motivation

In D7, there was an exposed option for the hard limit on facets. That doesn't seem to exist in D8. Please bring it back.

Proposed resolution

Remaining tasks

User interface changes

Add a dropdown with hard limit options:

API changes

Data model changes

Add a setting per facet for the hard_limit (integer)

Comments

edysmp created an issue. See original summary.

mpp’s picture

StatusFileSize
new67.33 KB
mpp’s picture

in SearchApiString we need to change the 50 with a config value for each facet:

      // Set the options for the actual query.
      $options = &$query->getOptions();

      $options['search_api_facets'][$field_identifier] = array(
        'field' => $field_identifier,
        'limit' => 50,
        'operator' => $this->facet->getQueryOperator(),
        'min_count' => 0,
        'missing' => FALSE,
      );
mpp’s picture

Issue summary: View changes
dragos-dumi’s picture

Assigned: Unassigned » dragos-dumi
dragos-dumi’s picture

I've attached a patch for hard limit configuration.

We need a test for this.

dragos-dumi’s picture

Assigned: dragos-dumi » Unassigned
Status: Active » Needs review
borisson_’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
borisson_’s picture

We discussed this at Drupalcon and figure that we can commit this after we have a test for this.

borisson_’s picture

Priority: Normal » Major

@Alienpruts had an actual issue with the limit of 50 over in #2815169: OR in facet always returns 50 results.

I'd say that makes this a very important issue.

+++ b/src/Form/FacetForm.php
@@ -373,6 +373,15 @@ public function form(array $form, FormStateInterface $form_state) {
+    $hard_limit_options = [3, 5, 10, 15, 20, 30, 40, 50, 75, 100];

I guess that also means we have to up the limit here. Let's add a couple of extra settings here; 250, 500. I don't think adding more is a good idea.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.9 KB
new5.56 KB

Adds an integration test and the additional config for more items.

borisson_’s picture

StatusFileSize
new477 bytes
new5.65 KB
borisson_’s picture

Issue tags: -Needs tests

This now has test-coverage, so removing the tag. Leaving this open for reviews.

Alienpruts’s picture

I can confirm the hard limit has been exposed and tested it with some values on a 300+ result set. No problems found :) .

heddn’s picture

Status: Needs review » Needs work
+++ b/src/Tests/IntegrationTest.php
@@ -601,6 +601,38 @@ class IntegrationTest extends WebTestBase {
+    $edit['facet_settings[hard_limit]'] = 3;
...
+    $this->assertText('Displaying 5 search results');

If we set a limit of 3, why are we still showing 5 search results?

borisson_’s picture

We set the limit only for the facets, not for the actual results.

heddn’s picture

Status: Needs work » Reviewed & tested by the community

Can we add that as a comment to the test? It is a nit, so I'm going to move to RTBC and it can be fixed on commit or in a re-roll.

strykaizer’s picture

Status: Reviewed & tested by the community » Needs work

I just tested this with search_api_db backend, and it did not limit the facet item count.
This might be a search_api_db issue though, maybe related to #2809753: getFacets in search_api_db returns wrong resultset (not sure)

Is this also tested with core_search as backend? Would be nice to have test coverage for both

borisson_’s picture

I haven't tested it with core search yet no. I'll try to write a test that does that this weekend.

borisson_’s picture

StatusFileSize
new3.4 KB
new9.05 KB

Stopping for the day. didn't get the core test to work yet :(

borisson_’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: expose_hard_facet_limit-2784349-20.patch, failed testing.

The last submitted patch, 20: expose_hard_facet_limit-2784349-20.patch, failed testing.

borisson_’s picture

This currently doesn't work for core search, and I don't think it'll be easy to do so. Let's add a description or only show this option for search api based queries on top of #12?

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new6.1 KB

Status: Needs review » Needs work

The last submitted patch, 25: expose_hard_facet_limit-2784349-25.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review

Back to NR.

mpp’s picture

Atm I can't apply this patch as it's conflicting with "hierarchical structures" in #2807333 which I'm using..

I'll see if I can test is later but since this is where the magic happens, I'm quite confident it will work:

-        'limit' => 50,
+        'limit' => $this->facet->getHardLimit(),

One thought though: I assume this won't scale for hard limit settings of 1000+?

borisson_’s picture

Building a system with 500+ items per facet is a very big one, not sure if we can support that - as that'd probably be really really slow.
It's still possible doing a form-alter and adding more items in the dropdown in the UI.

borisson_’s picture

StatusFileSize
new6.45 KB

Patch no longer applied.

Status: Needs review » Needs work

The last submitted patch, 30: expose_hard_facet_limit-2784349-30.patch, failed testing.

borisson_’s picture

Status: Needs work » Fixed

Committed, thanks for the issues, patches and reviews.

  • borisson_ committed 8b9819f on 8.x-1.x
    Issue #2784349 by borisson_, dragos-dumi, mpp: Expose hard facet limit...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.