November Happy Hour will be moved to Thursday December 5th.

TermsFacetForWordsIn

Vote:
 

Hi,

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

Hardback(1),
Paperback(1),
CD(1),
Digital(1)
Download(1),
Toys(1)

using

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

My desiresd resulset should be

Hardback(1), 
Paperback(1),
CD(1), 
Digital Download(1), 
Toys(1)

How should i write the query?

Regards

Khurram

#89570
Aug 20, 2014 10:30
Vote:
 

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.

#89577
Aug 20, 2014 11:55
Vote:
 

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

#89602
Aug 20, 2014 16:13
Vote:
 

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! :-)

#89609
Edited, Aug 20, 2014 20:55
Vote:
 

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)

Regards
Khurram

#89629
Aug 21, 2014 10:15
Vote:
 

Hi,

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)
        {
            if(!string.IsNullOrEmpty(product.Type))
            {
                return product.Type.Split(',');
            }
            return null;
        }

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

    "TypeAsList": [
        "something",
        "blabla",
        "something else"
    ],

You could then do 

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

Bundle of Thanks - Sorted.
/K

#89643
Aug 21, 2014 12:32
Vote:
 

Great :-)

#89644
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.