Recent searches


No recent searches

Excluding text from search, is it possible?



Posted Mar 14, 2024

At the bottom/end of each article I have a document versioning table where writers can add notes for what changed over time. My style sheet hides the table (display:none), but the text is included in search. I am looking for a way to exclude hidden text from search.

My style sheet:

/* Document Versions Table allows writers to document article changes that are not visible in published articles*/

div.DocumentVersion {
width: 100%;
text-align: left;
display: none; }
/* END Document Versions Table */

Table in articles:

<div class="DocumentVersion">
<table style="border-collapse: collapse; width: 100%;" border="1">
<tbody>
<tr>
<td style="width: 22.6191%;">
<strong>Document Version</strong>
</td>
<td style="width: 15.7618%;">
<strong>Date</strong>
</td>
<td style="width: 61.619%;">
<strong>Description of Change</strong>
</td>
</tr>
<tr>
<td style="width: 22.6191%;"></td>
<td style="width: 15.7618%;"></td>
<td style="width: 61.619%;"></td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>

 

 


0

1

1 comment

image avatar

Jakub

Zendesk Customer Care

Hello Lorrie McConnell

You can manipulate the search results on the client side using JavaScript to remove the unwanted text programmatically after the search results are displayed. This approach involves writing a script that runs after the search results are loaded and then searches for and removes the text related to the document versioning table.

Here's a conceptual example of how you might do this with JavaScript:

document.addEventListener('DOMContentLoaded', function() {
  // Function to remove version text from search results
  function removeVersionTextFromSearchResults() {
    // Select all search result description elements
    var searchResults = document.querySelectorAll('.search-result-description');

    // Loop through all search result descriptions
    searchResults.forEach(function(result) {
      // Check if the result contains the text 'Document Version'
      if (result.innerHTML.includes('Document Version')) {
        // Remove the unwanted text or manipulate the result as needed
        // This example assumes that the 'Document Version' text is at the end of the result
        result.innerHTML = result.innerHTML.split('<em>Document Version</em>')[0];
      }
    });
  }

  // Call the function to clean up search results
  removeVersionTextFromSearchResults();

  // If your search results are loaded asynchronously or there's pagination,
  // you may need to observe changes to the search results container and call the function again.
  // For example, using a MutationObserver to detect changes and reapply the function.
});


As you can see on this screenshot, even though I search for Document version this string is not visible in the search results. This is only "visual" removal of that element, but still the results including this text will be returned:

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post