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
a71f798c
Commit
a71f798c
authored
Jul 21, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added createDocument method to update query
parent
f5ddbee9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
0 deletions
+89
-0
library/Solarium/Document/ReadWrite.php
library/Solarium/Document/ReadWrite.php
+1
-0
library/Solarium/Query/Update.php
library/Solarium/Query/Update.php
+44
-0
tests/Solarium/Query/UpdateTest.php
tests/Solarium/Query/UpdateTest.php
+44
-0
No files found.
library/Solarium/Document/ReadWrite.php
View file @
a71f798c
...
...
@@ -75,6 +75,7 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
* Constructor
*
* @param array $fields
* @param array $boosts
*/
public
function
__construct
(
$fields
=
array
(),
$boosts
=
array
())
{
...
...
library/Solarium/Query/Update.php
View file @
a71f798c
...
...
@@ -79,6 +79,7 @@ class Solarium_Query_Update extends Solarium_Query
protected
$_options
=
array
(
'handler'
=>
'update'
,
'resultclass'
=>
'Solarium_Result_Update'
,
'documentclass'
=>
'Solarium_Document_ReadWrite'
,
);
/**
...
...
@@ -359,4 +360,47 @@ class Solarium_Query_Update extends Solarium_Query
return
$this
->
add
(
null
,
$optimize
);
}
/**
* Set a custom document class for use in the createDocument method
*
* This class should extend Solarium_Document_ReadWrite or
* at least be compatible with it's interface
*
* @param string $value classname
* @return Solarium_Query
*/
public
function
setDocumentClass
(
$value
)
{
return
$this
->
_setOption
(
'documentclass'
,
$value
);
}
/**
* Get the current documentclass option
*
* The value is a classname, not an instance
*
* @return string
*/
public
function
getDocumentClass
()
{
return
$this
->
getOption
(
'documentclass'
);
}
/**
* Create a document object instance
*
* You can optionally directly supply the fields and boosts
* to get a ready-made document instance for direct use in an add command
*
* @param array $fields
* @param array $boosts
* @return Solarium_Document_ReadWrite
*/
public
function
createDocument
(
$fields
=
array
(),
$boosts
=
array
())
{
$class
=
$this
->
getDocumentClass
();
return
new
$class
(
$fields
,
$boosts
);
}
}
\ No newline at end of file
tests/Solarium/Query/UpdateTest.php
View file @
a71f798c
...
...
@@ -402,4 +402,48 @@ class Solarium_Query_UpdateTest extends PHPUnit_Framework_TestCase
$this
->
_query
->
createCommand
(
'invalidtype'
);
}
public
function
testSetAndGetDocumentClass
()
{
$this
->
_query
->
setDocumentClass
(
'MyDocument'
);
$this
->
assertEquals
(
'MyDocument'
,
$this
->
_query
->
getDocumentClass
());
}
public
function
testCreateDocument
()
{
$doc
=
$this
->
_query
->
createDocument
();
$this
->
assertThat
(
$doc
,
$this
->
isInstanceOf
(
$this
->
_query
->
getDocumentClass
()));
}
public
function
testCreateDocumentWithCustomClass
()
{
$this
->
_query
->
setDocumentClass
(
'MyCustomDoc'
);
$doc
=
$this
->
_query
->
createDocument
();
$this
->
assertThat
(
$doc
,
$this
->
isInstanceOf
(
'MyCustomDoc'
));
}
public
function
testCreateDocumentWithFieldsAndBoosts
()
{
$fields
=
array
(
'id'
=>
1
,
'name'
=>
'testname'
);
$boosts
=
array
(
'name'
=>
2.7
);
$doc
=
$this
->
_query
->
createDocument
(
$fields
,
$boosts
);
$this
->
assertThat
(
$doc
,
$this
->
isInstanceOf
(
$this
->
_query
->
getDocumentClass
()));
$this
->
assertEquals
(
$fields
,
$doc
->
getFields
()
);
$this
->
assertEquals
(
2.7
,
$doc
->
getFieldBoost
(
'name'
)
);
}
}
class
MyCustomDoc
extends
Solarium_Document_ReadWrite
{
}
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