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
81a98bde
Commit
81a98bde
authored
Oct 30, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #222 from baldurrensch/filter_default
Filter by default in documents
parents
a6f06f2e
30dae1fe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
library/Solarium/QueryType/Update/Query/Document/Document.php
...ary/Solarium/QueryType/Update/Query/Document/Document.php
+54
-0
tests/Solarium/Tests/QueryType/Update/Query/Document/DocumentTest.php
...um/Tests/QueryType/Update/Query/Document/DocumentTest.php
+32
-0
No files found.
library/Solarium/QueryType/Update/Query/Document/Document.php
View file @
81a98bde
...
...
@@ -38,6 +38,7 @@
*/
namespace
Solarium\QueryType\Update\Query\Document
;
use
Solarium\Core\Query\Helper
;
use
Solarium\QueryType\Select\Result\AbstractDocument
;
use
Solarium\Exception\RuntimeException
;
...
...
@@ -139,6 +140,15 @@ class Document extends AbstractDocument implements DocumentInterface
*/
protected
$version
;
/**
* Helper instance
*
* @var Helper
*/
protected
$helper
;
protected
$filterControlCharacters
=
true
;
/**
* Constructor
*
...
...
@@ -175,6 +185,10 @@ class Document extends AbstractDocument implements DocumentInterface
$this
->
fields
[
$key
]
=
array
(
$this
->
fields
[
$key
]);
}
if
(
$this
->
filterControlCharacters
&&
is_string
(
$value
))
{
$value
=
$this
->
getHelper
()
->
filterControlCharacters
(
$value
);
}
$this
->
fields
[
$key
][]
=
$value
;
$this
->
setFieldBoost
(
$key
,
$boost
);
if
(
$modifier
!==
null
)
{
...
...
@@ -203,6 +217,10 @@ class Document extends AbstractDocument implements DocumentInterface
if
(
$value
===
null
&&
$modifier
==
null
)
{
$this
->
removeField
(
$key
);
}
else
{
if
(
$this
->
filterControlCharacters
&&
is_string
(
$value
))
{
$value
=
$this
->
getHelper
()
->
filterControlCharacters
(
$value
);
}
$this
->
fields
[
$key
]
=
$value
;
$this
->
setFieldBoost
(
$key
,
$boost
);
if
(
$modifier
!==
null
)
{
...
...
@@ -427,4 +445,40 @@ class Document extends AbstractDocument implements DocumentInterface
{
return
$this
->
version
;
}
/**
* Get a helper instance
*
* Uses lazy loading: the helper is instantiated on first use
*
* @return Helper
*/
public
function
getHelper
()
{
if
(
null
===
$this
->
helper
)
{
$this
->
helper
=
new
Helper
(
$this
);
}
return
$this
->
helper
;
}
/**
* Whether values should be filtered for control characters automatically
*
* @param boolean $filterControlCharacters
*/
public
function
setFilterControlCharacters
(
$filterControlCharacters
)
{
$this
->
filterControlCharacters
=
$filterControlCharacters
;
}
/**
* Returns whether values should be filtered automatically or control characters
*
* @return boolean
*/
public
function
getFilterControlCharacters
()
{
return
$this
->
filterControlCharacters
;
}
}
tests/Solarium/Tests/QueryType/Update/Query/Document/DocumentTest.php
View file @
81a98bde
...
...
@@ -458,4 +458,36 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$this
->
doc
->
getVersion
()
);
}
public
function
testEscapeByDefaultSetField
()
{
$this
->
doc
->
setField
(
'foo'
,
'bar'
.
chr
(
15
));
$this
->
assertEquals
(
'bar '
,
$this
->
doc
->
foo
);
}
public
function
testEscapeByDefaultAddField
()
{
$this
->
doc
->
setField
(
'foo'
,
'bar'
.
chr
(
15
));
$this
->
doc
->
addField
(
'foo'
,
'bar'
.
chr
(
15
)
.
chr
(
8
));
$this
->
assertEquals
(
array
(
'bar '
,
'bar '
),
$this
->
doc
->
foo
);
}
public
function
testNoEscapeSetField
()
{
$this
->
doc
->
setFilterControlCharacters
(
false
);
$this
->
doc
->
setField
(
'foo'
,
$value
=
'bar'
.
chr
(
15
));
$this
->
assertEquals
(
$value
,
$this
->
doc
->
foo
);
}
public
function
testNoEscapeAddField
()
{
$this
->
doc
->
setFilterControlCharacters
(
false
);
$this
->
doc
->
setField
(
'foo'
,
$value1
=
'bar'
.
chr
(
15
));
$this
->
doc
->
addField
(
'foo'
,
$value2
=
'bar'
.
chr
(
15
)
.
chr
(
8
));
$this
->
assertEquals
(
array
(
$value1
,
$value2
),
$this
->
doc
->
foo
);
}
}
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