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
a966f99c
Commit
a966f99c
authored
Dec 07, 2012
by
Robert Elwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ported changes for atomic updates over from wikia/app
parent
5c7afe1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
3 deletions
+119
-3
library/Solarium/Client/RequestBuilder/Update.php
library/Solarium/Client/RequestBuilder/Update.php
+6
-3
library/Solarium/Document/AtomicUpdate.php
library/Solarium/Document/AtomicUpdate.php
+113
-0
No files found.
library/Solarium/Client/RequestBuilder/Update.php
View file @
a966f99c
...
@@ -119,12 +119,13 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
...
@@ -119,12 +119,13 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
foreach
(
$doc
->
getFields
()
AS
$name
=>
$value
)
{
foreach
(
$doc
->
getFields
()
AS
$name
=>
$value
)
{
$boost
=
$doc
->
getFieldBoost
(
$name
);
$boost
=
$doc
->
getFieldBoost
(
$name
);
$modifier
=
$doc
instanceof
Solarium_Document_AtomicUpdate
?
$doc
->
getFieldModifier
(
$name
)
:
null
;
if
(
is_array
(
$value
))
{
if
(
is_array
(
$value
))
{
foreach
(
$value
AS
$multival
)
{
foreach
(
$value
AS
$multival
)
{
$xml
.=
$this
->
_buildFieldXml
(
$name
,
$boost
,
$multival
);
$xml
.=
$this
->
_buildFieldXml
(
$name
,
$boost
,
$multival
,
$modifier
);
}
}
}
else
{
}
else
{
$xml
.=
$this
->
_buildFieldXml
(
$name
,
$boost
,
$value
);
$xml
.=
$this
->
_buildFieldXml
(
$name
,
$boost
,
$value
,
$modifier
);
}
}
}
}
...
@@ -144,12 +145,14 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
...
@@ -144,12 +145,14 @@ class Solarium_Client_RequestBuilder_Update extends Solarium_Client_RequestBuild
* @param string $name
* @param string $name
* @param float $boost
* @param float $boost
* @param mixed $value
* @param mixed $value
* @param string $modifier
* @return string
* @return string
*/
*/
protected
function
_buildFieldXml
(
$name
,
$boost
,
$value
)
protected
function
_buildFieldXml
(
$name
,
$boost
,
$value
,
$modifier
=
null
)
{
{
$xml
=
'<field name="'
.
$name
.
'"'
;
$xml
=
'<field name="'
.
$name
.
'"'
;
$xml
.=
$this
->
attrib
(
'boost'
,
$boost
);
$xml
.=
$this
->
attrib
(
'boost'
,
$boost
);
$xml
.=
$this
->
attrib
(
'update'
,
$modifier
);
$xml
.=
'>'
.
htmlspecialchars
(
$value
,
ENT_NOQUOTES
,
'UTF-8'
);
$xml
.=
'>'
.
htmlspecialchars
(
$value
,
ENT_NOQUOTES
,
'UTF-8'
);
$xml
.=
'</field>'
;
$xml
.=
'</field>'
;
...
...
library/Solarium/Document/AtomicUpdate.php
0 → 100644
View file @
a966f99c
<?php
class
Solarium_Document_AtomicUpdate
extends
Solarium_Document_ReadWrite
{
/**
* Allows us to determine what kind of atomic update we want to set
* @var unknown_type
*/
protected
$_modifiers
=
array
();
/**
* This field needs to be explicitly set to observe the rules of atomic updates
*/
protected
$key
;
/**
* Directive to set a value using atomic updates
* @var string
*/
const
MODIFIER_SET
=
'set'
;
/**
* Directive to increment an integer value using atomic updates
* @var string
*/
const
MODIFIER_INC
=
'inc'
;
/**
* Directive to append a value (e.g. multivalued fields) using atomic updates
* @var string
*/
const
MODIFIER_ADD
=
'add'
;
/**
* Constructor
*
* @param array $fields
* @param array $boosts
* @param array $modifiers
*/
public
function
__construct
(
$fields
=
array
(),
$boosts
=
array
(),
$modifiers
=
array
())
{
parent
::
__construct
(
$fields
,
$boosts
);
$this
->
_modifiers
=
$modifiers
;
}
/**
* Sets the uniquely identifying key for use in atomic updating
* @param string $key
*/
public
function
setKey
(
$key
,
$value
)
{
$this
->
key
=
$key
;
return
parent
::
addField
(
$key
,
$value
);
}
/**
* (non-PHPdoc)
* @see Solarium_Document_ReadWrite::addField()
*/
public
function
addField
(
$key
,
$value
,
$boost
=
null
,
$modifier
=
self
::
MODIFIER_SET
)
{
return
parent
::
addField
(
$key
,
$value
,
$boost
)
->
setModifierForField
(
$key
,
$modifier
);
}
/**
* (non-PHPdoc)
* @see Solarium_Document_ReadWrite::clear()
*/
public
function
clear
()
{
$this
->
_modifiers
=
array
();
return
parent
::
clear
();
}
/**
* Sets the modifier type for the provided field
* @param string $key
* @param string $modifier
* @throws Exception
* @return Solarium_Document_AtomicUpdate
*/
public
function
setModifierForField
(
$key
,
$modifier
=
self
::
MODIFIER_SET
)
{
if
(
!
in_array
(
$modifier
,
array
(
self
::
MODIFIER_ADD
,
self
::
MODIFIER_INC
,
self
::
MODIFIER_SET
))
)
{
throw
new
Exception
(
'Attempt to set an atomic update modifier that is not supported'
);
}
$this
->
_modifiers
[
$key
]
=
$modifier
;
return
$this
;
}
/**
* Returns the appropriate modifier for atomic updates.
* @param string $key
* @return Ambigous <NULL, unknown_type>
*/
public
function
getModifierForField
(
$key
)
{
return
isset
(
$this
->
_modifiers
[
$key
])
?
$this
->
_modifiers
[
$key
]
:
null
;
}
/**
* (non-PHPdoc)
* @see Solarium_Document_ReadOnly::getFields()
*/
public
function
getFields
()
{
if
(
$this
->
key
==
null
||
!
isset
(
$this
->
_fields
[
$this
->
key
]))
{
throw
new
Exception
(
'Solarium_Document_ReadOnly must have a unique-ID\'d key registered before it can be used to build update commands'
);
}
return
parent
::
getFields
();
}
}
\ No newline at end of file
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