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
43dae657
Commit
43dae657
authored
Sep 10, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed examples and a bug in spellcheck response parsing, added a unittest
parent
5d9b6d5e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
37 deletions
+91
-37
examples/5.3.1-plugin-event-hooks.php
examples/5.3.1-plugin-event-hooks.php
+1
-1
examples/5.3.2-plugin-solarium-presets.php
examples/5.3.2-plugin-solarium-presets.php
+1
-1
library/Solarium/QueryType/Select/ResponseParser/Component/Spellcheck.php
.../QueryType/Select/ResponseParser/Component/Spellcheck.php
+48
-35
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/SpellcheckTest.php
...ryType/Select/ResponseParser/Component/SpellcheckTest.php
+41
-0
No files found.
examples/5.3.1-plugin-event-hooks.php
View file @
43dae657
...
@@ -3,7 +3,7 @@ require(__DIR__.'/init.php');
...
@@ -3,7 +3,7 @@ require(__DIR__.'/init.php');
// this very simple plugin shows a timing for each event and display some request debug info
// this very simple plugin shows a timing for each event and display some request debug info
class
basicDebug
extends
Solarium\Core\Plugin
class
basicDebug
extends
Solarium\Core\Plugin
\Plugin
{
{
protected
$start
;
protected
$start
;
...
...
examples/5.3.2-plugin-solarium-presets.php
View file @
43dae657
<?php
<?php
require
(
__DIR__
.
'/init.php'
);
require
(
__DIR__
.
'/init.php'
);
use
Solarium\Client
;
use
Solarium\Client
;
use
Solarium\Core\Plugin
;
use
Solarium\Core\Plugin
\Plugin
;
use
Solarium\QueryType\Select\Query\Query
as
Select
;
use
Solarium\QueryType\Select\Query\Query
as
Select
;
// This is a custom query class that could have some customized logic
// This is a custom query class that could have some customized logic
...
...
library/Solarium/QueryType/Select/ResponseParser/Component/Spellcheck.php
View file @
43dae657
...
@@ -79,18 +79,13 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
...
@@ -79,18 +79,13 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
$collations
=
array
();
$collations
=
array
();
foreach
(
$spellcheckResults
as
$key
=>
$value
)
{
foreach
(
$spellcheckResults
as
$key
=>
$value
)
{
switch
(
$key
)
{
switch
(
$key
)
{
case
'correctlySpelled'
:
case
'correctlySpelled'
:
$correctlySpelled
=
$value
;
$correctlySpelled
=
$value
;
break
;
break
;
case
'collation'
:
case
'collation'
:
if
(
!
array_key_exists
(
'collation'
,
$value
))
{
$collations
=
$this
->
parseCollation
(
$query
,
$value
);
foreach
(
$value
as
$collationValue
)
{
$collations
[]
=
$this
->
parseCollation
(
$query
,
$collationValue
);
}
}
else
{
$collations
[]
=
$this
->
parseCollation
(
$query
,
$value
);
}
break
;
break
;
default
:
default
:
$suggestions
[]
=
$this
->
parseSuggestion
(
$key
,
$value
);
$suggestions
[]
=
$this
->
parseSuggestion
(
$key
,
$value
);
...
@@ -108,51 +103,69 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
...
@@ -108,51 +103,69 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
*
*
* @param Query $queryObject
* @param Query $queryObject
* @param array $values
* @param array $values
* @return Collation
* @return Collation
[]
*/
*/
protected
function
parseCollation
(
$queryObject
,
$values
)
protected
function
parseCollation
(
$queryObject
,
$values
)
{
{
$collations
=
array
();
if
(
is_string
(
$values
))
{
if
(
is_string
(
$values
))
{
return
new
Collation
(
$values
,
null
,
array
());
}
else
{
$collations
[]
=
new
Collation
(
$values
,
null
,
array
());
$query
=
null
;
}
else
if
(
is_array
(
$values
)
&&
isset
(
$values
[
0
])
&&
is_string
(
$values
[
0
])
&&
$values
[
0
]
!==
'collationQuery'
)
{
$hits
=
null
;
$correctionResult
=
null
;
if
(
$queryObject
->
getResponseWriter
()
==
$queryObject
::
WT_JSON
)
{
foreach
(
$values
as
$value
)
{
$
values
=
$this
->
convertToKeyValueArray
(
$values
);
$
collations
[]
=
new
Collation
(
$value
,
null
,
array
()
);
}
}
foreach
(
$values
as
$key
=>
$value
)
{
}
else
{
switch
(
$key
)
{
case
'collationQuery'
:
if
(
$queryObject
->
getResponseWriter
()
==
$queryObject
::
WT_JSON
)
{
$query
=
$value
;
if
(
is_array
(
current
(
$values
))){
break
;
foreach
(
$values
as
$key
=>
$value
)
{
case
'hits'
:
$values
[
$key
]
=
$this
->
convertToKeyValueArray
(
$value
);
$hits
=
$value
;
}
break
;
}
else
{
case
'misspellingsAndCorrections'
:
$values
=
array
(
$this
->
convertToKeyValueArray
(
$values
));
$correctionResult
=
$value
;
break
;
}
}
}
}
$corrections
=
array
();
foreach
(
$values
as
$collationValue
)
{
if
(
$correctionResult
!==
null
)
{
$query
=
null
;
$hits
=
null
;
if
(
$queryObject
->
getResponseWriter
()
==
$queryObject
::
WT_JSON
)
{
$correctionResult
=
null
;
$correctionResult
=
$this
->
convertToKeyValueArray
(
$correctionResult
);
foreach
(
$collationValue
as
$key
=>
$value
)
{
switch
(
$key
)
{
case
'collationQuery'
:
$query
=
$value
;
break
;
case
'hits'
:
$hits
=
$value
;
break
;
case
'misspellingsAndCorrections'
:
$correctionResult
=
$value
;
break
;
}
}
}
foreach
(
$correctionResult
as
$input
=>
$correction
)
{
$corrections
=
array
();
$corrections
[
$input
]
=
$correction
;
if
(
$correctionResult
!==
null
)
{
if
(
$queryObject
->
getResponseWriter
()
==
$queryObject
::
WT_JSON
)
{
$correctionResult
=
$this
->
convertToKeyValueArray
(
$correctionResult
);
}
foreach
(
$correctionResult
as
$input
=>
$correction
)
{
$corrections
[
$input
]
=
$correction
;
}
}
}
}
return
new
Collation
(
$query
,
$hits
,
$corrections
);
$collations
[]
=
new
Collation
(
$query
,
$hits
,
$corrections
);
}
}
}
return
$collations
;
}
}
/**
/**
...
...
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/SpellcheckTest.php
View file @
43dae657
...
@@ -170,6 +170,47 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
...
@@ -170,6 +170,47 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
}
}
public
function
testParseSingleCollation
()
{
$data
=
array
(
'spellcheck'
=>
array
(
'suggestions'
=>
array
(
0
=>
'delll'
,
1
=>
array
(
'numFound'
=>
1
,
'startOffset'
=>
0
,
'endOffset'
=>
5
,
'origFreq'
=>
0
,
'suggestion'
=>
array
(
0
=>
'dell'
,
),
),
2
=>
'ultrashar'
,
3
=>
array
(
'numFound'
=>
1
,
'startOffset'
=>
6
,
'endOffset'
=>
15
,
'origFreq'
=>
0
,
'suggestion'
=>
array
(
0
=>
array
(
'word'
=>
'ultrasharp'
,
'freq'
=>
1
),
),
),
4
=>
'correctlySpelled'
,
5
=>
false
,
6
=>
'collation'
,
7
=>
'dell ultrasharp'
,
)
)
);
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
$data
);
$collations
=
$result
->
getCollations
();
$this
->
assertEquals
(
'dell ultrasharp'
,
$collations
[
0
]
->
getQuery
());
}
public
function
testParseNoData
()
public
function
testParseNoData
()
{
{
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
array
());
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
array
());
...
...
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