Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-22308

SearchService: Filtering on Attributes of Type "Object Relation" does not work

    Details

      Description

      When filtering on an attribute of type Object Relation the results are not as expected.

      (as in

      new Criterion\Field( 'recipient', Criterion\Operator::EQ, $currentUserId )
      

      where 'recipient' is an attribute of datatype 'Object Relation')

      This seems to be due to the fact that the searchService only takes into consideration the database fields sort_key_int or sort_key_string (depending onthe datatype).

      But in the converter class for Relation the sortKey is hardcoded to "false" which leads to empty entries in the sort_key_int column of ezcontentobject_attribute table rows for Object Relations.

      My quick fix was to replace

      Relation.php

      public function toFieldValue( StorageFieldValue $value, FieldValue $fieldValue )
          {
              $fieldValue->data = array(
                  "destinationContentId" => $value->dataInt,
              );
              $fieldValue->sortKey = false;
          }
      

      with

      Relation.php

      public function toFieldValue( StorageFieldValue $value, FieldValue $fieldValue )
          {
              $fieldValue->data = array(
                  "destinationContentId" => $value->dataInt,
              );
              $storageFieldValue->sortKeyInt = (int)$value->sortKey;
          }
      

      which seems to fix the problem. Since i'm no kernel-expert on eZ5 i'm not sure if this is the best solution, though.

        Issue Links

          Activity

          Hide
          Florent Huck (Inactive) added a comment -

          Hi Rene,

          I got the same problem but it seems that $storageFieldValue does not exist.
          Replace it by $fieldValue :

          public function toFieldValue( StorageFieldValue $value, FieldValue $fieldValue )
              {
                  $fieldValue->data = array(
                      "destinationContentId" => $value->dataInt ?: null,
                  );
                  $fieldValue->sortKey = (int)$value->sortKeyInt;
              }

          Show
          Florent Huck (Inactive) added a comment - Hi Rene, I got the same problem but it seems that $storageFieldValue does not exist. Replace it by $fieldValue : public function toFieldValue( StorageFieldValue $value, FieldValue $fieldValue ) { $fieldValue->data = array( "destinationContentId" => $value->dataInt ?: null, ); $fieldValue->sortKey = (int)$value->sortKeyInt; }
          Hide
          Florent Huck (Inactive) added a comment - - edited

          https://github.com/ezsystems/ezpublish-kernel/pull/838

          If you create a content with relation using the Public API (instead of legacy), sort_key_string is never filled.
          You have to modify also this :

          public function toStorageValue( FieldValue $value, StorageFieldValue $storageFieldValue )
              {
                  $storageFieldValue->dataInt = !empty( $value->data['destinationContentId'] )
                      ? $value->data['destinationContentId']
                      : null;
                  $storageFieldValue->sortKeyInt = $value->sortKey;
              }
          

          Show
          Florent Huck (Inactive) added a comment - - edited https://github.com/ezsystems/ezpublish-kernel/pull/838 If you create a content with relation using the Public API (instead of legacy), sort_key_string is never filled. You have to modify also this : public function toStorageValue( FieldValue $value, StorageFieldValue $storageFieldValue ) { $storageFieldValue->dataInt = !empty( $value->data['destinationContentId'] ) ? $value->data['destinationContentId'] : null; $storageFieldValue->sortKeyInt = $value->sortKey; }
          Show
          André Rømcke added a comment - Fixed in 5.3: https://github.com/ezsystems/ezpublish-kernel/commit/5870c7c350f9db703f1ca1b42b65019363fa9ec4
          Hide
          Pedro Resende (Inactive) added a comment -

          Tested and approved by Q.A.

          Show
          Pedro Resende (Inactive) added a comment - Tested and approved by Q.A.

            People

            • Assignee:
              Unassigned
              Reporter:
              Rene Hrdina
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours, 40 minutes
                7h 40m