Details

      Description

      We are creating a query with this criterion:

      new CriterionLanguageCode($this->contentHelper->getCurrentLanguageFromRequest())

      where $this->contentHelper->getCurrentLanguageFromRequest() is either 'eng-GB' or 'rus-RU'.

      This is the query object:

      object(eZPublishAPIRepositoryValuesContentQuery)#537 (6) {
      ["criterion"]=>
      object(eZPublishAPIRepositoryValuesContentQueryCriterionLogicalAnd)#538 (4) {
      ["criteria"]=>
      array(4) {
      [0]=>
      object(eZPublishAPIRepositoryValuesContentQueryCriterionContentTypeIdentifier)#539 (3) {
      ["operator"]=>
      string(1) "="
      ["value"]=>
      array(1) {
      [0]=>
      string(14) "in_or_out_post"
      }
      ["target"]=>
      NULL
      }
      [1]=>
      object(eZPublishAPIRepositoryValuesContentQueryCriterionLanguageCode)#531 (3) {
      ["operator"]=>
      string(1) "="
      ["value"]=>
      array(1) {
      [0]=>
      string(6) "eng-GB"
      }
      ["target"]=>
      NULL
      }
      [2]=>
      object(eZPublishAPIRepositoryValuesContentQueryCriterionVisibility)#532 (3) {
      ["operator"]=>
      string(1) "="
      ["value"]=>
      array(1) {
      [0]=>
      int(0)
      }
      ["target"]=>
      NULL
      }
      [3]=>
      object(eZPublishAPIRepositoryValuesContentQueryCriterionField)#536 (3) {
      ["operator"]=>
      string(2) "<="
      ["value"]=>
      int(1379966002)
      ["target"]=>
      string(12) "publish_date"
      }
      }
      ["operator"]=>
      NULL
      ["value"]=>
      NULL
      ["target"]=>
      NULL
      }
      ["sortClauses"]=>
      array(1) {
      [0]=>
      object(eZPublishAPIRepositoryValuesContentQuerySortClauseField)#526 (3) {
      ["direction"]=>
      string(10) "descending"
      ["target"]=>
      string(5) "field"
      ["targetData"]=>
      object(eZPublishAPIRepositoryValuesContentQuerySortClauseTargetFieldTarget)#525 (2) {
      ["typeIdentifier"]=>
      string(14) "in_or_out_post"
      ["fieldIdentifier"]=>
      string(12) "publish_date"
      }
      }
      }
      ["facetBuilders"]=>
      array(0) {
      }
      ["offset"]=>
      int(0)
      ["limit"]=>
      int(20)
      ["spellcheck"]=>
      NULL
      }
      

      This is the query that is being executed:

      SELECT `ezcontentobject`.`id`, `sort_table_0`.`sort_key_int` AS `sort_column_0`, `sort_table_0`.`sort_key_string` AS `sort_column_0_bis` FROM `ezcontentobject` INNER JOIN ezcontentobject_version ON ezcontentobject.id = ezcontentobject_version.contentobject_id INNER JOIN `ezcontentobject_attribute` AS `sort_table_0` ON ( `sort_table_0`.`contentobject_id` = `ezcontentobject`.`id` AND `sort_table_0`.`version` = `ezcontentobject`.`current_version` ) INNER JOIN `ezcontentclass_attribute` AS `cc_attr_0` ON ( `sort_table_0`.`contentclassattribute_id` = `cc_attr_0`.`id` AND `cc_attr_0`.`identifier` = 'publish_date' ) INNER JOIN `ezcontentclass` AS `cc_0` ON ( `cc_attr_0`.`contentclass_id` = `cc_0`.`id` AND `cc_0`.`identifier` = 'in_or_out_post' ) WHERE ( ( `ezcontentobject`.`contentclass_id` IN ( SELECT `id` FROM `ezcontentclass` WHERE `identifier` IN ( 'in_or_out_post' ) ) AND ( `ezcontentobject`.`language_mask` & 2 ) > 0 AND `ezcontentobject`.`id` IN ( SELECT `contentobject_id` FROM `ezcontentobject_tree` WHERE ( `ezcontentobject_tree`.`is_hidden` = 0 AND `ezcontentobject_tree`.`is_invisible` = 0 ) ) AND `ezcontentobject`.`id` IN ( SELECT `contentobject_id` FROM `ezcontentobject_attribute` WHERE ( `contentclassattribute_id` IN ( '310', '327' ) AND `sort_key_int` <= '1379967524' ) ) AND ( `ezcontentobject`.`section_id` IN ( '1' ) OR ( `ezcontentobject`.`contentclass_id` IN ( '27', '35' ) AND `ezcontentobject`.`section_id` IN ( '3' ) ) ) ) AND ezcontentobject_version.status = 1 ) ORDER BY `sort_column_0` DESC, `sort_column_0_bis` DESC LIMIT 20 OFFSET 0;
      

      These are the database results that are being returned:

      id language_mask language_code sort_column_0 sort_column_0_bis
      101 2 eng-GB 1379547145
      100 6 eng-GB 1379547144
      100 6 rus-RU 1379547144
      103 2 eng-GB 1379374347
      102 6 eng-GB 1379374346
      102 6 rus-RU 1379374346
      105 2 eng-GB 1379201549
      104 6 eng-GB 1379201548
      

      As you can see, I'm getting back duplicate ids for any content object that is available in more than one language which causes me to get fewer results than I need. If I set new CriterionLanguageCode('eng-GB'), I expect to only get back results with a language code of 'eng-GB'. How can I ensure this?

      1. AbstractQuery.php
        4 kB
        Gunnstein Lye
      2. PostQuery.php
        4 kB
        Gunnstein Lye
      3. SearchCommand.php
        3 kB
        Gunnstein Lye

        Activity

        Hide
        Christian Bacher (Inactive) added a comment - - edited

        1. The language criterion does only match content containing a language/translation. This has nothing to do with filtering languages in fields.
        2. The proper fix is: Adding a language parameter in the SortClause\Field and using it in the join of the attribute table.
        -> it makes no sense to sort with multiple languages and if a content field has more than one language it is ambiguous

        Show
        Christian Bacher (Inactive) added a comment - - edited 1. The language criterion does only match content containing a language/translation. This has nothing to do with filtering languages in fields. 2. The proper fix is: Adding a language parameter in the SortClause\Field and using it in the join of the attribute table. -> it makes no sense to sort with multiple languages and if a content field has more than one language it is ambiguous
        Show
        Petar Spanja (Inactive) added a comment - Pull request: https://github.com/ezsystems/ezpublish-kernel/pull/553
        Hide
        Christian Bacher (Inactive) added a comment -

        The main fact is that sorting on a translatable field without specifying a language does not make sense, how should be sorted otherwise? If it can not provided manually there must be implemented some mechanism above the API which decides which language should be used for sorting - may be using the prioritized language setting for the site - there is no information in the repository which can help here.

        Show
        Christian Bacher (Inactive) added a comment - The main fact is that sorting on a translatable field without specifying a language does not make sense, how should be sorted otherwise? If it can not provided manually there must be implemented some mechanism above the API which decides which language should be used for sorting - may be using the prioritized language setting for the site - there is no information in the repository which can help here.
        Show
        Petar Spanja (Inactive) added a comment - Fixed in ezpublish-kernel/master: https://github.com/ezsystems/ezpublish-kernel/commit/463e6e0265d0791f9904bc403ebb9a4e7c517acc
        Hide
        Filipe Dobreira (Inactive) added a comment -

        QA Approved.

        Show
        Filipe Dobreira (Inactive) added a comment - QA Approved.
        Hide
        Filipe Dobreira (Inactive) added a comment -

        QA Approved.

        Show
        Filipe Dobreira (Inactive) added a comment - QA Approved.

          People

          • Assignee:
            Unassigned
            Reporter:
            Gunnstein Lye
          • Votes:
            0 Vote for this issue
            Watchers:
            7 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 - 2 days, 7 hours, 25 minutes
              2d 7h 25m