Try our conversational search powered by Generative AI!




Class Product{
   string Type = "Hardback, Paperback, CD, Digital Download, Toys"

My data is indexing based on near about above type of object.

Indexed data is something like this $Type : "Hardback, Paperback, CD, Digital Download, Toys"

using TermsFacetForWordsIn in my query I get following results



returns me  whole string Hardback, Paperback, CD, Digital Download, Toys(1)

My desiresd resulset should be

Digital Download(1), 

How should i write the query?



Aug 20, 2014 10:30

Could you change the Type property to be of type List instead of a comma separated string? Optionally, you could do this:

            client.Conventions.ForInstancesOf().IncludeField(x => x.Type.Split(','));

            client.Search().TermsFacetFor(x => x.Type.Split(','));

Remember to put the first line of code in an initialization module or similar, and that you will need to reindex.

Aug 20, 2014 11:55

Is this line for intialization module?
client.Conventions.ForInstancesOf().IncludeField(x => x.Type.Split(','));

Aug 20, 2014 16:13

Yes, but I now realize that it may not be the case. It depends on how you are indexing your objects. Had this been standard PageData, the correct way would be to use an initializeable module and the SearchClient.Instance client object. However, since this is a custom object, I suppose you are indexing it on your own. All you need to do then is to make sure that you set up the conventions (the first line of code in my previous post) before you index your object, and also make sure that you set up the conventions for the same client object as you are doing the indexing with. I hope that makes sense! :-)

Edited, Aug 20, 2014 20:55

Thanks Per,

Its an Episerver Commerce Project with EpiServer Find.  and is based on ProductContent, I will be thankful if you can do any further help.

public class BookProduct : EPiServer.Commerce.Catalog.ContentTypes.ProductContent
public virtual string Formats //data will be Hardback,  Digital Download

I am using Jonas Solution for Indexing data Indexing Catalog Contents

I have already got understanding of your opinion and tried that but It was giving me this error on Indexing. I know it is due to data issue but I dont know what to do with this.

public void Initialize(InitializationEngine context)
SearchClient.Instance.Conventions.ForInstancesOf().ExcludeField(x => x.PermanentLinkMapper);
SearchClient.Instance.Conventions.ForInstancesOf().IncludeField(x => x.Series.Split(','));
SearchClient.Instance.Conventions.ForInstancesOf().IncludeField(x => x.Formats.Split(','));
CatalogRouteHelper.MapDefaultHierarchialRouter(RouteTable.Routes, false);

On Indexing job I got below error
ERROR EPiServer.Find.Cms.ContentIndexer - An exception occured while indexing (Batch): Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , ProductContent )
at EPiServer.Find.DelegateValueProvider`2.GetValue(Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at EPiServer.Find.Api.BulkActionConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
at EPiServer.Find.Json.Serializer.SerializeToStringBuilder(JsonSerializer serializer, Object value, StringBuilder buffer)
at EPiServer.Find.Api.BulkCommand.Execute()
at EPiServer.Find.Client.Index(IEnumerable objectsToIndex)
at EPiServer.Find.Cms.ContentIndexer.IndexWithRetry(IContent[] contents, Int32 maxRetries)
at EPiServer.Find.Cms.ContentIndexer.Index(IEnumerable`1 content, IndexOptions options)
at EPiServer.Find.Cms.ContentIndexer.<>c__DisplayClass16.b__e(Object x)


Aug 21, 2014 10:15


I'm guessing you may have some null values. To get around that, you could do this instead:

SearchClient.Instance.Conventions.ForInstancesOf().IncludeField(x => x.TypeAsList());

and then create a corresponding extension method

       public static string[] TypeAsList(this Product product)
                return product.Type.Split(',');
            return null;

After running the indexing, you index should be populated with the correct values. Something like this:

    "TypeAsList": [
        "something else"

You could then do 

.TermsFacetFor(x => x.TypeAsList())
Aug 21, 2014 10:35

Bundle of Thanks - Sorted.

Aug 21, 2014 12:32

Great :-)

Aug 21, 2014 12:36
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.