Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
96a273ab
Commit
96a273ab
authored
Mar 13, 2014
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #248 from adrienbrault/double-suggestion
Fix suggester parser with duplicates
parents
6cdc4983
c271e78a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
8 deletions
+71
-8
library/Solarium/QueryType/Suggester/ResponseParser.php
library/Solarium/QueryType/Suggester/ResponseParser.php
+23
-6
library/Solarium/QueryType/Suggester/Result/Result.php
library/Solarium/QueryType/Suggester/Result/Result.php
+19
-0
tests/Solarium/Tests/QueryType/Suggester/ResponseParserTest.php
...Solarium/Tests/QueryType/Suggester/ResponseParserTest.php
+15
-0
tests/Solarium/Tests/QueryType/Suggester/Result/ResultTest.php
.../Solarium/Tests/QueryType/Suggester/Result/ResultTest.php
+14
-2
No files found.
library/Solarium/QueryType/Suggester/ResponseParser.php
View file @
96a273ab
...
...
@@ -60,6 +60,7 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
$query
=
$result
->
getQuery
();
$suggestions
=
array
();
$allSuggestions
=
array
();
$collation
=
null
;
if
(
isset
(
$data
[
'spellcheck'
][
'suggestions'
])
&&
is_array
(
$data
[
'spellcheck'
][
'suggestions'
]))
{
...
...
@@ -74,12 +75,17 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
if
(
$term
==
'collation'
)
{
$collation
=
$termData
;
}
else
{
$suggestions
[
$term
]
=
new
$termClass
(
$termData
[
'numFound'
],
$termData
[
'startOffset'
],
$termData
[
'endOffset'
],
$termData
[
'suggestion'
]
);
if
(
!
array_key_exists
(
0
,
$termData
))
{
$termData
=
array
(
$termData
);
}
foreach
(
$termData
as
$currentTermData
)
{
$allSuggestions
[]
=
$this
->
createTerm
(
$termClass
,
$currentTermData
);
if
(
!
array_key_exists
(
$term
,
$suggestions
))
{
$suggestions
[
$term
]
=
$this
->
createTerm
(
$termClass
,
$currentTermData
);
}
}
}
}
}
...
...
@@ -88,8 +94,19 @@ class ResponseParser extends ResponseParserAbstract implements ResponseParserInt
$data
,
array
(
'results'
=>
$suggestions
,
'all'
=>
$allSuggestions
,
'collation'
=>
$collation
,
)
);
}
private
function
createTerm
(
$termClass
,
array
$termData
)
{
return
new
$termClass
(
$termData
[
'numFound'
],
$termData
[
'startOffset'
],
$termData
[
'endOffset'
],
$termData
[
'suggestion'
]
);
}
}
library/Solarium/QueryType/Suggester/Result/Result.php
View file @
96a273ab
...
...
@@ -69,6 +69,13 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
*/
protected
$results
;
/**
* Suggester flat results
*
* @var array
*/
protected
$all
;
/**
* Collation result
*
...
...
@@ -119,6 +126,18 @@ class Result extends BaseResult implements \IteratorAggregate, \Countable
return
$this
->
results
;
}
/**
* Get flat results
*
* @return array
*/
public
function
getAll
()
{
$this
->
parseResponse
();
return
$this
->
all
;
}
/**
* Get results for a specific term
*
...
...
tests/Solarium/Tests/QueryType/Suggester/ResponseParserTest.php
View file @
96a273ab
...
...
@@ -65,6 +65,15 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase
'video'
,
)
),
'vid'
,
array
(
'numFound'
=>
1
,
'startOffset'
=>
6
,
'endOffset'
=>
9
,
'suggestion'
=>
array
(
'video'
,
)
),
'collation'
,
'disk video'
),
...
...
@@ -88,8 +97,14 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase
'd'
=>
new
Term
(
2
,
3
,
7
,
array
(
'disk'
,
'ddr'
)),
'vid'
=>
new
Term
(
1
,
2
,
5
,
array
(
'video'
))
);
$allExpected
=
array
(
new
Term
(
2
,
3
,
7
,
array
(
'disk'
,
'ddr'
)),
new
Term
(
1
,
2
,
5
,
array
(
'video'
)),
new
Term
(
1
,
6
,
9
,
array
(
'video'
)),
);
$this
->
assertEquals
(
$expected
,
$result
[
'results'
]);
$this
->
assertEquals
(
$allExpected
,
$result
[
'all'
]);
$this
->
assertEquals
(
'disk video'
,
$result
[
'collation'
]);
}
}
tests/Solarium/Tests/QueryType/Suggester/Result/ResultTest.php
View file @
96a273ab
...
...
@@ -45,6 +45,11 @@ class ResultTest extends \PHPUnit_Framework_TestCase
*/
protected
$data
;
/**
* @var array
*/
protected
$allData
;
/**
* @var string
*/
...
...
@@ -56,8 +61,9 @@ class ResultTest extends \PHPUnit_Framework_TestCase
'term1'
=>
'data1'
,
'term2'
=>
'data2'
,
);
$this
->
allData
=
array_values
(
$this
->
data
);
$this
->
collation
=
'collation result'
;
$this
->
result
=
new
SuggesterDummy
(
$this
->
data
,
$this
->
collation
);
$this
->
result
=
new
SuggesterDummy
(
$this
->
data
,
$this
->
allData
,
$this
->
collation
);
}
public
function
testGetStatus
()
...
...
@@ -81,6 +87,11 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
$this
->
data
,
$this
->
result
->
getResults
());
}
public
function
testGetAll
()
{
$this
->
assertEquals
(
$this
->
allData
,
$this
->
result
->
getAll
());
}
public
function
testGetTerm
()
{
$this
->
assertEquals
(
$this
->
data
[
'term1'
],
$this
->
result
->
getTerm
(
'term1'
));
...
...
@@ -116,9 +127,10 @@ class SuggesterDummy extends Result
{
protected
$parsed
=
true
;
public
function
__construct
(
$results
,
$collation
)
public
function
__construct
(
$results
,
$
all
,
$
collation
)
{
$this
->
results
=
$results
;
$this
->
all
=
$all
;
$this
->
collation
=
$collation
;
$this
->
status
=
1
;
$this
->
queryTime
=
12
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment