Skip to content

Commit

Permalink
Bugfix for facet queries with local parameters (#937)
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Kalkbrenner <git@kalki.de>
  • Loading branch information
thomascorthals and mkalkbrenner committed Jun 28, 2021
1 parent 090c447 commit 802c69c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Query a single term in a Managed Resource

### Fixed
- Syntax error in request with facet queries that contain local parameters
- HEAD requests could lead to timeouts with cURL adapter

### Changed
Expand Down
11 changes: 10 additions & 1 deletion src/Component/RequestBuilder/FacetSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,18 @@ public function addFacetField(Request $request, FacetField $facet, bool $useLoca
*/
public function addFacetQuery($request, $facet): void
{
$localParams = $facet->getLocalParameters()->render();
$query = $facet->getQuery();

// add local params to those already present in the query, e.g. a qparser
if (null !== $localParams && null !== $query && 0 === strpos($query, '{!')) {
$localParams = strstr($query, '}', true).' '.substr($localParams, 2);
$query = substr($query, strpos($query, '}') + 1);
}

$request->addParam(
'facet.query',
sprintf('%s%s', $facet->getLocalParameters()->render(), $facet->getQuery())
sprintf('%s%s', $localParams, $query)
);
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Component/RequestBuilder/FacetSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,26 @@ public function testBuildWithIntervalFacet()
urldecode($request->getUri())
);
}

public function testBuildWithQueryFacetWithQparser()
{
$facet = new FacetQuery(
[
'local_key' => 'f1',
'query' => '{!frange l=100 u=200}price',
]
);

$this->component->addFacet($facet);

$request = $this->builder->buildComponent($this->component, $this->request);

$this->assertNull($request->getRawData());
$this->assertEquals(
'?facet.query={!frange l=100 u=200 key=f1}price&facet=true',
urldecode($request->getUri())
);
}
}

class UnknownFacet extends FacetField
Expand Down

0 comments on commit 802c69c

Please sign in to comment.