-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Query Elevation Component (#597)
* Added Query Elevation Component * Added docs for Query Elevation Component * Added integration test against techproducts
- Loading branch information
1 parent
ee77b43
commit e72d6b1
Showing
12 changed files
with
796 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...es/select-query/building-a-select-query/components/query-elevation-component.md
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,73 @@ | ||
Query Elevation is a Solr component that lets you configure the top results for a given query regardless of the normal Lucene scoring. Elevated query results can be configured in an external XML file or at request time. For more info see <https://lucene.apache.org/solr/guide/the-query-elevation-component.html>. | ||
|
||
Options | ||
------- | ||
|
||
| Name | Type | Default value | Description | | ||
|-----------------|---------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| transformers | string | [elevated] | Comma separated list of transformers to annotate each document. The [elevated] transformer tells whether or not the document was elevated. | | ||
| enableElevation | boolean | null | For debugging it may be useful to see results with and without elevation applied. To get results without elevation, use false. | | ||
| forceElevation | boolean | null | By default, this component respects the requested sort parameter. To return elevated documents first, use true. | | ||
| exclusive | boolean | null | You can force Solr to return only the results specified in the elevation file by using true. | | ||
| markExcludes | boolean | null | You can include documents that the elevation configuration would normally exclude by using true. The [excluded] transformer is added to each document. | | ||
| elevateIds | string | null | Comma separated list of documents to elevate. This overrides the elevations _and_ exclusions that are configured for the query in the elevation file. | | ||
| excludeIds | string | null | Comma separated list of documents to exclude. This overrides the elevations _and_ exclusions that are configured for the query in the elevation file. | | ||
|| | ||
|
||
Example | ||
------- | ||
|
||
```php | ||
<?php | ||
|
||
require(__DIR__.'/init.php'); | ||
htmlHeader(); | ||
|
||
// create a client instance | ||
$client = new Solarium\Client($config); | ||
|
||
// get a select query instance | ||
$query = $client->createSelect(); | ||
$query->setQuery('electronics'); | ||
|
||
// set a handler that is configured with an elevator component in solrconfig.xml (or add it to your default handler) | ||
$query->setHandler('elevate'); | ||
|
||
// get query elevation component | ||
$elevate = $query->getQueryElevation(); | ||
|
||
// return elevated documents first | ||
$elevate->setForceElevation(true); | ||
|
||
// specify documents to elevate and/or exclude if you don't use an elevation file or want to override it at request time | ||
$elevate->setElevateIds(array('VS1GB400C3', 'VDBDB1A16')); | ||
$elevate->setExcludeIds(array('SP2514N', '6H500F0')); | ||
|
||
// document transformers can be omitted from the results | ||
//$elevate->clearTransformers(); | ||
|
||
// this executes the query and returns the result | ||
$resultset = $client->select($query); | ||
// display the total number of documents found by solr | ||
echo 'NumFound: '.$resultset->getNumFound(); | ||
|
||
// show documents using the resultset iterator | ||
foreach ($resultset 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>'; | ||
} | ||
|
||
} | ||
|
||
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(__DIR__.'/init.php'); | ||
htmlHeader(); | ||
|
||
// create a client instance | ||
$client = new Solarium\Client($config); | ||
|
||
// get a select query instance | ||
$query = $client->createSelect(); | ||
$query->setQuery('electronics'); | ||
|
||
// set a handler that is configured with an elevator component in solrconfig.xml (or add it to your default handler) | ||
$query->setHandler('elevate'); | ||
|
||
// get query elevation component | ||
$elevate = $query->getQueryElevation(); | ||
|
||
// return elevated documents first | ||
$elevate->setForceElevation(true); | ||
|
||
// specify documents to elevate and/or exclude if you don't use an elevation file or want to override it at request time | ||
$elevate->setElevateIds(array('VS1GB400C3', 'VDBDB1A16')); | ||
$elevate->setExcludeIds(array('SP2514N', '6H500F0')); | ||
|
||
// document transformers can be omitted from the results | ||
//$elevate->clearTransformers(); | ||
|
||
// this executes the query and returns the result | ||
$resultset = $client->select($query); | ||
// display the total number of documents found by solr | ||
echo 'NumFound: '.$resultset->getNumFound(); | ||
|
||
// show documents using the resultset iterator | ||
foreach ($resultset 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>'; | ||
} | ||
|
||
} | ||
|
||
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
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.