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
3d0da19a
Commit
3d0da19a
authored
Sep 08, 2011
by
Christian Soronellas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now per field highlighting options can be added.
parent
ce1d99f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
1 deletion
+131
-1
library/Solarium/Client/RequestBuilder/Select/Component/Highlighting.php
...m/Client/RequestBuilder/Select/Component/Highlighting.php
+21
-1
library/Solarium/Query/Select/Component/Highlighting.php
library/Solarium/Query/Select/Component/Highlighting.php
+76
-0
tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php
...ient/RequestBuilder/Select/Component/HighlightingTest.php
+7
-0
tests/Solarium/Query/Select/Component/HighlightingTest.php
tests/Solarium/Query/Select/Component/HighlightingTest.php
+27
-0
No files found.
library/Solarium/Client/RequestBuilder/Select/Component/Highlighting.php
View file @
3d0da19a
...
...
@@ -52,7 +52,7 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting
* @param Solarium_Client_Request $request
* @return Solarium_Client_Request
*/
public
function
build
(
$component
,
$request
)
public
function
build
(
Solarium_Query_Select_Component_Highlighting
$component
,
Solarium_Client_Request
$request
)
{
// enable highlighting
$request
->
addParam
(
'hl'
,
'true'
);
...
...
@@ -77,7 +77,27 @@ class Solarium_Client_RequestBuilder_Select_Component_Highlighting
$request
->
addParam
(
'hl.regex.slop'
,
$component
->
getRegexSlop
());
$request
->
addParam
(
'hl.regex.pattern'
,
$component
->
getRegexPattern
());
$request
->
addParam
(
'hl.regex.maxAnalyzedChars'
,
$component
->
getRegexMaxAnalyzedChars
());
$fieldOptions
=
$component
->
getPerFieldOptions
();
if
(
sizeof
(
$fieldOptions
))
{
$this
->
_buildPerField
(
$fieldOptions
,
$request
);
}
return
$request
;
}
/**
* Set the per field highlighting options
*
* @param array $fieldOptions
* @param Solarium_Client_Request $request
*/
protected
function
_buildPerField
(
array
$fieldOptions
,
Solarium_Client_Request
$request
)
{
foreach
(
$fieldOptions
as
$field
=>
$options
)
{
foreach
(
$options
as
$option
=>
$value
)
{
$request
->
addParam
(
'f.'
.
$field
.
'.hl.'
.
$option
,
$value
,
true
);
}
}
}
}
\ No newline at end of file
library/Solarium/Query/Select/Component/Highlighting.php
View file @
3d0da19a
...
...
@@ -58,6 +58,20 @@ class Solarium_Query_Select_Component_Highlighting extends Solarium_Query_Select
* @var string
*/
protected
$_type
=
Solarium_Query_Select
::
COMPONENT_HIGHLIGHTING
;
/**
* Specifies the field over the highlight will be set
*
* @var string
*/
protected
$_overField
;
/**
* The options applied to specific fields
*
* @var array
*/
protected
$_fieldOptions
=
array
();
/**
* Set fields option
...
...
@@ -501,4 +515,66 @@ class Solarium_Query_Select_Component_Highlighting extends Solarium_Query_Select
return
$this
->
getOption
(
'regexmaxanalyzedchars'
);
}
/**
* Stop setting per field options
*/
public
function
endPerFieldOptions
()
{
$this
->
_overField
=
null
;
}
/**
* Returns the array with all the specific per field options
*
* @return array
*/
public
function
getPerFieldOptions
()
{
return
$this
->
_fieldOptions
;
}
/**
* Override the _setOption method to take in account the per field options
*
* @param string $name
* @param mixed $value
*/
protected
function
_setOption
(
$name
,
$value
)
{
if
(
null
!==
$this
->
_overField
)
{
$this
->
_fieldOptions
[
$this
->
_overField
][
$name
]
=
$value
;
}
else
{
parent
::
_setOption
(
$name
,
$value
);
}
return
$this
;
}
/**
* Checks if a given field exists on the lists field. If not, it will
* be added
*
* @param string $fieldName
*/
protected
function
_checkField
(
$fieldName
)
{
if
(
strstr
(
$this
->
getFields
(),
$fieldName
)
===
false
)
{
$this
->
setFields
(
$this
->
getFields
()
.
(
strlen
(
$this
->
getFields
())
>
0
?
','
:
''
)
.
$fieldName
);
}
}
/**
* This magic method implementation, sets the field over the highlight options
* will be applied
*
* @param string $name
* @return Solarium_Query_Select_Component_Highlighting
*/
public
function
__get
(
$name
)
{
$this
->
_checkField
(
$name
);
$this
->
_overField
=
$name
;
return
$this
;
}
}
\ No newline at end of file
tests/Solarium/Client/RequestBuilder/Select/Component/HighlightingTest.php
View file @
3d0da19a
...
...
@@ -59,6 +59,11 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
$component
->
setRegexPattern
(
'mypattern'
);
$component
->
setMaxAnalyzedChars
(
100
);
// Per field
$component
->
field
->
setSnippets
(
20
)
->
setFragsize
(
200
)
->
endPerFieldOptions
();
$request
=
$builder
->
build
(
$component
,
$request
);
$this
->
assertEquals
(
...
...
@@ -83,6 +88,8 @@ class Solarium_Client_RequestBuilder_Select_Component_HighlightingTest extends P
'hl.highlightMultiTerm'
=>
'true'
,
'hl.regex.slop'
=>
1.3
,
'hl.regex.pattern'
=>
'mypattern'
,
'f.field.hl.snippets'
=>
20
,
'f.field.hl.fragsize'
=>
200
),
$request
->
getParams
()
);
...
...
tests/Solarium/Query/Select/Component/HighlightingTest.php
View file @
3d0da19a
...
...
@@ -315,4 +315,31 @@ class Solarium_Query_Select_Component_HighlightingTest extends PHPUnit_Framework
);
}
public
function
testNonExistentPropertiesWillReturnTheComponentItself
()
{
$this
->
assertInstanceOf
(
'Solarium_Query_Select_Component'
,
$this
->
_hlt
->
field
);
}
/**
* @depends testNonExistentPropertiesWillReturnTheComponentItself
*/
public
function
testNonExistentPropertiesWillBeAddedToTheFieldsList
()
{
$this
->
_hlt
->
field
->
endPerFieldOptions
();
$this
->
assertContains
(
'field'
,
$this
->
_hlt
->
getFields
());
}
public
function
testMethodsCalledAfterUnexistendPropertySetWillBeAddedAsAFieldSpecificOption
()
{
$this
->
_hlt
->
field
->
setSnippets
(
20
)
->
setFragSize
(
200
)
->
endPerFieldOptions
();
$fieldOptions
=
$this
->
_hlt
->
getPerFieldOptions
();
$this
->
assertArrayHasKey
(
'field'
,
$fieldOptions
);
$this
->
assertInternalType
(
'array'
,
$fieldOptions
[
'field'
]);
$this
->
assertArrayHasKey
(
'snippets'
,
$fieldOptions
[
'field'
]);
$this
->
assertArrayHasKey
(
'fragsize'
,
$fieldOptions
[
'field'
]);
$this
->
assertEquals
(
20
,
$fieldOptions
[
'field'
][
'snippets'
]);
$this
->
assertEquals
(
200
,
$fieldOptions
[
'field'
][
'fragsize'
]);
}
}
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