Skip to content
Snippets Groups Projects
Commit f684befe authored by Joris Vercammen's avatar Joris Vercammen Committed by Jimmy Henderickx
Browse files

Issue #2938735 by krystalcode, borisson_: Trimming double quotes that are part of the actual result

parent 27bbb504
No related branches found
No related tags found
No related merge requests found
......@@ -61,8 +61,14 @@ class SearchApiString extends QueryTypePluginBase {
$facet_results = [];
foreach ($this->results as $result) {
if ($result['count'] || $query_operator == 'or') {
$result_filter = $result['filter'];
if ($result_filter[0] === '"') {
$result_filter = substr($result_filter, 1);
}
if ($result_filter[strlen($result_filter) - 1] === '"') {
$result_filter = substr($result_filter, 0, -1);
}
$count = $result['count'];
$result_filter = trim($result['filter'], '"');
$result = new Result($this->facet, $result_filter, $result_filter, $count);
$facet_results[] = $result;
}
......
......@@ -138,4 +138,53 @@ class SearchApiStringTest extends UnitTestCase {
$this->assertEquals(['owl' => 'Long-eared owl'], $query_type->getConfiguration());
}
/**
* Tests trimming in ::build.
*
* @dataProvider provideTrimValues
*/
public function testTrim($expected_value, $input_value) {
$query = new SearchApiQuery([], 'search_api_query', []);
$facet = new Facet([], 'facets_facet');
$original_results = [['count' => 1, 'filter' => $input_value]];
$query_type = new SearchApiString(
[
'facet' => $facet,
'query' => $query,
'results' => $original_results,
],
'search_api_string',
[]
);
$built_facet = $query_type->build();
$this->assertInstanceOf(FacetInterface::class, $built_facet);
$results = $built_facet->getResults();
$this->assertInternalType('array', $results);
$this->assertInstanceOf(ResultInterface::class, $results[0]);
$this->assertEquals(1, $results[0]->getCount());
$this->assertEquals($expected_value, $results[0]->getDisplayValue());
}
/**
* Data provider for ::provideTrimValues
*
* @return array
* An array of expected and input values.
*/
public function provideTrimValues() {
return [
['owl', '"owl"'],
['owl', 'owl'],
['owl', '"owl'],
['owl', 'owl"'],
['"owl', '""owl"'],
['owl"', '"owl""'],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment