I have a site that I have upgraded from v7.5 to v8.1. In addition I have changed from Solr 4.7 to Solr 4.10. In my general search routine I am trying to filter out content items based on Sitecore role membership and which roles have read access to an item and which roles are denied. To accomplish this we have two custom fields in the Solr index. One is called read_roles and one is called denied_roles. For the purposes of this question all that really matters is read_roles.
The read_roles field in the Solr index looks like this:
"read_roles_sm": [
"Emailcampaign\\Common Opt Out",
"Emailcampaign\\Two-Column Message Opted Out",
"extranet\\Anonymous Role",
"extranet\\Approved Role",
"extranet\\DistribA",
"extranet\\DistribB"
],
In my C# code that does the searching I have a method called ApplySecurityFilter that looks like this:
public static IQueryable<T> ApplySecurityFilter<T>(this IQueryable<T> query) where T : SearchResultItem {
var userRoles = Sitecore.Context.User.Roles.Select(r => r.Name);
var readPredicate = PredicateBuilder.False<T>();
readPredicate = userRoles.Aggregate(readPredicate, (current, role) => current.Or(i => i["read_roles"].Contains(role)));
var denyPredicate = PredicateBuilder.True<T>();
denyPredicate = userRoles.Aggregate(denyPredicate, (current, role) => current.And(i => !i["denied_roles"].Contains(role)));
if (readPredicate.Body.NodeType != System.Linq.Expressions.ExpressionType.Constant) {
query = query.Filter(readPredicate);
}
if (readPredicate.Body.NodeType != System.Linq.Expressions.ExpressionType.Constant) {
query = query.Filter(denyPredicate);
}
return query;
}
This all works fine in v7.5 with Solr 4.7. The code runs and translates my Linq style query in to a query that Solr can handle. In the end when I look in the log files this is part of the query that gets sent to Solr.
&fq=(((-denied_roles_sm:(*extranet\\Anonymous\ Role*) AND read_roles_sm:(*extranet\\Anonymous\ Role*)) AND _latestversion:(1))
And that works great. Now when I run the exact same code in v8.1 with Solr 4.10 for some reason the query that gets sent to Solr is slightly different. It looks like this:
&fq=(((-denied_roles_sm:("\*extranet\\Anonymous\\ Role\*") AND read_roles_sm:("\*extranet\\Anonymous\\ Role\*")) AND _latestversion:(1))
As you can see for some reason the Solr provider seems to have modified the text of the role name that gets sent to Solr. And there are no matches and therefore I get no results returned. I can't figure out why the upgraded version of my site is sending the query to Solr in a slightly different way. Any ideas?