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
acfbc18e
Commit
acfbc18e
authored
Jul 11, 2012
by
Albert Casademont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add multiple collations to the Spellcheck Response Parser
parent
7b57f3e2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
22 deletions
+63
-22
examples/2.1.5.9-spellcheck.php
examples/2.1.5.9-spellcheck.php
+8
-5
library/Solarium/Client/ResponseParser/Select/Component/Spellcheck.php
...ium/Client/ResponseParser/Select/Component/Spellcheck.php
+4
-4
library/Solarium/Result/Select/Spellcheck.php
library/Solarium/Result/Select/Spellcheck.php
+19
-9
tests/Solarium/Client/ResponseParser/Select/Component/SpellcheckTest.php
...Client/ResponseParser/Select/Component/SpellcheckTest.php
+24
-0
tests/Solarium/Result/Select/SpellcheckTest.php
tests/Solarium/Result/Select/SpellcheckTest.php
+8
-4
No files found.
examples/2.1.5.9-spellcheck.php
View file @
acfbc18e
...
@@ -41,13 +41,16 @@ foreach($spellcheckResult as $suggestion) {
...
@@ -41,13 +41,16 @@ foreach($spellcheckResult as $suggestion) {
echo
'<hr/>'
;
echo
'<hr/>'
;
}
}
$collation
=
$spellcheckResult
->
getCollation
();
$collations
=
$spellcheckResult
->
getCollations
();
echo
'<h1>Collation</h1>'
;
echo
'<h1>Collations</h1>'
;
echo
'Query: '
.
$collation
->
getQuery
()
.
'<br/>'
;
foreach
(
$collations
as
$collation
)
{
echo
'Hits: '
.
$collation
->
getHits
()
.
'<br/>'
;
echo
'Query: '
.
$collation
->
getQuery
()
.
'<br/>'
;
echo
'Hits: '
.
$collation
->
getHits
()
.
'<br/>'
;
echo
'<hr/>'
;
}
echo
'Corrections:<br/>'
;
echo
'Corrections:<br/>'
;
foreach
(
$collation
->
getCorrections
()
as
$input
=>
$correction
)
{
foreach
(
$collation
->
getCorrections
()
as
$input
=>
$correction
)
{
echo
$input
.
' => '
.
$correction
.
'<br/>'
;
echo
$input
.
' => '
.
$correction
.
'<br/>'
;
}
}
htmlFooter
();
htmlFooter
();
\ No newline at end of file
library/Solarium/Client/ResponseParser/Select/Component/Spellcheck.php
View file @
acfbc18e
...
@@ -66,7 +66,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
...
@@ -66,7 +66,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$suggestions
=
array
();
$suggestions
=
array
();
$correctlySpelled
=
null
;
$correctlySpelled
=
null
;
$collation
=
null
;
$collation
s
=
array
()
;
$index
=
0
;
$index
=
0
;
while
(
isset
(
$spellcheckResults
[
$index
])
&&
isset
(
$spellcheckResults
[
$index
+
1
]))
{
while
(
isset
(
$spellcheckResults
[
$index
])
&&
isset
(
$spellcheckResults
[
$index
+
1
]))
{
...
@@ -78,7 +78,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
...
@@ -78,7 +78,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$correctlySpelled
=
$value
;
$correctlySpelled
=
$value
;
break
;
break
;
case
'collation'
:
case
'collation'
:
$collation
=
$this
->
_parseCollation
(
$value
);
$collation
s
[]
=
$this
->
_parseCollation
(
$value
);
break
;
break
;
default
:
default
:
$suggestions
[]
=
$this
->
_parseSuggestion
(
$key
,
$value
);
$suggestions
[]
=
$this
->
_parseSuggestion
(
$key
,
$value
);
...
@@ -87,7 +87,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
...
@@ -87,7 +87,7 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$index
+=
2
;
$index
+=
2
;
}
}
return
new
Solarium_Result_Select_Spellcheck
(
$suggestions
,
$collation
,
$correctlySpelled
);
return
new
Solarium_Result_Select_Spellcheck
(
$suggestions
,
$collation
s
,
$correctlySpelled
);
}
else
{
}
else
{
return
null
;
return
null
;
}
}
...
@@ -173,4 +173,4 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
...
@@ -173,4 +173,4 @@ class Solarium_Client_ResponseParser_Select_Component_Spellcheck
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
,
$frequency
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
,
$frequency
);
);
}
}
}
}
\ No newline at end of file
library/Solarium/Result/Select/Spellcheck.php
View file @
acfbc18e
...
@@ -53,11 +53,11 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
...
@@ -53,11 +53,11 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
protected
$_suggestions
;
protected
$_suggestions
;
/**
/**
* Collation
object
* Collation
s array
*
*
* @var
Solarium_Result_Select_Spellcheck_Collation
* @var
array
*/
*/
protected
$_collation
;
protected
$_collation
s
;
/**
/**
* Correctly spelled?
* Correctly spelled?
...
@@ -70,25 +70,35 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
...
@@ -70,25 +70,35 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
* Constructor
* Constructor
*
*
* @param array $suggestions
* @param array $suggestions
* @param
Solarium_Result_Select_Spellcheck_Collation $collation
* @param
array $collations
* @param boolean $correctlySpelled
* @param boolean $correctlySpelled
* @return void
* @return void
*/
*/
public
function
__construct
(
$suggestions
,
$collation
,
$correctlySpelled
)
public
function
__construct
(
$suggestions
,
$collation
s
,
$correctlySpelled
)
{
{
$this
->
_suggestions
=
$suggestions
;
$this
->
_suggestions
=
$suggestions
;
$this
->
_collation
=
$collation
;
$this
->
_collation
s
=
$collations
;
$this
->
_correctlySpelled
=
$correctlySpelled
;
$this
->
_correctlySpelled
=
$correctlySpelled
;
}
}
/**
/**
* Get the collation result
* Get the
first
collation result
*
*
* @return Solarium_Result_Select_Spellcheck_Collation
* @return Solarium_Result_Select_Spellcheck_Collation
*/
*/
public
function
getCollation
()
public
function
getCollation
()
{
{
return
$this
->
_collation
;
return
empty
(
$this
->
_collations
)
?
null
:
reset
(
$this
->
_collations
);
}
/**
* Get all collations
*
* @return array
*/
public
function
getCollations
()
{
return
$this
->
_collations
;
}
}
/**
/**
...
@@ -147,4 +157,4 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
...
@@ -147,4 +157,4 @@ class Solarium_Result_Select_Spellcheck implements IteratorAggregate, Countable
{
{
return
count
(
$this
->
_suggestions
);
return
count
(
$this
->
_suggestions
);
}
}
}
}
\ No newline at end of file
tests/Solarium/Client/ResponseParser/Select/Component/SpellcheckTest.php
View file @
acfbc18e
...
@@ -85,6 +85,21 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
...
@@ -85,6 +85,21 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
3
=>
'ultrasharp'
3
=>
'ultrasharp'
),
),
),
),
8
=>
'collation'
,
9
=>
array
(
0
=>
'collationQuery'
,
1
=>
'dell ultrasharp new'
,
2
=>
'hits'
,
3
=>
0
,
4
=>
'misspellingsAndCorrections'
,
5
=>
array
(
0
=>
'delll'
,
1
=>
'dell'
,
2
=>
'ultrashar'
,
3
=>
'ultrasharp'
),
),
)
)
)
)
);
);
...
@@ -95,6 +110,9 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
...
@@ -95,6 +110,9 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
$this
->
assertEquals
(
false
,
$result
->
getCorrectlySpelled
());
$this
->
assertEquals
(
false
,
$result
->
getCorrectlySpelled
());
$this
->
assertEquals
(
'dell'
,
$suggestions
[
0
]
->
getWord
());
$this
->
assertEquals
(
'dell'
,
$suggestions
[
0
]
->
getWord
());
$this
->
assertEquals
(
'dell ultrasharp'
,
$result
->
getCollation
()
->
getQuery
());
$this
->
assertEquals
(
'dell ultrasharp'
,
$result
->
getCollation
()
->
getQuery
());
$collations
=
$result
->
getCollations
();
$this
->
assertEquals
(
'dell ultrasharp'
,
$collations
[
0
]
->
getQuery
());
$this
->
assertEquals
(
'dell ultrasharp new'
,
$collations
[
1
]
->
getQuery
());
}
}
public
function
testParse
()
public
function
testParse
()
...
@@ -129,6 +147,8 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
...
@@ -129,6 +147,8 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
5
=>
false
,
5
=>
false
,
6
=>
'collation'
,
6
=>
'collation'
,
7
=>
'dell ultrasharp'
,
7
=>
'dell ultrasharp'
,
8
=>
'collation'
,
9
=>
'dell ultrasharp new'
,
)
)
)
)
);
);
...
@@ -139,6 +159,10 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
...
@@ -139,6 +159,10 @@ class Solarium_Client_ResponseParser_Select_Component_SpellcheckTest extends PHP
$this
->
assertEquals
(
false
,
$result
->
getCorrectlySpelled
());
$this
->
assertEquals
(
false
,
$result
->
getCorrectlySpelled
());
$this
->
assertEquals
(
'dell'
,
$suggestions
[
0
]
->
getWord
());
$this
->
assertEquals
(
'dell'
,
$suggestions
[
0
]
->
getWord
());
$this
->
assertEquals
(
'dell ultrasharp'
,
$result
->
getCollation
()
->
getQuery
());
$this
->
assertEquals
(
'dell ultrasharp'
,
$result
->
getCollation
()
->
getQuery
());
$collations
=
$result
->
getCollations
();
$this
->
assertEquals
(
'dell ultrasharp'
,
$collations
[
0
]
->
getQuery
());
$this
->
assertEquals
(
'dell ultrasharp new'
,
$collations
[
1
]
->
getQuery
());
}
}
public
function
testParseNoData
()
public
function
testParseNoData
()
...
...
tests/Solarium/Result/Select/SpellcheckTest.php
View file @
acfbc18e
...
@@ -37,7 +37,7 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase
...
@@ -37,7 +37,7 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase
*/
*/
protected
$_result
;
protected
$_result
;
protected
$_suggestions
,
$_collation
,
$_correctlySpelled
;
protected
$_suggestions
,
$_collation
s
,
$_correctlySpelled
;
public
function
setUp
()
public
function
setUp
()
{
{
...
@@ -45,15 +45,19 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase
...
@@ -45,15 +45,19 @@ class Solarium_Result_Select_SpellcheckTest extends PHPUnit_Framework_TestCase
'key1'
=>
'content1'
,
'key1'
=>
'content1'
,
'key2'
=>
'content2'
,
'key2'
=>
'content2'
,
);
);
$this
->
_collation
=
'dummy1'
;
$this
->
_collations
=
array
(
'dummy1'
,
'dummy2'
,
);
$this
->
_correctlySpelled
=
false
;
$this
->
_correctlySpelled
=
false
;
$this
->
_result
=
new
Solarium_Result_Select_Spellcheck
(
$this
->
_suggestions
,
$this
->
_collation
,
$this
->
_correctlySpelled
);
$this
->
_result
=
new
Solarium_Result_Select_Spellcheck
(
$this
->
_suggestions
,
$this
->
_collation
s
,
$this
->
_correctlySpelled
);
}
}
public
function
testGetCollation
()
public
function
testGetCollation
()
{
{
$this
->
assertEquals
(
$this
->
_collation
,
$this
->
_result
->
getCollation
());
$this
->
assertEquals
(
$this
->
_collations
,
$this
->
_result
->
getCollations
());
$this
->
assertEquals
(
reset
(
$this
->
_collations
),
$this
->
_result
->
getCollation
());
}
}
public
function
testGetCorrectlySpelled
()
public
function
testGetCorrectlySpelled
()
...
...
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