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
47b74f62
Commit
47b74f62
authored
Dec 20, 2012
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for versioning / optimistic concurrency control
parent
058c6f51
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
0 deletions
+91
-0
library/Solarium/QueryType/Update/Query/Document/Document.php
...ary/Solarium/QueryType/Update/Query/Document/Document.php
+52
-0
library/Solarium/QueryType/Update/RequestBuilder.php
library/Solarium/QueryType/Update/RequestBuilder.php
+5
-0
tests/Solarium/Tests/QueryType/Update/Query/Document/DocumentTest.php
...um/Tests/QueryType/Update/Query/Document/DocumentTest.php
+20
-0
tests/Solarium/Tests/QueryType/Update/RequestBuilderTest.php
tests/Solarium/Tests/QueryType/Update/RequestBuilderTest.php
+14
-0
No files found.
library/Solarium/QueryType/Update/Query/Document/Document.php
View file @
47b74f62
...
@@ -78,6 +78,27 @@ class Document extends AbstractDocument implements DocumentInterface
...
@@ -78,6 +78,27 @@ class Document extends AbstractDocument implements DocumentInterface
*/
*/
const
MODIFIER_ADD
=
'add'
;
const
MODIFIER_ADD
=
'add'
;
/**
* This value has the same effect as not setting a version
*
* @var int
*/
const
VERSION_DONT_CARE
=
0
;
/**
* This value requires an existing document with the same key, but no specific version
*
* @var int
*/
const
VERSION_MUST_EXIST
=
1
;
/**
* This value requires that no document with the same key exists (so no automatic overwrite like default)
*
* @var int
*/
const
VERSION_MUST_NOT_EXIST
=
-
1
;
/**
/**
* Document boost value
* Document boost value
*
*
...
@@ -108,6 +129,15 @@ class Document extends AbstractDocument implements DocumentInterface
...
@@ -108,6 +129,15 @@ class Document extends AbstractDocument implements DocumentInterface
*/
*/
protected
$fieldBoosts
;
protected
$fieldBoosts
;
/**
* Version value
*
* Can be used for updating using Solr's optimistic concurrency control
*
* @var int
*/
protected
$version
;
/**
/**
* Constructor
* Constructor
*
*
...
@@ -373,4 +403,26 @@ class Document extends AbstractDocument implements DocumentInterface
...
@@ -373,4 +403,26 @@ class Document extends AbstractDocument implements DocumentInterface
return
parent
::
getFields
();
return
parent
::
getFields
();
}
}
/**
* Set version
*
* @param int $version
* @return self
*/
public
function
setVersion
(
$version
)
{
$this
->
version
=
$version
;
return
$this
;
}
/**
* Get version
*
* @return int
*/
public
function
getVersion
()
{
return
$this
->
version
;
}
}
}
library/Solarium/QueryType/Update/RequestBuilder.php
View file @
47b74f62
...
@@ -134,6 +134,11 @@ class RequestBuilder extends BaseRequestBuilder
...
@@ -134,6 +134,11 @@ class RequestBuilder extends BaseRequestBuilder
}
}
}
}
$version
=
$doc
->
getVersion
();
if
(
$version
!==
null
)
{
$xml
.=
$this
->
buildFieldXml
(
'_version_'
,
null
,
$version
);
}
$xml
.=
'</doc>'
;
$xml
.=
'</doc>'
;
}
}
...
...
tests/Solarium/Tests/QueryType/Update/Query/Document/DocumentTest.php
View file @
47b74f62
...
@@ -424,4 +424,24 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
...
@@ -424,4 +424,24 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
$this
->
doc
->
getFields
();
$this
->
doc
->
getFields
();
}
}
public
function
testSetAndGetVersion
()
{
$this
->
assertEquals
(
null
,
$this
->
doc
->
getVersion
()
);
$this
->
doc
->
setVersion
(
Document
::
VERSION_MUST_NOT_EXIST
);
$this
->
assertEquals
(
Document
::
VERSION_MUST_NOT_EXIST
,
$this
->
doc
->
getVersion
()
);
$this
->
doc
->
setVersion
(
234
);
$this
->
assertEquals
(
234
,
$this
->
doc
->
getVersion
()
);
}
}
}
tests/Solarium/Tests/QueryType/Update/RequestBuilderTest.php
View file @
47b74f62
...
@@ -194,6 +194,20 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
...
@@ -194,6 +194,20 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
);
);
}
}
public
function
testBuildAddXmlWithVersionedDocument
()
{
$doc
=
new
Document
(
array
(
'id'
=>
1
));
$doc
->
setVersion
(
Document
::
VERSION_MUST_NOT_EXIST
);
$command
=
new
AddCommand
;
$command
->
addDocument
(
$doc
);
$this
->
assertEquals
(
'<add><doc><field name="id">1</field><field name="_version_">-1</field></doc></add>'
,
$this
->
builder
->
buildAddXml
(
$command
)
);
}
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