5

This is related to Solr QueryElevationComponent component usage, but I'm looking for information on getting elevation setup.

I see some other questions involving Solr query elevation.

Is there documentation anywhere about getting elevation setup in the first place?

I imagine that I somehow need to get the enableElevation/forceElevation parameters into SolrNet.Commands.Parameters.CommonQueryOptions.ExtraParams, but I'm not sure how to get there.

I could get my own implementation of Sitecore.ContentSearch.SolrProvider.LinqToSolrIndex in there, but unfortunately there are no override points (the obvious method, BuildQueryOptions is private).

We're using Sitecore 8.2 Update-2 and Solr 5.4.1.

Thanks!

1 Answer 1

1

In my experience, trying to get ExtraParam to work with the Sitecore.ContentSearch especially in 8.* has been unfruitful (tried getting grouping to work on groupId with no luck) as the ExtraParams along with a lot of other SolrNet pieces are locked down an unexposed through the api. I used a different approach (in unrelated functionality to the grouping bit) to invoke the suggest handler in Solr (repurposed below):

var index = ContentSearchManager.GetIndex((SitecoreIndexableItem)contextDataItem);
var serviceUrl = SolrContentSearchManager.ServiceAddress.TrimEnd('/');
var handler = "/elevate";

IEnumerable<string> results = null;
var solrUrl = string.Format("{0}/{1}", serviceUrl, index.Name);
var solrConnection = new SolrConnection(solrUrl);

var parameters = new Dictionary<string, string>();
parameters.Add("q", searchTerm);
parameters.Add("enableElevation", "true");
parameters.Add("forceElevation", "true");
parameters.Add("df", "text");
parameters.Add("wt", "xml");

var xmlResponse = solrConnection.Get(handler, parameters);
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xmlResponse);
//parse the returned xml into proper results
results = _parseSuggestion(xmlDocument, suggestionType).ToList();

return results;

Which would invoke something like http://localhost:8983/solr/your_products_master/elevate?q=ipod&df=text&debugQuery=true&enableElevation=true&forceElevation=true

I realize that this approach pretty much circumvents using Predicate Builder or really any of the ContentSearch api already in place. In Sitecore 9 I believe they opened up a lot of the api to allow for passing QueryOptions and possibly ExtraParams as well (have not had a chance to confirm). Hopefully this helps even if only a little.

5
  • Thanks for this. I'd definitely like to avoid bypassing the ContentSearch/Linq APIs entirely, but it is a worthwhile thought. Commented Mar 12, 2018 at 17:36
  • Yep, totally understood. I know in my Suggest case I had a very finite list of results being returned. Ultimately what are you trying to do? Get a set of Items returned to the top as sponsored or weighted results? Just curious if there is a different solution to the feature ask in particular.
    – vandsh
    Commented Mar 12, 2018 at 17:48
  • The use case is that there are some conditions based on the text query that should cause certain results to appear at the top. For instance, if the query is the name of a brand, the brand landing page should appear first. This would be easy to do by reordering the result list after query time, but this isn't feasible when doing paginated results. For functionality purposes, I could construct a query to generate a stupidly high boost value for those, but that screws with the scoring in a way that I don't like. Commented Mar 12, 2018 at 17:54
  • Make sense, boost/scoring is what I was wondering. My other thought, since you likely know which items are a Brand Landing Page if ordering results by TemplateID/Name or using some computed bool field (ie: TopResults) to order by to get those Landing Pages to render higher?
    – vandsh
    Commented Mar 12, 2018 at 18:17
  • Changing the ordering at query time would prevent the default ordering by score, which is something I need. And doing a computed field wouldn't help, as whether the landing page should be at the top is dependent on the text query the user types in. Commented Mar 12, 2018 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.