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
7970cb38
Commit
7970cb38
authored
Jan 15, 2013
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for DateTime objects as field value in an update document
parent
e320f506
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
library/Solarium/QueryType/Update/RequestBuilder.php
library/Solarium/QueryType/Update/RequestBuilder.php
+11
-5
tests/Solarium/Tests/QueryType/Update/RequestBuilderTest.php
tests/Solarium/Tests/QueryType/Update/RequestBuilderTest.php
+11
-0
No files found.
library/Solarium/QueryType/Update/RequestBuilder.php
View file @
7970cb38
...
@@ -80,7 +80,7 @@ class RequestBuilder extends BaseRequestBuilder
...
@@ -80,7 +80,7 @@ class RequestBuilder extends BaseRequestBuilder
foreach
(
$query
->
getCommands
()
as
$command
)
{
foreach
(
$query
->
getCommands
()
as
$command
)
{
switch
(
$command
->
getType
())
{
switch
(
$command
->
getType
())
{
case
UpdateQuery
::
COMMAND_ADD
:
case
UpdateQuery
::
COMMAND_ADD
:
$xml
.=
$this
->
buildAddXml
(
$command
);
$xml
.=
$this
->
buildAddXml
(
$command
,
$query
);
break
;
break
;
case
UpdateQuery
::
COMMAND_DELETE
:
case
UpdateQuery
::
COMMAND_DELETE
:
$xml
.=
$this
->
buildDeleteXml
(
$command
);
$xml
.=
$this
->
buildDeleteXml
(
$command
);
...
@@ -108,9 +108,10 @@ class RequestBuilder extends BaseRequestBuilder
...
@@ -108,9 +108,10 @@ class RequestBuilder extends BaseRequestBuilder
* Build XML for an add command
* Build XML for an add command
*
*
* @param Query\Command\Add $command
* @param Query\Command\Add $command
* @param UpdateQuery $query
* @return string
* @return string
*/
*/
public
function
buildAddXml
(
$command
)
public
function
buildAddXml
(
$command
,
$query
=
null
)
{
{
$xml
=
'<add'
;
$xml
=
'<add'
;
$xml
.=
$this
->
boolAttrib
(
'overwrite'
,
$command
->
getOverwrite
());
$xml
.=
$this
->
boolAttrib
(
'overwrite'
,
$command
->
getOverwrite
());
...
@@ -127,10 +128,10 @@ class RequestBuilder extends BaseRequestBuilder
...
@@ -127,10 +128,10 @@ class RequestBuilder extends BaseRequestBuilder
$modifier
=
$doc
->
getFieldModifier
(
$name
);
$modifier
=
$doc
->
getFieldModifier
(
$name
);
if
(
is_array
(
$value
))
{
if
(
is_array
(
$value
))
{
foreach
(
$value
as
$multival
)
{
foreach
(
$value
as
$multival
)
{
$xml
.=
$this
->
buildFieldXml
(
$name
,
$boost
,
$multival
,
$modifier
);
$xml
.=
$this
->
buildFieldXml
(
$name
,
$boost
,
$multival
,
$modifier
,
$query
);
}
}
}
else
{
}
else
{
$xml
.=
$this
->
buildFieldXml
(
$name
,
$boost
,
$value
,
$modifier
);
$xml
.=
$this
->
buildFieldXml
(
$name
,
$boost
,
$value
,
$modifier
,
$query
);
}
}
}
}
...
@@ -156,10 +157,15 @@ class RequestBuilder extends BaseRequestBuilder
...
@@ -156,10 +157,15 @@ class RequestBuilder extends BaseRequestBuilder
* @param float $boost
* @param float $boost
* @param mixed $value
* @param mixed $value
* @param string $modifier
* @param string $modifier
* @param UpdateQuery $query
* @return string
* @return string
*/
*/
protected
function
buildFieldXml
(
$name
,
$boost
,
$value
,
$modifier
=
null
)
protected
function
buildFieldXml
(
$name
,
$boost
,
$value
,
$modifier
=
null
,
$query
=
null
)
{
{
if
(
$value
instanceof
\DateTime
)
{
$value
=
$query
->
getHelper
()
->
formatDate
(
$value
);
}
$xml
=
'<field name="'
.
$name
.
'"'
;
$xml
=
'<field name="'
.
$name
.
'"'
;
$xml
.=
$this
->
attrib
(
'boost'
,
$boost
);
$xml
.=
$this
->
attrib
(
'boost'
,
$boost
);
$xml
.=
$this
->
attrib
(
'update'
,
$modifier
);
$xml
.=
$this
->
attrib
(
'update'
,
$modifier
);
...
...
tests/Solarium/Tests/QueryType/Update/RequestBuilderTest.php
View file @
7970cb38
...
@@ -208,6 +208,17 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
...
@@ -208,6 +208,17 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
);
);
}
}
public
function
testBuildAddXmlWithDateTime
()
{
$command
=
new
AddCommand
;
$command
->
addDocument
(
new
Document
(
array
(
'id'
=>
1
,
'datetime'
=>
new
\DateTime
(
'2013-01-15 14:41:58'
))));
$this
->
assertEquals
(
'<add><doc><field name="id">1</field><field name="datetime">2013-01-15T14:41:58Z</field></doc></add>'
,
$this
->
builder
->
buildAddXml
(
$command
,
$this
->
query
)
);
}
public
function
testBuildDeleteXml
()
public
function
testBuildDeleteXml
()
{
{
$command
=
new
DeleteCommand
;
$command
=
new
DeleteCommand
;
...
...
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