I have ContentSearch code that works and runs fine using Lucene. When I switch the configs over to Solr, the query fails, and the logs state that the field I'm using in the query doesn't exist.
[IndexField("tags")]
public IEnumerable<ID> Tags { get; set; }
16644 13:34:20 ERROR Solr Error : ["undefined field tags"] - Query attempted: [((_template:(2d7ad1cb107e44158690c03e0b65f90c) AND -_name:("__Standard Values")) AND tags:(fc8ac78af9aa495fb4ee08aca0444e1b))]
Note that the error says 'undefined field tags', but really, this should be tags_sm
when Sitecore adds the suffix to the query.
Changing [IndexField("tags")]
to [IndexField("tags_sm")]
gets it working....but now my code is Search Provider dependent.
Is there something I'm missing to make this work without the suffix? I thought Sitecore would automatically add it in there?
Here is how the query looks:-
var filterPredicate = PredicateBuilder.True<ArticleSearchResultItem>()
.And(x => x.TemplateId == IArticlePageItemConstants.TemplateId && x.Name != "__Standard Values");
if (parameters.TagId != (ID)null && parameters.TagId != ID.Null)
{
filterPredicate = filterPredicate.And(x => x.Tags.Contains(parameters.TagId));
}
var queryable = searchContext.GetQueryable<ArticleSearchResultItem>();
var searchResults = queryable
.Where(filterPredicate);
This is on Sitecore 8.1 Update-2, using Solr 6.1.0. Thanks.
public IEnumerable<ID>
topublic IEnumerable<string>
orpublic List<string>
IEnumerable<ID>
in the config, something like this? <typeMatch type="System.Collections.Generic.IEnumerable`1[Sitecore.Data.ID]" typeName="idCollection" fieldNameFormat="{0}_sm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />_sm
.[TypeConverter(typeof(IndexFieldEnumerableConverter))]