Documentation
8.2 Solr type "relation_json"
Solr does not allow storage of key/value or an array. This may get you into problems which need a lot of database queries to solve, mainly for facet fields.
The "relation_json" type allows storage of a json object into a (facet) field, which makes storage of multiple fields a lot easier.
This type can be used to store multiple properties of the relations of a content item in solr.
In your solr mapping you can add the content like this:
1 2 3 4 5 6 7 8 9 10 11 | <<strong>type </strong>name<strong>="integrated.relation_json"</strong>> <<strong>options</strong>> <<strong>string </strong>key<strong>="alias"</strong>>solr_alias</<strong>string</strong>> <<strong>string </strong>key<strong>="relation_id"</strong>>integrated_relation_id</<strong>string</strong>> <<strong>array </strong>key<strong>="properties"</strong>> <<strong>string </strong>key<strong>="id"</strong>>id</<strong>string</strong>> <<strong>string </strong>key<strong>="slug"</strong>>slug</<strong>string</strong>> <<strong>string </strong>key<strong>="title_alias"</strong>>title</<strong>string</strong>> </<strong>array</strong>> </<strong>options</strong>> </<strong>type</strong>> |
The alias is the name for the field in solr.
The relation_id is the relationId of the relation. All the references of this relation will be stored in solr using json_encode. In the properties you have to define the properties that will be stored in solr.
The properties work the same as Integrated fields, the key is the alias, the value is the property.
You have to use a json_decode filter to read the values as an array. There is no twig json_decode filter available in Integrated yet, you can build your own twig filter or use php.
Example of json_decode twig function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <strong><?php namespace </strong>YourBundle\Twig\Extension; <em> </em><strong>class </strong>JsonDecodeExtension <strong>extends </strong>\Twig_Extension { <em>/** * <strong>@return </strong>array */ </em><strong>public function </strong>getFilters() { <strong>return </strong>[ <strong>new </strong>\Twig_SimpleFilter(<strong>'json_decode'</strong>, [$this, <strong>'jsonDecode'</strong>]), ]; } <em>/** * <strong>@param </strong>$jsonArray * <strong>@return </strong>mixed */ </em><strong>public function </strong>jsonDecode($jsonArray) { <strong>return </strong>json_decode($jsonArray); } <em>/** * <strong>@return </strong>string */ </em><strong>public function </strong>getName() { <strong>return </strong><strong>'json_decode'</strong>; } } |