Domain Access sites pointing wrong URL in return

Created on 18 August 2023, over 1 year ago

Problem

I have a D9 site that uses Domain Access with Federated Search, and when content is shared with Domain Access, the URLs seem to point to the wrong site randomly. See Screenshoot-1

I have tuned on these modules:

Domain

Domain Access

Domain Configuration

Domain Configuration UI

Search API

Search API Autocomplete

Search API AZ Glossary

Search API Federated Solr

Search API Field Map

Search API Solr.

I have setup the "Site Name" field in the search index. See Screenshot-sitename.png

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @plinkowski
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    @plinkowski I think this is properly handled on the Domain side using Domain Source, which allows you to force a canonical URL for any node assigned to multiple domains.

    I suspect that without using that module, the search index will be based on the domain from which the indexing runs.

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Technical notes -- taken from this module's README:

    "sm_site_name":["Drupal 8"],
    "sm_urls":["http://d8.fs-demo.local/node/10"],
    
    • The annotation "sm_" means "string multiple" (an array of strings)
    • The React application simply iterates over those arrays when printing links to the node
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Technical note 2:

    It is possible that the getSiteName() Helper is not working properly since the DOMAIN_ACCESS_FIELD constant now lives in an interface. See this code:

          // @TODO: Handle domain access properly.
          if (defined('DOMAIN_ACCESS_FIELD')) {
            $manager = \Drupal::service('domain.negotiator');
            $active_domain = $manager->getActiveDomain();
            $site_name = $active_domain->label();
          }
    

    See lines 167-172 of src/Utility/Helpers.php

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    I see, Joe provided more clarity.

    The SiteName and URL fields (in Solr) are both positional arrays. We need to ensure that they are sorted in the same way prior to indexing.

    It may be that DomainAccessManager::getContentUrls needs to use $domains = $this->domainStorage->loadMultipleSorted($list); instead of $domains = $this->domainStorage->loadMultiple($list);

    See line 187 of domain_access/src/DomainAccessManager.php

    Worst case, those fields should be sorted / reconciled in hook_search_api_solr_documents_alter() inside Domain Access.

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Moving to Search API Field Map, which is responsible for getting the Site Name and URL values.

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Paul-

    I have not been able to reproduce this locally running Drupal 10. Here's what my index shows:

            "sm_urls":[
              "http://example.local/node/10",
              "http://four.example.local/node/10",
              "http://one.example.local/node/10",
              "http://two.example.local/node/10"
             ],
            "sm_site_name":[
              "Domain 10", (this is the default domain)
              "Four",
              "One",
              "Two"
             ],
    

    This matches exactly what we expect.

    Some questions:

    * What Drupal and module versions are you running?
    * What is in "$config['search_api_federated_solr.search_app.settings']['facet']['site_name']['site_list'] " in settings.php?
    * Do the site name filters work as expected?
    * Do you have admin access to the SOLR index so we can see the raw data (like shown above)?

  • Status changed to Active over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    We managed to track this down.

    Apparently, SOLR auto-sorts multivalue text fields (see https://solr.apache.org/guide/7_2/docvalues.html) for instance. In this case, since the names of the sites and the urls don't match (in alphabetical order), the sort is thrown off.

    Here's how we broke that on local testing:

    27
            "sm_urls":["http://example.local/node/1",
              "http://four.example.local/node/1",
              "http://one.example.local/node/1",
              "http://three.example.local/node/1",
              "http://two.example.local/node/1"],
            "sm_site_name":["Domain 10",
              "Four",
              "One",
              "Two",
              "XThree"],
    

    Note that both arrays are alpha-sorted. The "XThree" throws that off.

    There might be ways to force that behavior to change at the index level, but that would involve handling schema files, which could be problematic.

    It may be better to have a handler to normalize this data after it is retrieved. We would load the sort in a subscriber to

    \Drupal\search_api_solr\Event\PostExtractResultsEvent

    Which is earlier versions is hook_search_api_solr_search_results_alter()

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    The correct solution would seem to be:

    • When using Domain Access, change the Site Name and URLs fields to Storage Only in the Search API field configuration
    • Write an implementation of the \Drupal\search_api_solr\Event\PostExtractResultsEvent handler in Search API Field Map (which is where we handle all domain-specific handling.
    • In that implementation, copy any z*_ field for a document to s*_ so that it can be used by the React app.
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    We have a fix for this inside the main module. Re-filing.

  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    And the patch.

  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Last patch has bad logic.

  • πŸ‡ΊπŸ‡ΈUnited States ddavisboxleitner

    I have tested the patch and it works as intended. In testing, the site names and urls are in correct order.

    sm_urls
    
    array (
      0 => '//example.local',
      1 => '//one.example.local',
      2 => '//two.example.local',
      3 => '//four.example.local',
    )
    
    sm_site_name
    
    array (
      0 => 'Domain 10',
      1 => 'One',
      2 => 'Two',
      3 => 'Four',
    )
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Original patch was malformed and returned links to the site homepages, not the content.

  • Merge request !13Apply patch from #15 β†’ (Merged) created by agentrickard
  • Pipeline finished with Skipped
    about 2 months ago
    #324386
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024