One of the results you will find if you search your sitecore solution for one of the params (i.e. facetsRootItemId) is App_Config\Sitecore\SPEAK\Sitecore.Speak.ItemWebApi.config
You can use this file to find which processor deals with the search request, which is Sitecore.ItemWebApi.Pipelines.Request.Search, Sitecore.Speak.ItemWebApi
.
What I suggest is overriding that processor, using the code from the decompiled DLL. Then stick a break point in the code and see if and where any of the OTB code is failing, this should help you diagnose further the issue.
Example code below:
using Sitecore.ContentSearch;
using Sitecore.ContentSearch.Linq;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Globalization;
using Sitecore.ItemWebApi.Facets;
using Sitecore.ItemWebApi.Pipelines.Request;
using Sitecore.ItemWebApi.Pipelines.Search;
using Sitecore.Pipelines;
using Sitecore.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace YourNameSpace.Pipeline
{
public class SearchRequestProcessor : RequestProcessor
{
private const string SearchParameterName = "search";
private const string LanguageParameterName = "language";
private const string ShowHiddenItemsParameterName = "showHiddenItems";
public override void Process(RequestArgs args)
{
Assert.ArgumentNotNull((object)args, nameof(args));
string searchText = WebUtil.GetQueryString("search", (string)null);
if (searchText == null)
{
if (!args.Context.HttpContext.Request.HasQueryStringFlag("search"))
return;
searchText = string.Empty;
}
string str = WebUtil.GetQueryString("showHiddenItems", (string)null);
if (str == null)
str = string.Empty;
bool showHiddenItems = str == "true";
string queryString = WebUtil.GetQueryString("language", string.Empty);
if (!string.IsNullOrEmpty(queryString))
{
using (new LanguageSwitcher(queryString))
this.RunSearchPipeline(args, searchText, queryString, showHiddenItems);
}
else
this.RunSearchPipeline(args, searchText, queryString, showHiddenItems);
}
private void RunSearchPipeline(
RequestArgs args,
string searchText,
string languageName,
bool showHiddenItems)
{
Item searchDefinition = this.GetSearchDefinition(Sitecore.Context.Database);
Item rootItem = this.GetRootItem(args, searchDefinition);
string searchText1 = this.GetSearchText(searchDefinition, searchText);
using (IProviderSearchContext searchContext = ContentSearchManager.GetIndex((IIndexable)new SitecoreIndexableItem(rootItem)).CreateSearchContext())
{
SearchArgs args1 = new SearchArgs(searchContext, searchDefinition, rootItem, searchText1, languageName, showHiddenItems);
CorePipeline.Run("itemWebApiSearch", (Sitecore.Pipelines.PipelineArgs)args1);
SearchResults<ConvertedSearchResultItem> results = args1.Queryable.GetResults<ConvertedSearchResultItem>();
args.Items = results.Hits.Select<SearchHit<ConvertedSearchResultItem>, Item>((Func<SearchHit<ConvertedSearchResultItem>, Item>)(s => s.Document.GetItem())).Where<Item>((Func<Item, bool>)(x => x != null)).ToArray<Item>();
args.CustomData["totalCount"] = (object)results.TotalSearchResults;
if (results.Facets == null)
return;
args.CustomData["facets"] = (object)this.GetFacets(args1.FacetProviders, results.Facets);
}
}
private IEnumerable<Facet> GetFacets(
IList<IFacetProvider> facetProviders,
FacetResults facets)
{
List<Facet> facets1 = new List<Facet>();
foreach (FacetCategory category in facets.Categories)
{
FacetCategory facetCategory = category;
IFacetProvider facetProvider = facetProviders.FirstOrDefault<IFacetProvider>((Func<IFacetProvider, bool>)(provider => provider.CanHandle(facetCategory.Name)));
Facet facet = facetProvider == null ? new Facet(facetCategory.Name) : facetProvider.GetFacet(facetCategory.Name);
foreach (Sitecore.ContentSearch.Linq.FacetValue facetValue in (IEnumerable<Sitecore.ContentSearch.Linq.FacetValue>)facetCategory.Values.Where<Sitecore.ContentSearch.Linq.FacetValue>((Func<Sitecore.ContentSearch.Linq.FacetValue, bool>)(v => v.AggregateCount != 0)).OrderBy<Sitecore.ContentSearch.Linq.FacetValue, string>((Func<Sitecore.ContentSearch.Linq.FacetValue, string>)(v => v.Name)).ThenByDescending<Sitecore.ContentSearch.Linq.FacetValue, int>((Func<Sitecore.ContentSearch.Linq.FacetValue, int>)(value => value.AggregateCount)))
{
Sitecore.ItemWebApi.Facets.FacetValue value;
if (facetProvider != null)
{
string name = facetValue.Name;
value = facetProvider.GetValue(facet, name);
}
else
value = new Sitecore.ItemWebApi.Facets.FacetValue(facet.Name + ":" + facetValue.Name, facetValue.Name)
{
DisplayText = Capitalize(facetValue.Name)
};
value.Count = facetValue.AggregateCount;
if (facet.Values.Exists((Predicate<Sitecore.ItemWebApi.Facets.FacetValue>)(v => v.Text == value.Text)))
facet.Values.Find((Predicate<Sitecore.ItemWebApi.Facets.FacetValue>)(v => v.Text == value.Text)).Count += value.Count;
else
facet.Values.Add(value);
}
facets1.Add(facet);
}
return (IEnumerable<Facet>)facets1;
}
private Item GetRootItem(RequestArgs args, Item searchDescriptor)
{
string queryString = WebUtil.GetQueryString("root", searchDescriptor != null ? searchDescriptor["root"] : string.Empty);
return string.IsNullOrEmpty(queryString) ? Sitecore.Context.ContentDatabase.GetRootItem() : Sitecore.Context.ContentDatabase.GetItem(queryString);
}
private Item GetSearchDefinition(Database database)
{
string str = WebUtil.GetQueryString("searchConfig", (string)null) ?? ParseSearchText.AllItemId.ToString();
if (ID.IsID(str))
{
Item searchDefinition = database.GetItem(str);
if (searchDefinition != null)
return searchDefinition;
}
return database.GetItem(ParseSearchText.SearchId)?.Children[str];
}
private string GetSearchText(Item searchDescriptor, string searchText)
{
if (searchDescriptor == null)
return searchText;
string empty = string.Empty;
if (!string.IsNullOrEmpty(searchDescriptor[nameof(Search)]))
empty = searchDescriptor[nameof(Search)];
if (GetBool(searchDescriptor["AppendSearchText"], true) && !string.IsNullOrEmpty(searchText))
empty += searchText;
return empty;
}
public static bool GetBool(string value, bool defaultValue)
{
if (string.IsNullOrEmpty(value))
return defaultValue;
return value.Equals("true", StringComparison.OrdinalIgnoreCase) || value.Equals("yes", StringComparison.OrdinalIgnoreCase) || value.Equals("1", StringComparison.OrdinalIgnoreCase);
}
public static string Capitalize(string text)
{
string str = text.Trim();
return str.Length == 0 ? string.Empty : str.Substring(0, 1).ToUpperInvariant() + str.Substring(1).ToLowerInvariant();
}
}
internal static class RequestExtensions
{
private static readonly string[] Separator = new string[1]
{
","
};
internal static bool HasQueryStringFlag(this HttpRequest request, string parameterName)
{
if (WebUtil.GetQueryString(parameterName, (string)null) != null)
return true;
string str = request.QueryString[(string)null];
return !string.IsNullOrEmpty(str) && ((IEnumerable<string>)str.Split(RequestExtensions.Separator, StringSplitOptions.RemoveEmptyEntries)).Contains<string>(parameterName);
}
}
}
Sitecore patch:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<processor type="YourNameSpace.Pipeline.SearchRequestProcessor, YourNameSpace" patch:instead="processor[@type='Sitecore.ItemWebApi.Pipelines.Request.Search, Sitecore.Speak.ItemWebApi']" />
</itemWebApiRequest>
</pipelines>
</sitecore>
</configuration>