Skip to content

Commit

Permalink
[BUGFIX] Handle float values in options facet parser
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanowak authored and dkd-kaehm committed Oct 13, 2023
1 parent 22dee75 commit 8f2f567
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function getOptionsFromSolrResponse(string $facetName, ResponseAdapter
foreach ($response->facets->{$facetName}->buckets as $bucket) {
$optionValue = $bucket->val;
$optionCount = $bucket->count;
$optionsFromSolrResponse[$optionValue] = $optionCount;
$optionsFromSolrResponse[(string)$optionValue] = $optionCount;
}

return $optionsFromSolrResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace ApacheSolrForTypo3\Solr\Tests\Unit\Domain\Search\ResultSet\Facets\OptionBased\Options;

use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Facets\OptionBased\Options\OptionsFacetParser;
use ApacheSolrForTypo3\Solr\System\Solr\ResponseAdapter;
use ApacheSolrForTypo3\Solr\Tests\Unit\UnitTest;

class OptionsFacetParserTest extends UnitTest
{
/**
* @test
*/
public function canListFloatValuesAsOptionsFromSolrResponse(): void
{
$responseAdapter = new ResponseAdapter(
/* @lang JSON */
'{
"facets": {
"floatOptions": {
"buckets": [
{ "val": 0.001, "count": 1 },
{ "val": 0.002, "count": 2 },
{ "val": 0.003, "count": 3 }
]
}
}
}'
);
$optionsFacetParser = $this->getAccessibleMock(
OptionsFacetParser::class,
null,
[],
'',
false
);
/** @link OptionsFacetParser::getOptionsFromSolrResponse */
$optionsArray = $optionsFacetParser->_call(
'getOptionsFromSolrResponse',
'floatOptions',
$responseAdapter,
);
self::assertCount(3, $optionsArray, 'EXT:solr can not list floats in facets.');
}
}

0 comments on commit 8f2f567

Please sign in to comment.