-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from netgen/NGSTACK-489-extra-solr-fields
NGSTACK-489 Extra solr fields
- Loading branch information
Showing
18 changed files
with
746 additions
and
9 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,56 @@ | ||
Extra fields from Solr | ||
====================== | ||
|
||
This feature allows you to extract additionally indexed Solr fields from each SearchHit in SearchResult. For example, you can index some fields from children content on the parent content and then get those fields during search (eg. children count). | ||
|
||
.. note:: | ||
|
||
This feature is available only with the Solr search engine. | ||
|
||
1. Usage | ||
~~~~~~~~ | ||
|
||
In order for this functionality to work, you have to use overridden `Netgen\EzPlatformSearchExtra\API\Values\Content\Search\Query` or `Netgen\EzPlatformSearchExtra\API\Values\Content\Search\LocationQuery` queries and use it's property `extraFields` to provide a list of additional fields that you want to extract from the Solr document. Those fields, if exist, and their values will appear in the `extraFields` property of each `SearchHit` object contained in the `SearchResult.` | ||
|
||
2. Example | ||
~~~~~~~~~~ | ||
|
||
Example of a content field mapper: | ||
|
||
.. code-block:: php | ||
public function mapFields(SPIContent $content) | ||
{ | ||
return [ | ||
new Field( | ||
'extra_field_example', | ||
5, | ||
new IntegerField() | ||
), | ||
]; | ||
} | ||
Search example: | ||
|
||
.. code-block:: php | ||
/** @var \Netgen\EzPlatformSearchExtra\API\Values\Content\Search\Query $query **/ | ||
$query = new Query(); | ||
$query->extraFields = [ | ||
'extra_field_example_i', | ||
]; | ||
/** @var \Netgen\EzPlatformSiteApi\API\FindService $findService **/ | ||
$searchResult = $findService->findContent($query); | ||
/** @var \Netgen\EzPlatformSearchExtra\API\Values\Content\Search\SearchHit $searchHit **/ | ||
foreach ($searchResult->searchHits as $searchHit) { | ||
var_dump($searchHit->extraFields); | ||
} | ||
This will output the following data: | ||
|
||
.. code-block:: shell | ||
array(1) { ["extra_field_example_i"]=> int(5) } |
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 |
---|---|---|
|
@@ -9,5 +9,6 @@ Reference | |
random_sort | ||
subdocuments | ||
spellcheck_suggestions | ||
extra_fields | ||
|
||
.. include:: /reference/map.rst.inc |
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,16 @@ | ||
<?php | ||
|
||
namespace Netgen\EzPlatformSearchExtra\API\Values\Content\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\LocationQuery as BaseLocationQuery; | ||
|
||
class LocationQuery extends BaseLocationQuery | ||
{ | ||
/** | ||
* List of additional fields that should be | ||
* extracted from the Solr document for each hit. | ||
* | ||
* @var string[] | ||
*/ | ||
public $extraFields; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Netgen\EzPlatformSearchExtra\API\Values\Content\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Query as BaseQuery; | ||
|
||
class Query extends BaseQuery | ||
{ | ||
/** | ||
* List of additional fields that should be | ||
* extracted from the Solr document for each hit. | ||
* | ||
* @var string[] | ||
*/ | ||
public $extraFields; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace Netgen\EzPlatformSearchExtra\API\Values\Content\Search; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit as BaseSearchHit; | ||
|
||
class SearchHit extends BaseSearchHit | ||
{ | ||
/** | ||
* Additional fields from Solr document. | ||
* | ||
* @var array | ||
*/ | ||
public $extraFields; | ||
} |
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
Oops, something went wrong.