forked from solariumphp/solarium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
3,424 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: php | ||
phps: | ||
- 5.4 | ||
- 5.3 | ||
script: phpunit -c phpunit.xml.dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Solarium PHP Solr client library | ||
|
||
Solarium is a PHP Solr client that not only facilitates Solr communication but | ||
also tries to accurately model Solr concepts. | ||
Please see the project website for a more detailed description. | ||
|
||
## Project website | ||
http://www.solarium-project.org/ | ||
|
||
## License: | ||
See the COPYING file or view online | ||
https://github.com/basdenooijer/solarium/blob/master/COPYING | ||
|
||
## Issue tracker | ||
http://github.com/basdenooijer/solarium/issues | ||
|
||
## Contributors | ||
https://github.com/basdenooijer/solarium/contributors | ||
|
||
## API docs | ||
http://api.solarium-project.org/ | ||
|
||
## Travis Continuous Integration status | ||
|
||
* Develop branch [![Develop build status](https://secure.travis-ci.org/basdenooijer/solarium.png?branch=develop)](http://travis-ci.org/basdenooijer/solarium) | ||
* Master branch [![Develop build status](https://secure.travis-ci.org/basdenooijer/solarium.png?branch=master)](http://travis-ci.org/basdenooijer/solarium) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,14 @@ | |
"name": "solarium/solarium", | ||
"type": "library", | ||
"description": "PHP Solr client", | ||
"keywords": ["solr", "search"], | ||
"keywords": ["solr", "search", "php"], | ||
"homepage": "http://www.solarium-project.org", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"license": "NewBSD", | ||
"authors": [ | ||
{ | ||
"name": "Bas de Nooijer", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Gasol Wu", | ||
"email": "[email protected]" | ||
"name": "See GitHub contributors", | ||
"homepage": "https://github.com/basdenooijer/solarium/contributors" | ||
} | ||
], | ||
"require": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
require('init.php'); | ||
htmlHeader(); | ||
|
||
// create a client instance | ||
$client = new Solarium_Client($config); | ||
|
||
// get a suggester query instance | ||
$query = $client->createSuggester(); | ||
$query->setQuery('ap ip v'); //multiple terms | ||
$query->setDictionary('suggest'); | ||
$query->setOnlyMorePopular(true); | ||
$query->setCount(10); | ||
$query->setCollate(true); | ||
|
||
// this executes the query and returns the result | ||
$resultset = $client->suggester($query); | ||
|
||
echo '<b>Query:</b> '.$query->getQuery().'<hr/>'; | ||
|
||
// display results for each term | ||
foreach ($resultset as $term => $termResult) { | ||
echo '<h3>' . $term . '</h3>'; | ||
echo 'NumFound: '.$termResult->getNumFound().'<br/>'; | ||
echo 'StartOffset: '.$termResult->getStartOffset().'<br/>'; | ||
echo 'EndOffset: '.$termResult->getEndOffset().'<br/>'; | ||
echo 'Suggestions:<br/>'; | ||
foreach($termResult as $result){ | ||
echo '- '.$result.'<br/>'; | ||
} | ||
|
||
echo '<hr/>'; | ||
} | ||
|
||
// display collation | ||
echo 'Collation: '.$resultset->getCollation(); | ||
|
||
htmlFooter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
require('init.php'); | ||
htmlHeader(); | ||
|
||
// create a client instance and get a select query instance | ||
$client = new Solarium_Client($config); | ||
|
||
|
||
|
||
|
||
// first an example manually defining dereferenced params | ||
$query = $client->createSelect(); | ||
$helper = $query->getHelper(); | ||
|
||
$join = $helper->qparser('join', array('from' => 'manu_id', 'to' => 'id'), true); | ||
$queryString = $join . 'id:1'; | ||
$query->setQuery($queryString); | ||
$request = $client->createRequest($query); | ||
|
||
// output resulting url with dereferenced params | ||
echo urldecode($request->getUri()) . '<hr/>'; | ||
|
||
|
||
|
||
|
||
// this second example gives the exact same result, using the special join helper | ||
$query = $client->createSelect(); | ||
$helper = $query->getHelper(); | ||
|
||
$join = $helper->join('manu_id', 'id', true); | ||
$queryString = $join . 'id:1'; | ||
$query->setQuery($queryString); | ||
$request = $client->createRequest($query); | ||
|
||
echo urldecode($request->getUri()); | ||
|
||
|
||
|
||
|
||
htmlFooter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
require('init.php'); | ||
|
||
htmlHeader(); | ||
|
||
// create a client instance and autoload the customize request plugin | ||
$client = new Solarium_Client($config); | ||
$parallel = $client->getPlugin('parallelexecution'); | ||
|
||
// Add a delay param to better show the effect, as an example Solr install with | ||
// only a dozen documents is too fast for good testing | ||
// This param only works with the correct Solr plugin, | ||
// see http://www.raspberry.nl/2012/01/04/solr-delay-component/ | ||
// If you don't have to plugin the example still works, just without the delay. | ||
$customizer = $client->getPlugin('customizerequest'); | ||
$customizer->createCustomization(array( | ||
'key' => 'delay', | ||
'type' => 'param', | ||
'name' => 'delay', | ||
'value' => '500', | ||
'persistent' => true | ||
)); | ||
|
||
// create two queries to execute in an array. Keys are important for fetching the results later! | ||
$queryInstock = $client->createSelect()->setQuery('inStock:true'); | ||
$queryLowprice = $client->createSelect()->setQuery('price:[1 TO 300]'); | ||
|
||
// first execute the queries the normal way and time it | ||
$start = microtime(true); | ||
$client->execute($queryInstock); | ||
$client->execute($queryLowprice); | ||
echo 'Execution time for normal "serial" execution of two queries: ' . round(microtime(true)-$start, 3); | ||
|
||
|
||
echo '<hr/>'; | ||
|
||
|
||
// now execute the two queries parallel and time it | ||
$start = microtime(true); | ||
$parallel->addQuery('instock', $queryInstock); | ||
$parallel->addQuery('lowprice', $queryLowprice); | ||
$results = $parallel->execute(); | ||
echo 'Execution time for parallel execution of two queries: ' . round(microtime(true)-$start, 3); | ||
|
||
|
||
htmlFooter(); | ||
|
||
// Note: for this example on a default Solr index (with a tiny index) running on localhost the performance gain is | ||
// minimal to none, sometimes even slightly slower! | ||
// In a realworld scenario with network latency, a bigger dataset, more complex queries or multiple solr instances the | ||
// performance gain is much more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
require('init.php'); | ||
|
||
// this very simple plugin is used to show some events | ||
class simpleDebug extends Solarium_Plugin_Abstract | ||
{ | ||
protected $_output = array(); | ||
|
||
public function display() | ||
{ | ||
echo implode('<br/>', $this->_output); | ||
} | ||
|
||
public function eventBufferedAddFlushStart($buffer) { | ||
$this->_output[] = 'Flushing buffer (' . count($buffer) . 'docs)'; | ||
} | ||
} | ||
|
||
htmlHeader(); | ||
|
||
// create a client instance and autoload the buffered add plugin | ||
$client = new Solarium_Client($config); | ||
$buffer = $client->getPlugin('bufferedadd'); | ||
$buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value | ||
|
||
// also register a plugin for outputting events | ||
$debug = new simpleDebug(); | ||
$client->registerPlugin('debugger', $debug); | ||
|
||
// let's insert 25 docs | ||
for ($i=1; $i<=25; $i++) { | ||
|
||
// create a new document with dummy data and add it to the buffer | ||
$data = array( | ||
'id' => 'test_'.$i, | ||
'name' => 'test for buffered add', | ||
'price' => $i, | ||
); | ||
$buffer->createDocument($data); | ||
|
||
// alternatively you could create document instances yourself and use the addDocument(s) method | ||
} | ||
|
||
// At this point two flushes will already have been done by the buffer automatically (at the 10th and 20th doc), now | ||
// manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command. | ||
$buffer->flush(); | ||
|
||
// In total 3 flushes (requests) have been sent to Solr. This should be visible in this output: | ||
$debug->display(); | ||
|
||
htmlFooter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
require('init.php'); | ||
|
||
htmlHeader(); | ||
|
||
// create a client instance | ||
$client = new Solarium_Client($config); | ||
|
||
// get a select query instance | ||
$query = $client->createSelect(); | ||
$query->setFields(array('id')); | ||
|
||
// get a plugin instance and apply settings | ||
$prefetch = $client->getPlugin('prefetchiterator'); | ||
$prefetch->setPrefetch(2); //fetch 2 rows per query (for real world use this can be way higher) | ||
$prefetch->setQuery($query); | ||
|
||
// display the total number of documents found by solr | ||
echo 'NumFound: ' . count($prefetch); | ||
|
||
// show document IDs using the resultset iterator | ||
foreach ($prefetch as $document) { | ||
echo '<hr/>ID: '. $document->id; | ||
} | ||
|
||
htmlFooter(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.