dotCMS / core

Headless/Hybrid Content Management System for Enterprises
http://dotcms.com
Other
865 stars 467 forks source link

Support Or logic operator in CA Query filters #30190

Open freddyDOTCMS opened 1 month ago

freddyDOTCMS commented 1 month ago

Parent Issue

30141

Problem Statement

We create a new query sintax for the CA Endpoint and ViewTool, is not really the same CubeJs syntax, let see an example on the filter attribute:

Example to get all the request for any PAGE or for the URL equals to something like '/dA/716dcfa9-537d-419a-837f-73084a499cf3/fileAsset/1200w/50q/bg-footer.jpg', the CubeJS query look like:


{
  "measures": [
    "request.count"
  ],
  "filters": [
    {
       "or": [
            {
              "member": "request.whatAmI",
              "operator": "equals",
              "values": [
                "PAGE"
              ]
            },
            {
              "member": "request.url",
              "operator": "equals",
              "values": [
                "/dA/716dcfa9-537d-419a-837f-73084a499cf3/fileAsset/1200w/50q/bg-footer.jpg"
              ]
            }
        ]
     }
  ],
  "dimensions": [
    "request.url"
  ],
  "order": {
    "request.count": "desc"
  }
}

In our less verbose Syntax:


{
  "measures": [
    "request.count"
  ],
  "filters": "member": "request.whatAmI = ['PAGE'] OR request.url = ['/dA/716dcfa9-537d-419a-837f-73084a499cf3/fileAsset/1200w/50q/bg-footer.jpg"']",
  "dimensions": [
    "request.url"
  ],
  "order": {
    "request.count": "desc"
  }
}

It is failing because it translate it like to different filters in the filters attribute and it is a AND.

Steps to Reproduce

set ($queryMap = {"measures" : ["request.count"],

            "orders": "request.count desc",
            "dimensions":["request.url"],
            "filters":"request.whatAmI = ['PAGE'] OR request.url = ['/dA/716dcfa9-537d-419a-837f-73084a499cf3/fileAsset/1200w/50q/bg-footer.jpg']"
            })

set($collection = $analytics.runReportFromMap($queryMap).getResults())

Accessed Pages

foreach($item in $collection)

-> URL: $item.get("request.url").get() -> Count: $item.get("request.count").get()

end

You must be request to both the FIle and the Home Page

Acceptance Criteria

Make the Or filter works when we retrieve CA data

dotCMS Version

latest

Proposed Objective

Core Features

Proposed Priority

Priority 2 - Important

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

jcastro-dotcms commented 1 month ago

This issue is NOT reproducible anymore. The OR logical operator is working as expected.

jcastro-dotcms commented 1 month ago

NOTE TO QA:

In order to test this, click around the pages in the front-end. Then, you can create a test HTML Page and add a Code Snippet to it with the following code:

#set ($queryMap = {"measures" : ["request.count"],
"orders": "request.count desc",
"dimensions":["request.url"],
"filters":"request.whatAmI = ['PAGE'] or request.url = ['<GET-YOUR-OWN-FILE-ASSET-URL-FROM-CUBEJS>']"
})

#set($collection = $analytics.runReportFromMap($queryMap).getResults())

<h2>Accessed Pages</h2>

#foreach($item in $collection)
<ul>
    <li>URL: $item.get("request.url").get()</li>
    <li>Count: $item.get("request.count").get()</li>
</ul>
#end

Replace the <GET-YOUR-OWN-FILE-ASSET-URL-FROM-CUBEJS> with something similar to this: /dA/716dcfa9-537d-419a-837f-73084a499cf3/fileAsset/1200w/50q/bg-footer.jpg

josemejias11 commented 1 month ago

Approved: Tested on trunk_a12617a, Docker, macOS 14.5, FF v126.0.1