Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
facets-3052574
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
facets-3052574
Commits
f684befe
Commit
f684befe
authored
6 years ago
by
Joris Vercammen
Committed by
Jimmy Henderickx
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/facets/query_type/SearchApiString.php
+7
-1
7 additions, 1 deletion
src/Plugin/facets/query_type/SearchApiString.php
tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
+49
-0
49 additions, 0 deletions
tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
with
56 additions
and
1 deletion
src/Plugin/facets/query_type/SearchApiString.php
+
7
−
1
View file @
f684befe
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
+
49
−
0
View file @
f684befe
...
...
@@ -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""'
],
];
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment