Skip to content

Commit cccdc04

Browse files
author
Markus Kalkbrenner
authored
fix examples (#677)
fixes #675 fixes #674
1 parent e279403 commit cccdc04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+415
-318
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ All notable changes to the solarium library will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [5.0.2]
8+
### Fixed
9+
- Spellchecker result isn't NULL in case of no suggestions and correctly spelled
10+
- RangeFacet Result
11+
- Solarium\QueryType\Select\Result and Component return types
12+
- Solarium\Component\Highlighting::setFields() should accept comma separated string, too
13+
- Solarium\Component\Result\Grouping\ValueGroup various return types
14+
- Solarium\Component\RequestBuilder\RequestParamsTrait::addParam should not add empty arrays
15+
- MinimumScoreFilterPlugin
16+
- Running the examples
17+
18+
### Added
19+
- Solarium\Component\MoreLikeThis::setInterestingTerms()
20+
- Solarium\Component\MoreLikeThis::setMatchInclude()
21+
- Solarium\Component\MoreLikeThis::setMatchOffset()
22+
23+
724
## [5.0.1]
825
### Fixed
926
- Getting started documentation

README.md

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -48,50 +48,9 @@ has to be changed to something like
4848

4949
## Run the examples
5050

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

53-
### Add repository section
54-
55-
Add or update the repository sections in your `composer.json` file.
56-
57-
```
58-
"repositories": [
59-
{
60-
"type": "vcs",
61-
"url": "git@github.com:solariumphp/solarium.git"
62-
}
63-
]
64-
```
65-
66-
### Reinstall
67-
68-
You need to fetch the newly configured git checkout. This will fetch the examples too.
69-
70-
```
71-
composer install
72-
```
73-
74-
### Make a copy of settings.dist.php
75-
76-
You must copy this file into your project root.
77-
78-
```
79-
cp ./vendor/solarium/solarium/examples/config.dist.php ./config.php
80-
```
81-
82-
Now you can change the `./config.php` if you are not using the default solr settings.
83-
84-
### Start webserver
85-
86-
Start the webserver from within the project root.
87-
88-
```
89-
php -S localhost:8888
90-
```
91-
92-
### Run the examples
93-
94-
Open http://localhost:8888/vendor/solarium/solarium/examples/
9554

9655
## More information
9756

docs/getting-started.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Some users of Solarium have been nice enough to create easy ways of integrating
103103
- Lithium <https://github.com/joseym/li3_solr>
104104
- Fuel PHP <https://github.com/bgrimes/fuelphp-solarium>
105105
- Yii <https://github.com/estahn/YiiSolarium>
106+
- Drupal <https://www.drupal.org/project/search_api_solr>
107+
- Typo3 <https://extensions.typo3.org/extension/solr/>
106108
- Magento <https://github.com/jeroenvermeulen/magento-solarium>
107109
- Wordpress <https://github.com/pantheon-systems/solr-for-wordpress>
108110

@@ -339,13 +341,19 @@ For all options (like boosting) see the docs.
339341
Example code
340342
============
341343

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

349-
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.
352+
Afterwards you need to configure a web server to use the `examples` folder as docroot. But the easiest way is to use the
353+
built-in web server of PHP. To do so continue like this:
354+
```
355+
cd examples
356+
php -S localhost:8888
357+
```
350358

351-
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)
359+
Now open `http://localhost:8888/` in your browser and follow the instructions.

examples/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
config.php

examples/2.1.5.10-stats.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
echo 'Stddev: ' . $field->getStddev() . '<br/>';
3434

3535
echo '<h2>Field facets</h2>';
36-
foreach ($field->getFacets() as $field => $facet) {
37-
echo '<h3>Facet ' . $field . '</h3>';
36+
foreach ($field->getFacets() as $facetName => $facet) {
37+
echo '<h3>Facet ' . $facetName . '</h3>';
3838
foreach ($facet as $facetStats) {
3939
echo '<h4>Value: ' . $facetStats->getValue() . '</h4>';
4040
echo 'Min: ' . $facetStats->getMin() . '<br/>';

examples/2.1.5.6-grouping-by-field.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
foreach ($fieldGroup as $valueGroup) {
3232

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

3536
foreach ($valueGroup as $document) {
3637

examples/2.1.5.7-grouping-by-query.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require(__DIR__.'/init.php');
44
htmlHeader();
55

6+
echo "<h2>Note: Query grouping seems to be broken in Solr 8.0.0!</h2>";
7+
68
// create a client instance
79
$client = new Solarium\Client($config);
810

examples/2.1.5.8-distributed-search.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require(__DIR__.'/init.php');
44
htmlHeader();
55

6+
echo "<h2>Note: The techproducts isn't distributed by default!</h2>";
7+
68
// create a client instance
79
$client = new Solarium\Client($config);
810

examples/2.1.5.9-spellcheck.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@
77
$client = new Solarium\Client($config);
88

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

1319
// add spellcheck settings
14-
$spellcheck = $query->getSpellcheck();
15-
$spellcheck->setQuery('tes');
16-
$spellcheck->setCount(10);
17-
$spellcheck->setBuild(true);
18-
$spellcheck->setCollate(true);
19-
$spellcheck->setExtendedResults(true);
20-
$spellcheck->setCollateExtendedResults(true);
20+
$spellcheck = $query->getSpellcheck()
21+
->setCount(10)
22+
->setBuild(true)
23+
->setCollate(true)
24+
->setExtendedResults(true)
25+
->setCollateExtendedResults(true)
26+
->setDictionary('default');
2127

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

examples/2.3.1-mlt-query.php

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,30 @@
99
$client = new Client($config);
1010

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

14-
$query->setQuery('id:SP2514N');
15-
$query->setMltFields('manu,cat');
16-
$query->setMinimumDocumentFrequency(1);
17-
$query->setMinimumTermFrequency(1);
18-
$query->createFilterQuery('stock')->setQuery('inStock:true');
19-
$query->setInterestingTerms('details');
20-
$query->setMatchInclude(true);
18+
$query->getMoreLikeThis()
19+
->setFields('manu,cat')
20+
->setMinimumDocumentFrequency(1)
21+
->setMinimumTermFrequency(1)
22+
->setInterestingTerms('details')
23+
->setMatchInclude(true);
24+
25+
$query->setQuery('id:SP2514N')
26+
->createFilterQuery('stock')->setQuery('inStock:true');
2127

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

25-
echo 'Document used for matching:<br/><table>';
26-
foreach ($resultset->getMatch() as $field => $value) {
27-
// this converts multivalue fields to a comma-separated string
28-
if (is_array($value)) {
29-
$value = implode(', ', $value);
30-
}
31-
32-
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
33-
}
34-
echo '</table><hr/>';
35-
36-
// display the total number of MLT documents found by solr
37-
echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
38-
echo '<b>Listing of matched docs:</b>';
39-
40-
// show MLT documents using the resultset iterator
31+
echo 'Documents used for matching:<br/>';
32+
// show documents using the resultset iterator
4133
foreach ($resultset as $document) {
4234

43-
echo '<hr/><table>';
35+
echo '<table>';
4436

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

50+
echo '<hr/>';
51+
52+
$mlt = $resultset->getMoreLikeThis();
53+
54+
// display the total number of MLT documents found by solr
55+
echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
56+
echo '<b>Listing of matched docs:</b>';
57+
58+
// show MLT documents using the resultset iterator
59+
foreach ($mlt as $results) {
60+
foreach ($results as $document) {
61+
echo '<hr/><table>';
62+
63+
// the documents are also iterable, to get all fields
64+
foreach ($document as $field => $value) {
65+
// this converts multivalue fields to a comma-separated string
66+
if (is_array($value)) {
67+
$value = implode(', ', $value);
68+
}
69+
70+
echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
71+
}
72+
73+
echo '</table>';
74+
}
75+
}
76+
5877
htmlFooter();

0 commit comments

Comments
 (0)