Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
facets
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
facets
Merge requests
!7
Issue
#3190240
: SliderProcessor adding results when nothing found
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3190240
: SliderProcessor adding results when nothing found
issue/facets-3190240:3190240-sliderprocessor-adding-results
into
8.x-1.x
Overview
1
Commits
2
Pipelines
0
Changes
1
All threads resolved!
Show all comments
Open
Quentin Fahrner
requested to merge
issue/facets-3190240:3190240-sliderprocessor-adding-results
into
8.x-1.x
4 years ago
Overview
1
Commits
2
Pipelines
0
Changes
1
All threads resolved!
Show all comments
Expand
0
0
Merge request reports
Compare
8.x-1.x
version 1
531ca8f1
4 years ago
8.x-1.x (HEAD)
and
latest version
latest version
4944ab8d
2 commits,
4 years ago
version 1
531ca8f1
1 commit,
4 years ago
1 file
+
35
−
16
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
modules/facets_range_widget/src/Plugin/facets/processor/SliderProcessor.php
+
35
−
16
Options
@@ -25,44 +25,63 @@ class SliderProcessor extends ProcessorPluginBase implements PostQueryProcessorI
* {@inheritdoc}
*/
public
function
postQuery
(
FacetInterface
$facet
)
{
// Only consider facets with results.
$results
=
$facet
->
getResults
();
if
(
empty
(
$results
))
{
return
;
}
$widget
=
$facet
->
getWidgetInstance
();
$config
=
$widget
->
getConfiguration
();
$simple_results
=
[];
// Generate all the "results" between min and max, with the configured step.
foreach
(
$facet
->
getResults
()
as
$result
)
{
$simple_results
[
'f_'
.
(
float
)
$result
->
getRawValue
()]
=
[
'value'
=>
(
float
)
$result
->
getRawValue
(),
$simple_results
=
[];
foreach
(
$results
as
$result
)
{
$rawValue
=
(
float
)
$result
->
getRawValue
();
$simple_results
[
'f_'
.
$rawValue
]
=
[
'value'
=>
$rawValue
,
'count'
=>
(
int
)
$result
->
getCount
(),
];
}
uasort
(
$simple_results
,
function
(
$a
,
$b
)
{
uasort
(
$simple_results
,
static
function
(
$a
,
$b
)
{
if
(
$a
[
'value'
]
===
$b
[
'value'
])
{
return
0
;
}
return
$a
[
'value'
]
<
$b
[
'value'
]
?
-
1
:
1
;
});
$step
=
$config
[
'step'
];
if
(
$config
[
'min_type'
]
==
'fixed'
)
{
// Compute min.
$min
=
reset
(
$simple_results
)[
'value'
]
??
0
;
if
(
!
empty
(
$config
[
'min_type'
])
&&
$config
[
'min_type'
]
===
'fixed'
)
{
$min
=
$config
[
'min_value'
];
}
// Compute max.
$max
=
end
(
$simple_results
)[
'value'
]
??
0
;
if
(
!
empty
(
$config
[
'max_type'
])
&&
$config
[
'max_type'
]
===
'fixed'
)
{
$max
=
$config
[
'max_value'
];
}
else
{
$min
=
reset
(
$simple_results
)[
'value'
]
??
0
;
$max
=
end
(
$simple_results
)[
'value'
]
??
0
;
// If max is not divisible by step, we should add the remainder to max to
// make sure that we don't lose any possible values.
if
(
$max
%
$step
!==
0
)
{
$max
=
$max
+
(
$step
-
$max
%
$step
);
}
// Compute step.
if
(
!
empty
(
$config
[
'step'
])
&&
$config
[
'step'
]
>
0
)
{
$step
=
$config
[
'step'
];
}
else
{
$step
=
max
(
1
,
ceil
(
$max
/
100
));
}
// If max is not divisible by step, we should add the remainder to max to
// make sure that we don't lose any possible values.
if
(
$max
%
$step
!==
0
)
{
$max
+=
(
$step
-
$max
%
$step
);
}
// Creates an array of all results between min and max by the step from the
// configuration.
$new_results
=
[];
for
(
$i
=
$min
;
$i
<=
$max
;
$i
+=
$step
)
{
$count
=
isset
(
$simple_results
[
'f_'
.
$i
])
?
$simple_results
[
'f_'
.
$i
][
'count'
]
:
0
;
$new_result
=
$simple_results
[
'f_'
.
$i
]
??
NULL
;
$count
=
$new_result
!==
NULL
?
$new_result
[
'count'
]
:
0
;
$new_results
[]
=
new
Result
(
$facet
,
(
float
)
$i
,
(
float
)
$i
,
$count
);
}
Loading