AI 发现的 XX 结果隐藏 - 默认启用

I’m experimenting with using AI on our discourse forum and so far its pretty good (great work guys), it’s really taking into context user intent and provides very relevant results.

The problem is I see is that the results are hidden by default

I cant find any settings to enable the toggle by default, how does the admin do this? The real power is to enable this feature by default and move away from semantic search which can be a hit or miss.

Funnily I tried to search this this forum using AI and couldn’t get any relevant answers.

1 个赞

Well, AI still found it in the Related Topics section :wink::

Yes I’ve seen that page but I don’t see anything there that talks about how to enable the AI search results by default for everyone. Am I missing something here?

Perhaps I misunderstood you :slight_smile:. I thought you meant ‘enable the feature’ instead of ‘enable the toggle switch’. If you’re referring to the toggle, I don’t think there’s a way to do so.

We just made it toggle by default when the full page search has zero results, and will make it auto-append AI results on the quick header search has zero or few results next.

There is no setting to always toggle it automatically on the full page search, as that would case Frontend developers: stop moving things that I’m about to click on | by Stephen Jayakar | Medium

4 个赞

That’s a great start. It would be nice to have an option to prioritize which results we want to show as the first choice (extension of the logic that was just implemented). AI or native semantic search. In my case the AI produces far more relevant results when searching.

The thought here is that the token are already consumed to run the AI search so why not show the results if they are more appropriate. Many users are still wary of AI so they don’t toggle the switch but at the same time end up with misleading search results (semantic) and they don’t realize it. Let the admins decide what’s best for their community defaults.

3 个赞

As a temporary solution if someone needs to enable the toggle button by default, you can add this script to your theme (I’ve put it under <body>) which basically looks for a change in the AI search results and then toggles the AI results to enabled. This isn’t the cleanest code, maybe @awesomerobot has a more elegant way to do this.

<script type="text/javascript">
    // THIS SCRIPT IS TO ENABLE THE TOGGLE TO INCLUDE SEARCH RESULTS FROM AI AFTER THE SEARCH IS COMPLETE - DELETE ONCE THERE IS A NATIVE OPTION TO ENABLE THIS BY DEFAULT
    console.log('Script loaded. Continually looking for .semantic-search__searching and managing observer.');

    let searchObserver = null; // Variable to hold the observer instance

    function observeSearchContainer() {
      const searchStatusContainer = document.querySelector('.semantic-search__searching');

      if (searchStatusContainer) {
        // If the container is found
        if (!searchObserver) {
            // If an observer is not already running, start one
            console.log('.semantic-search__searching found. Starting observation.');

            searchObserver = new MutationObserver(function(mutations) {
              //console.log('Mutation detected in .semantic-search__searching:', mutations);
              mutations.forEach(function(mutation) {
                // Check for relevant mutations within the observed container
                if (mutation.type === 'characterData') {
                  //console.log('Relevant mutation type detected. Attempting to trigger toggle button functionality. ' + mutation.type);
                  const currentToggleButton = document.querySelector('button.d-toggle-switch__checkbox.semantic-search__results-toggle');
                  if (currentToggleButton) {
                      const isCurrentlyEnabled = currentToggleButton.getAttribute('aria-checked') === 'true';
                      if (!isCurrentlyEnabled) { // If the toggle is NOT currently enabled
                        // Trigger a click event to activate associated functionality
                        currentToggleButton.click();
                        console.log('Toggle button click event triggered.');
                      } else {
                        console.log('Toggle button already enabled.');
                      }
                  } else {
                    // This case might happen if the toggle button is removed while the container is still present
                    console.log('Toggle button not found when trying to trigger functionality.');
                  }
                }
              });
            });

            const config = { childList: true, subtree: true, characterData: true, attributes: true };
            searchObserver.observe(searchStatusContainer, config);
            console.log('MutationObserver started on .semantic-search__searching.');
        } else {
            // Container found, and observer is already running for it
            //console.log('.semantic-search__searching found, observer already active.');
        }
      } else {
        // If the container is NOT found
        if (searchObserver) {
            // If an observer was previously running, it means the container was removed
            console.log('.semantic-search__searching removed. Disconnecting observer.');
            searchObserver.disconnect(); // Stop observing
            searchObserver = null; // Reset the observer variable
        } else {
            // Container not found, and no observer is active (correct state)
            //console.log('.semantic-search__searching not found yet.');
        }
      }
    }

    // Use an interval to periodically check for the existence of the container
    const containerCheckInterval = setInterval(observeSearchContainer, 500); // Check every 500 milliseconds
</script>