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
068ebe83
Commit
068ebe83
authored
Feb 11, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/spellcheck-bugfix' into develop
parents
ea0232ea
3a1b3458
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
71 additions
and
25 deletions
+71
-25
examples/2.1.5.9-spellcheck.php
examples/2.1.5.9-spellcheck.php
+8
-3
library/Solarium/QueryType/Select/ResponseParser/Component/Spellcheck.php
.../QueryType/Select/ResponseParser/Component/Spellcheck.php
+10
-7
library/Solarium/QueryType/Select/Result/Spellcheck/Suggestion.php
...olarium/QueryType/Select/Result/Spellcheck/Suggestion.php
+27
-9
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/SpellcheckTest.php
...ryType/Select/ResponseParser/Component/SpellcheckTest.php
+7
-0
tests/Solarium/Tests/QueryType/Select/Result/Spellcheck/SuggestionTest.php
...sts/QueryType/Select/Result/Spellcheck/SuggestionTest.php
+19
-6
No files found.
examples/2.1.5.9-spellcheck.php
View file @
068ebe83
...
@@ -12,7 +12,8 @@ $query->setRows(0);
...
@@ -12,7 +12,8 @@ $query->setRows(0);
// add spellcheck settings
// add spellcheck settings
$spellcheck
=
$query
->
getSpellcheck
();
$spellcheck
=
$query
->
getSpellcheck
();
$spellcheck
->
setQuery
(
'delll ultrashar'
);
$spellcheck
->
setQuery
(
'tes'
);
$spellcheck
->
setCount
(
10
);
$spellcheck
->
setBuild
(
true
);
$spellcheck
->
setBuild
(
true
);
$spellcheck
->
setCollate
(
true
);
$spellcheck
->
setCollate
(
true
);
$spellcheck
->
setExtendedResults
(
true
);
$spellcheck
->
setExtendedResults
(
true
);
...
@@ -35,8 +36,12 @@ foreach($spellcheckResult as $suggestion) {
...
@@ -35,8 +36,12 @@ foreach($spellcheckResult as $suggestion) {
echo
'StartOffset: '
.
$suggestion
->
getStartOffset
()
.
'<br/>'
;
echo
'StartOffset: '
.
$suggestion
->
getStartOffset
()
.
'<br/>'
;
echo
'EndOffset: '
.
$suggestion
->
getEndOffset
()
.
'<br/>'
;
echo
'EndOffset: '
.
$suggestion
->
getEndOffset
()
.
'<br/>'
;
echo
'OriginalFrequency: '
.
$suggestion
->
getOriginalFrequency
()
.
'<br/>'
;
echo
'OriginalFrequency: '
.
$suggestion
->
getOriginalFrequency
()
.
'<br/>'
;
echo
'Frequency: '
.
$suggestion
->
getFrequency
()
.
'<br/>'
;
foreach
(
$suggestion
->
getWords
()
as
$word
)
{
echo
'Word: '
.
$suggestion
->
getWord
()
.
'<br/>'
;
echo
'-----<br/>'
;
echo
'Frequency: '
.
$word
[
'freq'
]
.
'<br/>'
;
echo
'Word: '
.
$word
[
'word'
]
.
'<br/>'
;
}
echo
'<hr/>'
;
echo
'<hr/>'
;
}
}
...
...
library/Solarium/QueryType/Select/ResponseParser/Component/Spellcheck.php
View file @
068ebe83
...
@@ -182,16 +182,19 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
...
@@ -182,16 +182,19 @@ class Spellcheck extends ResponseParserAbstract implements ComponentParserInterf
$endOffset
=
(
isset
(
$value
[
'endOffset'
]))
?
$value
[
'endOffset'
]
:
null
;
$endOffset
=
(
isset
(
$value
[
'endOffset'
]))
?
$value
[
'endOffset'
]
:
null
;
$originalFrequency
=
(
isset
(
$value
[
'origFreq'
]))
?
$value
[
'origFreq'
]
:
null
;
$originalFrequency
=
(
isset
(
$value
[
'origFreq'
]))
?
$value
[
'origFreq'
]
:
null
;
if
(
is_string
(
$value
[
'suggestion'
][
0
]))
{
$words
=
array
();
$word
=
$value
[
'suggestion'
][
0
];
foreach
(
$value
[
'suggestion'
]
as
$suggestion
)
{
$frequency
=
null
;
if
(
is_string
(
$suggestion
))
{
}
else
{
$suggestion
=
array
(
$word
=
$value
[
'suggestion'
][
0
][
'word'
];
'word'
=>
$suggestion
,
$frequency
=
$value
[
'suggestion'
][
0
][
'freq'
];
'freq'
=>
null
,
);
}
$words
[]
=
$suggestion
;
}
}
return
new
Suggestion
(
return
new
Suggestion
(
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
,
$frequency
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
s
);
);
}
}
}
}
library/Solarium/QueryType/Select/Result/Spellcheck/Suggestion.php
View file @
068ebe83
...
@@ -51,17 +51,15 @@ class Suggestion
...
@@ -51,17 +51,15 @@ class Suggestion
* @param int $startOffset
* @param int $startOffset
* @param int $endOffset
* @param int $endOffset
* @param int $originalFrequency
* @param int $originalFrequency
* @param string $word
* @param array $words
* @param int $frequency
*/
*/
public
function
__construct
(
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
,
$frequency
)
public
function
__construct
(
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
s
)
{
{
$this
->
numFound
=
$numFound
;
$this
->
numFound
=
$numFound
;
$this
->
startOffset
=
$startOffset
;
$this
->
startOffset
=
$startOffset
;
$this
->
endOffset
=
$endOffset
;
$this
->
endOffset
=
$endOffset
;
$this
->
originalFrequency
=
$originalFrequency
;
$this
->
originalFrequency
=
$originalFrequency
;
$this
->
word
=
$word
;
$this
->
words
=
$words
;
$this
->
frequency
=
$frequency
;
}
}
/**
/**
...
@@ -107,13 +105,28 @@ class Suggestion
...
@@ -107,13 +105,28 @@ class Suggestion
}
}
/**
/**
* Get word
* Get
first
word
*
*
* @return string
* @return string
|null
*/
*/
public
function
getWord
()
public
function
getWord
()
{
{
return
$this
->
word
;
$word
=
reset
(
$this
->
words
);
if
(
isset
(
$word
[
'word'
]))
{
return
$word
[
'word'
];
}
else
{
return
$word
;
}
}
/**
* Get all words (and frequencies)
*
* @return array
*/
public
function
getWords
()
{
return
$this
->
words
;
}
}
/**
/**
...
@@ -125,7 +138,12 @@ class Suggestion
...
@@ -125,7 +138,12 @@ class Suggestion
*/
*/
public
function
getFrequency
()
public
function
getFrequency
()
{
{
return
$this
->
frequency
;
$word
=
reset
(
$this
->
words
);
if
(
isset
(
$word
[
'freq'
]))
{
return
$word
[
'freq'
];
}
else
{
return
null
;
}
}
}
}
}
tests/Solarium/Tests/QueryType/Select/ResponseParser/Component/SpellcheckTest.php
View file @
068ebe83
...
@@ -194,6 +194,10 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
...
@@ -194,6 +194,10 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
'suggestion'
=>
array
(
'suggestion'
=>
array
(
0
=>
array
(
0
=>
array
(
'word'
=>
'ultrasharp'
,
'word'
=>
'ultrasharp'
,
'freq'
=>
2
),
1
=>
array
(
'word'
=>
'ultrasharpy'
,
'freq'
=>
1
'freq'
=>
1
),
),
),
),
...
@@ -209,6 +213,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
...
@@ -209,6 +213,9 @@ class SpellcheckTest extends \PHPUnit_Framework_TestCase
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
$data
);
$result
=
$this
->
parser
->
parse
(
$this
->
query
,
null
,
$data
);
$collations
=
$result
->
getCollations
();
$collations
=
$result
->
getCollations
();
$this
->
assertEquals
(
'dell ultrasharp'
,
$collations
[
0
]
->
getQuery
());
$this
->
assertEquals
(
'dell ultrasharp'
,
$collations
[
0
]
->
getQuery
());
$words
=
$result
->
getSuggestion
(
1
)
->
getWords
();
$this
->
assertEquals
(
array
(
'word'
=>
'ultrasharpy'
,
'freq'
=>
1
),
$words
[
1
]);
}
}
public
function
testParseNoData
()
public
function
testParseNoData
()
...
...
tests/Solarium/Tests/QueryType/Select/Result/Spellcheck/SuggestionTest.php
View file @
068ebe83
...
@@ -40,7 +40,7 @@ class SuggestionTest extends \PHPUnit_Framework_TestCase
...
@@ -40,7 +40,7 @@ class SuggestionTest extends \PHPUnit_Framework_TestCase
*/
*/
protected
$result
;
protected
$result
;
protected
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
,
$frequency
;
protected
$numFound
,
$startOffset
,
$endOffset
,
$originalFrequency
,
$word
s
,
$frequency
;
public
function
setUp
()
public
function
setUp
()
{
{
...
@@ -48,11 +48,19 @@ class SuggestionTest extends \PHPUnit_Framework_TestCase
...
@@ -48,11 +48,19 @@ class SuggestionTest extends \PHPUnit_Framework_TestCase
$this
->
startOffset
=
2
;
$this
->
startOffset
=
2
;
$this
->
endOffset
=
3
;
$this
->
endOffset
=
3
;
$this
->
originalFrequency
=
4
;
$this
->
originalFrequency
=
4
;
$this
->
word
=
'dummyword'
;
$this
->
words
=
array
(
$this
->
frequency
=
5
;
array
(
'word'
=>
'dummyword'
,
'freq'
=>
5
),
array
(
'word'
=>
'secondword'
,
'freq'
=>
1
)
);
$this
->
result
=
new
Suggestion
(
$this
->
result
=
new
Suggestion
(
$this
->
numFound
,
$this
->
startOffset
,
$this
->
endOffset
,
$this
->
originalFrequency
,
$this
->
word
,
$this
->
frequency
$this
->
numFound
,
$this
->
startOffset
,
$this
->
endOffset
,
$this
->
originalFrequency
,
$this
->
word
s
);
);
}
}
...
@@ -78,12 +86,17 @@ class SuggestionTest extends \PHPUnit_Framework_TestCase
...
@@ -78,12 +86,17 @@ class SuggestionTest extends \PHPUnit_Framework_TestCase
public
function
testGetWord
()
public
function
testGetWord
()
{
{
$this
->
assertEquals
(
$this
->
word
,
$this
->
result
->
getWord
());
$this
->
assertEquals
(
$this
->
word
s
[
0
][
'word'
]
,
$this
->
result
->
getWord
());
}
}
public
function
testGetFrequency
()
public
function
testGetFrequency
()
{
{
$this
->
assertEquals
(
$this
->
frequency
,
$this
->
result
->
getFrequency
());
$this
->
assertEquals
(
$this
->
words
[
0
][
'freq'
],
$this
->
result
->
getFrequency
());
}
public
function
testGetWords
()
{
$this
->
assertEquals
(
$this
->
words
,
$this
->
result
->
getWords
());
}
}
}
}
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