Skip to content

Commit

Permalink
fix examples (solariumphp#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kalkbrenner authored May 14, 2019
1 parent e279403 commit cccdc04
Show file tree
Hide file tree
Showing 45 changed files with 415 additions and 318 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to the solarium library will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.0.2]
### Fixed
- Spellchecker result isn't NULL in case of no suggestions and correctly spelled
- RangeFacet Result
- Solarium\QueryType\Select\Result and Component return types
- Solarium\Component\Highlighting::setFields() should accept comma separated string, too
- Solarium\Component\Result\Grouping\ValueGroup various return types
- Solarium\Component\RequestBuilder\RequestParamsTrait::addParam should not add empty arrays
- MinimumScoreFilterPlugin
- Running the examples

### Added
- Solarium\Component\MoreLikeThis::setInterestingTerms()
- Solarium\Component\MoreLikeThis::setMatchInclude()
- Solarium\Component\MoreLikeThis::setMatchOffset()


## [5.0.1]
### Fixed
- Getting started documentation
Expand Down
45 changes: 2 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,9 @@ has to be changed to something like

## Run the examples

This needs a git checkout using composer.
To run the examples read through the _Example code_ section of
https://solarium.readthedocs.io/en/stable/getting-started/

### Add repository section

Add or update the repository sections in your `composer.json` file.

```
"repositories": [
{
"type": "vcs",
"url": "[email protected]:solariumphp/solarium.git"
}
]
```

### Reinstall

You need to fetch the newly configured git checkout. This will fetch the examples too.

```
composer install
```

### Make a copy of settings.dist.php

You must copy this file into your project root.

```
cp ./vendor/solarium/solarium/examples/config.dist.php ./config.php
```

Now you can change the `./config.php` if you are not using the default solr settings.

### Start webserver

Start the webserver from within the project root.

```
php -S localhost:8888
```

### Run the examples

Open http://localhost:8888/vendor/solarium/solarium/examples/

## More information

Expand Down
24 changes: 16 additions & 8 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Some users of Solarium have been nice enough to create easy ways of integrating
- Lithium <https://github.com/joseym/li3_solr>
- Fuel PHP <https://github.com/bgrimes/fuelphp-solarium>
- Yii <https://github.com/estahn/YiiSolarium>
- Drupal <https://www.drupal.org/project/search_api_solr>
- Typo3 <https://extensions.typo3.org/extension/solr/>
- Magento <https://github.com/jeroenvermeulen/magento-solarium>
- Wordpress <https://github.com/pantheon-systems/solr-for-wordpress>

Expand Down Expand Up @@ -339,13 +341,19 @@ For all options (like boosting) see the docs.
Example code
============

With Solarium a set of examples is included to demonstrate the usage and to test your Solr environment. To get the examples working you need to do the following:

1. make the /examples folder browseable on your (test)webserver.
2. download a standard Solr release and start the included Jetty example (see the Solr example/README.txt file)
3. load the demo data into the example index (again see the Solr example/README.txt file)
4. open the example dir in a browser, the index.html file listing all available examples should show up
With Solarium a set of examples is available to demonstrate the usage and to test your Solr environment. But since the
examples are not included in the distribution you need a git checkout of solarium and install the dependencies:
```
git clone https://github.com/solariumphp/solarium.git
cd solarium
composer install
```

That's all! The default config file of the examples was made for the standard Solr example included with a Solr release. If you want to use a custom Solr environment you can copy the file 'config.dist.php' in the example dir to 'config.php' and correct the settings. Your environment needs to have the default Solr example schema and data for the examples to work.
Afterwards you need to configure a web server to use the `examples` folder as docroot. But the easiest way is to use the
built-in web server of PHP. To do so continue like this:
```
cd examples
php -S localhost:8888
```

If examples for some Solarium functionality are missing please request them by opening an issue in the issue tracker: [<http://github.com/solariumphp/solarium/issues>](http://github.com/solariumphp/solarium/issues)
Now open `http://localhost:8888/` in your browser and follow the instructions.
1 change: 0 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
config.php
4 changes: 2 additions & 2 deletions examples/2.1.5.10-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
echo 'Stddev: ' . $field->getStddev() . '<br/>';

echo '<h2>Field facets</h2>';
foreach ($field->getFacets() as $field => $facet) {
echo '<h3>Facet ' . $field . '</h3>';
foreach ($field->getFacets() as $facetName => $facet) {
echo '<h3>Facet ' . $facetName . '</h3>';
foreach ($facet as $facetStats) {
echo '<h4>Value: ' . $facetStats->getValue() . '</h4>';
echo 'Min: ' . $facetStats->getMin() . '<br/>';
Expand Down
3 changes: 2 additions & 1 deletion examples/2.1.5.6-grouping-by-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

foreach ($fieldGroup as $valueGroup) {

echo '<h2>'.(int)$valueGroup->getValue().'</h2>';
$value = $valueGroup->getValue();
echo '<h2>'.(null !== $value ? (int) $value : 'NULL').'</h2>';

foreach ($valueGroup as $document) {

Expand Down
2 changes: 2 additions & 0 deletions examples/2.1.5.7-grouping-by-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require(__DIR__.'/init.php');
htmlHeader();

echo "<h2>Note: Query grouping seems to be broken in Solr 8.0.0!</h2>";

// create a client instance
$client = new Solarium\Client($config);

Expand Down
2 changes: 2 additions & 0 deletions examples/2.1.5.8-distributed-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require(__DIR__.'/init.php');
htmlHeader();

echo "<h2>Note: The techproducts isn't distributed by default!</h2>";

// create a client instance
$client = new Solarium\Client($config);

Expand Down
24 changes: 15 additions & 9 deletions examples/2.1.5.9-spellcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
$client = new Solarium\Client($config);

// get a select query instance
$query = $client->createSelect();
$query->setRows(0);
$query = $client->createSelect()
// Unfortunately the /select handler of the techproducts examlpe doesn't contain a spellchecker anymore.
// Therefore we have to use the /browse handler and turn of velocity by forcing json as response writer.
->setHandler('browse')
->setResponseWriter(\Solarium\Core\Query\AbstractQuery::WT_JSON)
// Normally we would use 'spellcheck.q'. But the /browse handler checks 'q'.
->setQuery('memori')
->setRows(0);

// add spellcheck settings
$spellcheck = $query->getSpellcheck();
$spellcheck->setQuery('tes');
$spellcheck->setCount(10);
$spellcheck->setBuild(true);
$spellcheck->setCollate(true);
$spellcheck->setExtendedResults(true);
$spellcheck->setCollateExtendedResults(true);
$spellcheck = $query->getSpellcheck()
->setCount(10)
->setBuild(true)
->setCollate(true)
->setExtendedResults(true)
->setCollateExtendedResults(true)
->setDictionary('default');

// this executes the query and returns the result
$resultset = $client->select($query);
Expand Down
69 changes: 44 additions & 25 deletions examples/2.3.1-mlt-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,30 @@
$client = new Client($config);

// get a morelikethis query instance
$query = $client->createMoreLikeThis();
$query = $client->createSelect()
// Unfortunately the /mlt handler of the techproducts examlpe doesn't exist anymore.
// Therefore we have to use the /browse handler and turn of velocity by forcing json as response writer.
->setHandler('browse')
->setResponseWriter(\Solarium\Core\Query\AbstractQuery::WT_JSON);

$query->setQuery('id:SP2514N');
$query->setMltFields('manu,cat');
$query->setMinimumDocumentFrequency(1);
$query->setMinimumTermFrequency(1);
$query->createFilterQuery('stock')->setQuery('inStock:true');
$query->setInterestingTerms('details');
$query->setMatchInclude(true);
$query->getMoreLikeThis()
->setFields('manu,cat')
->setMinimumDocumentFrequency(1)
->setMinimumTermFrequency(1)
->setInterestingTerms('details')
->setMatchInclude(true);

$query->setQuery('id:SP2514N')
->createFilterQuery('stock')->setQuery('inStock:true');

// this executes the query and returns the result
$resultset = $client->select($query);

echo 'Document used for matching:<br/><table>';
foreach ($resultset->getMatch() 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><hr/>';

// display the total number of MLT documents found by solr
echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
echo '<b>Listing of matched docs:</b>';

// show MLT documents using the resultset iterator
echo 'Documents used for matching:<br/>';
// show documents using the resultset iterator
foreach ($resultset as $document) {

echo '<hr/><table>';
echo '<table>';

// the documents are also iterable, to get all fields
foreach ($document as $field => $value) {
Expand All @@ -55,4 +47,31 @@
echo '</table>';
}

echo '<hr/>';

$mlt = $resultset->getMoreLikeThis();

// display the total number of MLT documents found by solr
echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
echo '<b>Listing of matched docs:</b>';

// show MLT documents using the resultset iterator
foreach ($mlt as $results) {
foreach ($results 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();
2 changes: 2 additions & 0 deletions examples/2.3.2-mlt-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require(__DIR__.'/init.php');
htmlHeader();

echo "<h2>Note: The techproducts example doesn't include a /mlt handler anymore!</h2>";

// create a client instance
$client = new Solarium\Client($config);

Expand Down
6 changes: 1 addition & 5 deletions examples/5.2-extending.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ class MyClient extends Client
* Querytype mappings
*/
protected $queryTypes = array(
self::QUERY_SELECT => array(
'query' => 'MyQuery',
'requestbuilder' => 'Solarium\QueryType\Select\RequestBuilder',
'responseparser' => 'Solarium\QueryType\Select\ResponseParser'
),
self::QUERY_SELECT => MyQuery::class,
);
}

Expand Down
9 changes: 1 addition & 8 deletions examples/6.1.1-zend-http-adapter.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
<?php

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();

require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);

// set the adapter to zendhttp and get a zendhttp client instance reference
$client->setAdapter('Solarium\Core\Client\Adapter\ZendHttp');
$zendHttp = $client->getAdapter()->getZendHttp();

// you can use any of the zend_http features, like http-authentication
$zendHttp->setAuth('user', 'password!', Zend_Http_Client::AUTH_BASIC);
$client->setAdapter(\Solarium\Core\Client\Adapter\Zend2Http::class);

// get a select query instance
$query = $client->createSelect();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();

require(__DIR__.'/init.php');
htmlHeader();

Expand All @@ -12,7 +9,7 @@
// set the adapter to curl
// note that this is only shown for documentation purposes, normally you don't need
// to do this as curl is the default adapter
$client->setAdapter('Solarium\Core\Client\Adapter\Curl');
$client->setAdapter(\Solarium\Core\Client\Adapter\Curl::class);

// get a select query instance
$query = $client->createSelect();
Expand Down
42 changes: 0 additions & 42 deletions examples/6.1.2-pecl-http-adapter.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();

require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);

// set the adapter to curl
$client->setAdapter('Solarium\Core\Client\Adapter\Http');
$client->setAdapter(\Solarium\Core\Client\Adapter\Http::class);

// get a select query instance
$query = $client->createSelect();
Expand Down
Loading

0 comments on commit cccdc04

Please sign in to comment.