ext-solr icon indicating copy to clipboard operation
ext-solr copied to clipboard

[BUG] Duplicate results with "Hide at login" content

Open dmitryd opened this issue 2 years ago • 1 comments

Describe the bug

Create two content elements on the page:

  • normal content with some text
  • any text, set "Hide at login" user group

Index. Search for the term. You will see two entries for this page.

The problem happens because solr indexes user groups 0 (regular not logged in user) and -1 (show content when there is no login) for the anonymous user.

Duplicate is not displayed if I add a filter like this:

plugin.tx_solr.search.query.filter.noHideAtLogin = !access:"c:-1"

I believe the access filter should only limit the query to 0 when user is not logged in.

When user is logged in, it becomes more complicated because solr cannot know if the version with -1 or any groups exist.

Perhaps a better fix on the php side:

--- solr/Classes/IndexQueue/FrontendHelper/UserGroupDetector.php
+++ solr/Classes/IndexQueue/FrontendHelper/UserGroupDetector.php
@@ -196,8 +196,9 @@
         if ($this->originalTca[$table]['ctrl']['enablecolumns']['fe_group']) {
             $frontendGroups = $record[$this->originalTca[$table]['ctrl']['enablecolumns']['fe_group']];
 
-            if (empty($frontendGroups)) {
+            if (empty($frontendGroups) || $frontendGroups == '-1') {
                 // default = public access
+                // -1 is "hide at login", which is effectively "0"
                 $frontendGroups = 0;
             } else {
                 if ($this->request->getParameter('loggingEnabled')) {

Used versions (please complete the following information):

  • TYPO3 Version: 11.5
  • EXT:solr Version: release-11.5.x (same with previous versions)
  • PHP Version: 8.0

Additional context

Related #464

dmitryd avatar Feb 04 '22 13:02 dmitryd

The same problem occurs with "Show at any login [-2]" and any other fe_group

For each element with a fe_group != 0 setting, a new duplicate is added.

Example

Content 1: normal access, bodytext="public content" Content 2: Hide at login (-1), bodytext="hide at login" Content 3: Show at login (-2), bodytext="show at login" Content 4: any fe-group (int > 0), bodytext="show for usergroup"

There will be 4 results for the same page

Here's the json result from the Solr Admin:

{
  "responseHeader":{
    "status":0,
    "QTime":0,
    "params":{
      "q":"uid:164",
      "fl":"uid,title,type,variantId,changed,rootline,access,_version_,content,contentExact",
      "q.op":"OR",
      "_":"1649420426949"}},
  "response":{"numFound":4,"start":0,"numFoundExact":true,"docs":[
      {
        "type":"pages",
        "uid":164,
        "variantId":"7b372e6e51ecd807b831bd8498217254e423915d/pages/164",
        "changed":"2022-04-08T14:37:10Z",
        "rootline":["0-1/",
          "1-1/164/"],
        "title":"solrtest",
        "content":"public content show at login",
        "contentExact":"public content show at login",
        "access":["r:0"],
        "_version_":1729544119947100160},
      {
        "type":"pages",
        "uid":164,
        "variantId":"7b372e6e51ecd807b831bd8498217254e423915d/pages/164",
        "changed":"2022-04-08T14:37:10Z",
        "rootline":["0-1/",
          "1-1/164/"],
        "title":"solrtest",
        "content":"public content hide at login show at login",
        "contentExact":"public content hide at login show at login",
        "access":["r:0"],
        "_version_":1729544120133746688},
      {
        "type":"pages",
        "uid":164,
        "variantId":"7b372e6e51ecd807b831bd8498217254e423915d/pages/164",
        "changed":"2022-04-08T14:37:10Z",
        "rootline":["0-1/",
          "1-1/164/"],
        "title":"solrtest",
        "content":"public content show at login",
        "contentExact":"public content show at login",
        "access":["r:0"],
        "_version_":1729544120310956032},
      {
        "type":"pages",
        "uid":164,
        "variantId":"7b372e6e51ecd807b831bd8498217254e423915d/pages/164",
        "changed":"2022-04-08T14:37:10Z",
        "rootline":["0-1/",
          "1-1/164/"],
        "title":"solrtest",
        "content":"public content show at login show for usergroup",
        "contentExact":"public content show at login show for usergroup",
        "access":["r:0"],
        "_version_":1729544120488165376}]
  }}

thomasrawiel avatar Apr 08 '22 12:04 thomasrawiel