Facet results are wrapped in double quotes, and to properly display them without them double quotes are trimmed.

$result_filter = trim($result['filter'], '"');

This piece of code however trims all double quotes at the beginning and end of the result, even if they are part of the actual result. This can happen for example in the case of having a Width filter with string results in inches like 25".

The following patch more intelligently trims only one double quote at the beginning/end of the result.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

krystalcode created an issue. See original summary.

krystalcode’s picture

Status: Active » Needs review
FileSize
1.68 KB

Patch attached.

Status: Needs review » Needs work
borisson_’s picture

Looks like this patch doesn't apply, what version was this made against? Can you try doing this against the latest dev-release?

borisson_’s picture

Status: Needs work » Needs review
FileSize
2.68 KB

Not sure why the changes in QueryString were needed, this should do the same. There is also a test now, that verifies that this works as it should.

StryKaizer’s picture

Status: Needs review » Reviewed & tested by the community

  • StryKaizer committed f684bef on 8.x-1.x authored by borisson_
    Issue #2938735 by krystalcode, borisson_: Trimming double quotes that...
StryKaizer’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

TrevorBradley’s picture

This patch doesn't work for me, specifically because @krystalcode's changes to QueryString weren't kept as part of the patch.

The issue is that QueryString calls UrlProcessorPluginBase::setActiveItems, which still trims quotation marks BEFORE the code even gets over to SearchApiString. By the time the results get over to SearchApiString, they're already empty.

Since QueryString extends UrlProcessorPluginBase, it's possible to modify setActiveItems here to be kinder to dangling quotes.

It's likely the changes to SearchApiString are also requried. Investigating...

TrevorBradley’s picture

OK, something is real screwy here.

Developing against 8.x-1.2: If I modify UrlPluginProcessorPluginBase::setActiveItems as per @krystalcode's suggestions:

  public function setActiveItems(FacetInterface $facet) {
    // Get the filter key of the facet.
    if (isset($this->activeFilters[$facet->id()])) {
      foreach ($this->activeFilters[$facet->id()] as $value) {
        //$facet->setActiveItem(trim($value, '"'));
        if ($value[0] === '"')  {
          $value = substr($value, 1);
          if ($value[strlen($value) - 1] === '"') {
            $value = substr($value, 0, -1);
          }
        }
        $facet->setActiveItem($value);
      }
    }
  }

This works perfectly, without any changes whatsoever to SearchApiString at all. My filters against strings that end in a quote work perfectly.

Obviously this is a closed isse, but I think it doesn't solve the core issue. Worse yet, it may be attempting to resolve the issue in the wrong file.

On my own site, I'm going to resolve this by extending the QueryString plugin to add in this modified setActiveItems, but I think there's still a fundamental issue here with facets dev. Not sure how to start resolving it - start a new issue so there's a new codebase to develop against?

TrevorBradley’s picture

Since this is closed, I decided to adapt #3020427: Allow unpaired quotes on facet search fields into a new patch. This can stay closed.