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
6537ad19
Commit
6537ad19
authored
May 29, 2011
by
Bas de Nooijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- added more examples
- small docblock fix
parent
db313467
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
252 additions
and
1 deletion
+252
-1
examples/3.1-add-docs.php
examples/3.1-add-docs.php
+36
-0
examples/3.2-delete-by-query.php
examples/3.2-delete-by-query.php
+23
-0
examples/3.3-delete-by-id.php
examples/3.3-delete-by-id.php
+23
-0
examples/5.1-partial-usage.php
examples/5.1-partial-usage.php
+51
-0
examples/5.3.1-plugin-event-hooks.php
examples/5.3.1-plugin-event-hooks.php
+119
-0
library/Solarium/Autoloader.php
library/Solarium/Autoloader.php
+0
-1
No files found.
examples/3.1-add-docs.php
0 → 100644
View file @
6537ad19
<?php
require
(
'init.php'
);
htmlHeader
();
// create a new document for the data
$doc1
=
new
Solarium_Document_ReadWrite
();
$doc1
->
id
=
123
;
$doc1
->
name
=
'testdoc-1'
;
$doc1
->
price
=
364
;
// and a second one
$doc2
=
new
Solarium_Document_ReadWrite
();
$doc2
->
id
=
124
;
$doc2
->
name
=
'testdoc-2'
;
$doc2
->
price
=
340
;
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get an update query instance
$update
=
$client
->
createUpdate
();
// add the documents and a commit command to the update query
$update
->
addDocuments
(
array
(
$doc1
,
$doc2
));
$update
->
addCommit
();
// this executes the query and returns the result
$result
=
$client
->
update
(
$update
);
echo
'<b>Update query executed<b><br/>'
;
echo
'Query status: '
.
$result
->
getStatus
()
.
'<br/>'
;
echo
'Query time: '
.
$result
->
getQueryTime
();
htmlFooter
();
\ No newline at end of file
examples/3.2-delete-by-query.php
0 → 100644
View file @
6537ad19
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get an update query instance
$update
=
$client
->
createUpdate
();
// add the delete query and a commit command to the update query
$update
->
addDeleteQuery
(
'name:testdoc*'
);
$update
->
addCommit
();
// this executes the query and returns the result
$result
=
$client
->
update
(
$update
);
echo
'<b>Update query executed<b><br/>'
;
echo
'Query status: '
.
$result
->
getStatus
()
.
'<br/>'
;
echo
'Query time: '
.
$result
->
getQueryTime
();
htmlFooter
();
\ No newline at end of file
examples/3.3-delete-by-id.php
0 → 100644
View file @
6537ad19
<?php
require
(
'init.php'
);
htmlHeader
();
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// get an update query instance
$update
=
$client
->
createUpdate
();
// add the delete id and a commit command to the update query
$update
->
addDeleteById
(
123
);
$update
->
addCommit
();
// this executes the query and returns the result
$result
=
$client
->
update
(
$update
);
echo
'<b>Update query executed<b><br/>'
;
echo
'Query status: '
.
$result
->
getStatus
()
.
'<br/>'
;
echo
'Query time: '
.
$result
->
getQueryTime
();
htmlFooter
();
\ No newline at end of file
examples/5.1-partial-usage.php
0 → 100644
View file @
6537ad19
<?php
require
(
'init.php'
);
htmlHeader
();
// This example shows how to manually execute the query flow.
// By doing this manually you can customize data in between any step (although a plugin might be better for this)
// And you can use only a part of the flow. You could for instance use the query object and request builder,
// but execute the request in your own code.
// create a client instance
$client
=
new
Solarium_Client
(
$config
);
// create a select query instance
$query
=
$client
->
createSelect
();
// manually create a request for the query
$request
=
$client
->
createRequest
(
$query
);
// you can now use the request object for getting an uri (ie. to use in you own code)
// or you could modify the request object
echo
'Request URI: '
.
$request
->
getUri
()
.
'<br/>'
;
// you can still execute the request using the client and get a 'raw' response object
$response
=
$client
->
executeRequest
(
$request
);
// and finally you can convert the response into a result
$result
=
$client
->
createResult
(
$query
,
$response
);
// display the total number of documents found by solr
echo
'NumFound: '
.
$result
->
getNumFound
();
// show documents using the resultset iterator
foreach
(
$result
as
$document
)
{
echo
'<hr/><table>'
;
// the documents are also iterable, to get all fields
foreach
(
$document
AS
$field
=>
$value
)
{
// this converts multivalue fields to a comma-separated string
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
htmlFooter
();
\ No newline at end of file
examples/5.3.1-plugin-event-hooks.php
0 → 100644
View file @
6537ad19
<?php
require
(
'init.php'
);
// this very simple plugin shows a timing for each event and display some request debug info
class
basicDebug
extends
Solarium_Plugin_Abstract
{
protected
$_start
;
protected
$_output
=
array
();
public
function
__construct
()
{
$this
->
_start
=
microtime
(
true
);
}
protected
function
_timer
(
$event
)
{
$time
=
round
(
microtime
(
true
)
-
$this
->
_start
,
5
);
$this
->
_output
[]
=
'['
.
$time
.
'] '
.
$event
;
}
public
function
display
()
{
echo
implode
(
'<br/>'
,
$this
->
_output
);
}
public
function
preCreateRequest
()
{
$this
->
_timer
(
'preCreateRequest'
);
}
public
function
postCreateRequest
()
{
$this
->
_timer
(
'postCreateRequest'
);
}
// This method uses the aviable param(s) (see plugin abstract class)
// You can access or modify data this way
public
function
preExecuteRequest
(
$request
)
{
$this
->
_timer
(
'preExecuteRequest'
);
// this dummy param will be visible in the debug output but will also be used in the actual Solr request
$request
->
addParam
(
'dummyparam'
,
'dummyvalue'
);
$this
->
_output
[]
=
'Request URI: '
.
$request
->
getUri
();
}
public
function
postExecuteRequest
()
{
$this
->
_timer
(
'postExecuteRequest'
);
}
public
function
preCreateResult
()
{
$this
->
_timer
(
'preCreateResult'
);
}
public
function
postCreateResult
()
{
$this
->
_timer
(
'postCreateResult'
);
}
public
function
preExecute
()
{
$this
->
_timer
(
'preExecute'
);
}
public
function
postExecute
()
{
$this
->
_timer
(
'postExecute'
);
}
public
function
preCreateQuery
()
{
$this
->
_timer
(
'preCreateResult'
);
}
public
function
postCreateQuery
()
{
$this
->
_timer
(
'postCreateResult'
);
}
}
htmlHeader
();
// create a client instance and register the plugin
$plugin
=
new
basicDebug
();
$client
=
new
Solarium_Client
(
$config
);
$client
->
registerPlugin
(
'debugger'
,
$plugin
);
// execute a select query and display the results
$query
=
$client
->
createSelect
();
$resultset
=
$client
->
select
(
$query
);
echo
'NumFound: '
.
$resultset
->
getNumFound
();
foreach
(
$resultset
as
$document
)
{
echo
'<hr/><table>'
;
foreach
(
$document
AS
$field
=>
$value
)
{
if
(
is_array
(
$value
))
$value
=
implode
(
', '
,
$value
);
echo
'<tr><th>'
.
$field
.
'</th><td>'
.
$value
.
'</td></tr>'
;
}
echo
'</table>'
;
}
// display the debug plugin output
echo
'<hr/><h1>Plugin output</h1>'
;
$plugin
->
display
();
htmlFooter
();
\ No newline at end of file
library/Solarium/Autoloader.php
View file @
6537ad19
...
...
@@ -31,7 +31,6 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
* @link http://www.solarium-project.org/
*
* @package Solarium
*/
...
...
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