Content Editor Search Bar Not Working

> Sometimes it works, sometimes not
Cover Image for Content Editor Search Bar Not Working

As Sitecore developers, I suspect that all of us use the search bar in Content Editor quite frequently. Have you noticed that sometimes when you use that search bar, no results are returned, or the results are not what you expect? Whenever this happened to me, I always found that refreshing the page "fixed" the issue. If you have the habit of always clicking the top sitecore item before searching, then it's likely you've never noticed this issue.

This has been a problem for as long as I can remember, and I finally figured it out. Turns out that other devs that I know have also seen this for years but have never been able to put their finger on it.

The Problem & Reproduction Steps

Defining custom master and web indexes will cause the Content Editor search bar to change index context depending on which item you have selected in the tree.

To replicate the issue:

  1. Define a custom master index
  2. Click one of the items in the tree that is indexed by the custom index
  3. Search for an item that is not indexed by the custom index
  4. Notice that the item is not found

Once I figured out how to reliably replicate the issue, I looked at the Crawling log, and noticed that while the query was identical, the _indexname fq parameter was different:

&fq=_indexname:(sitecore_master_index)

While the other had:

&fq=_indexname:(sitecore_custom_master_index)

Let's go over some real examples.

Content Search From Root Node

Starting with an example that returns the results I am expecting:

Content Search from root node

Where it says Search Results(sitecore), it is indicating that the search context is derived from the sitecore item at the top of the tree. This is guaranteed to use the sitecore_master_index. Since we're searching for {11111111-1111-1111-1111-111111111111}, it will show up in the results. The second result item is a custom item that I created which has a field with a value of 11111111, so it also appears in the search. Perfect.

Content Search From Nested Node

Here's an example where the search context is derived from a nested item that does not return the results I'm expecting:

Content Search from nested node

Where it says Search Results(mg2), the search context is derived from the mg2 item, which is located at the path /sitecore/content/home/locations/mg office. This item is included in my custom master index. The Sitecore root item does not appear in the results.

Why This Can Be a Problem

Developers and content authors need truth; especially newer users who are not familiar with the intricacies of Sitecore. If they search for an item and it doesn't show up, they will think it doesn't exist. If the search results are not what they expect, they will think that the search is broken, or they may select the wrong item.

Solution: Remove Custom Indexes From Content Editor Search via Config

Below is a simple fix for the issue.


_15
<sitecore>
_15
<configuration>
_15
<pipelines>
_15
<!-- Disable custom indexes in Content Editor search bar -->
_15
<contentSearch.getContextIndex>
_15
<processor type="Sitecore.ContentSearch.Pipelines.GetContextIndex.FetchIndex, Sitecore.ContentSearch">
_15
<excludedIndexes hint="list">
_15
<mainMaster>custom_master_index</mainMaster>
_15
<mainWeb>custom_web_index</mainWeb>
_15
</excludedIndexes>
_15
</processor>
_15
</contentSearch.getContextIndex>
_15
</pipelines>
_15
</sitecore>
_15
</configuration>

You may need to do the above in multiple configs if your instance supports multisite.

While we're in the code, I also recommend reviewing any instances of ContentSearchManager.GetIndex().CreateSearchContext() in your code, in case you have any pre-existing customizations regarding creating search contexts.

Two final notes on this approach:

  1. This is a customization (which introduces more complexity)
  2. Master indexes can take a long time to rebuild, so you should consider performance implications

Conclusion

I was not aware that custom indexes were a factor when using Content Editor.

Ultimately, the impact of searching is based on where you are in the content tree when you do the search. If you use custom indexes that are quite selective in terms of what items or fields to index, always click the top Sitecore node before searching, or apply the config patch as a second option.

I'll leave you with a mystery. The Sitecore Author Toolbox browser extension has a giant search bar at the top which works beautifully, no matter where you are in the content tree. It makes a GET request to to this endpoint when performing the search: /sitecore/shell/applications/search/instant/instantsearch.aspx?q=&v=1. What is this, and why is there no mention of it online?

References

  • https://sitecore.stackexchange.com/questions/9796/how-does-sitecore-decide-the-index-to-use-with-getindex
  • https://sitecoreblog.marklowe.ch/2014/05/determining-the-context-index-when-performing-bucket-queries/
  • https://thesitecorezone.wordpress.com/2015/06/28/optimizing-sitecore-indexing-performance-part-2/

More Stories

Cover Image for Hello World

Hello World

> Welcome to the show

Cover Image for Add TypeScript Type Checks to RouteData fields

Add TypeScript Type Checks to RouteData fields

> Inspired by error: Conversion of type may be a mistake because neither type sufficiently overlaps with the other.

Cover Image for Super Fast Project Builds with Visual Studio Publish

Super Fast Project Builds with Visual Studio Publish

> For when solution builds take too long

Cover Image for SPE Script Performance & Troubleshooting

SPE Script Performance & Troubleshooting

> Script never ends or runs too slow? Get in here.

Cover Image for Tips for Applying Cumulative Sitecore XM/XP Patches and Hotfixes

Tips for Applying Cumulative Sitecore XM/XP Patches and Hotfixes

> It's probably time to overhaul your processes

Cover Image for JSS + TypeScript Sitecore Project Tips

JSS + TypeScript Sitecore Project Tips

> New tech, new challenges

Cover Image for On Mentorship and Community Contributions

On Mentorship and Community Contributions

> Reflections and what I learned as an MVP mentor

Cover Image for NextJS: Access has been blocked by CORS policy

NextJS: Access has been blocked by CORS policy

> CORS is almost as much of a nuisance as GDPR popups

Cover Image for Azure PaaS Cache Optimization

Azure PaaS Cache Optimization

> App Services benefit greatly from proper configuration

Cover Image for Don't Ignore the HttpRequestValidationException

Don't Ignore the HttpRequestValidationException

> Doing so could be... potentially dangerous

Cover Image for NextJS: Short URL for Viewing Layout Service Response

NextJS: Short URL for Viewing Layout Service Response

> Because the default URL is 2long4me

Cover Image for JSS: Reducing Bloat in Multilist Field Serialization

JSS: Reducing Bloat in Multilist Field Serialization

> Because: performance, security, and error-avoidance

Cover Image for Script: Boost SIF Certificate Expiry Days

Script: Boost SIF Certificate Expiry Days

> One simple script that definitely won't delete your system32 folder

Cover Image for How to Run Old Versions of Solr in a Docker Container

How to Run Old Versions of Solr in a Docker Container

> Please don't make me install another version of Solr on my local...

Cover Image for Symposium 2022 Reflections

Symposium 2022 Reflections

> Sitecore is making big changes

Cover Image for Troubleshooting 502 Responses in Azure App Services

Troubleshooting 502 Responses in Azure App Services

> App Services don't support all libraries

Cover Image for Tips for Forms Implementations

Tips for Forms Implementations

> And other pro tips

Cover Image for NextJS/JSS Edit Frames Before JSS v21.1.0

NextJS/JSS Edit Frames Before JSS v21.1.0

> It is possible. We have the technology.

Cover Image for NextJS: Unable to Verify the First Certificate

NextJS: Unable to Verify the First Certificate

> UNABLE_TO_VERIFY_LEAF_SIGNATURE

Cover Image for Year in Review: 2022

Year in Review: 2022

> Full steam ahead

Cover Image for On Sitecore Stack Exchange (SSE)

On Sitecore Stack Exchange (SSE)

> What I've learned, what I see, what I want to see

Cover Image for Sitecore Symposium 2022

Sitecore Symposium 2022

> What I'm Watching 👀

Cover Image for Early Returns in React Components

Early Returns in React Components

> When and how should you return early in a React component?

Cover Image for Ideas For Docker up.ps1 Scripts

Ideas For Docker up.ps1 Scripts

> Because Docker can be brittle

Cover Image for Tips for New Sitecore Developers

Tips for New Sitecore Developers

> Because learning Sitecore can be hard