Developer forum

Forum » Dynamicweb 10 » Facet list from db-column

Facet list from db-column

Jens Peter Olsson
Reply

I have values like "A, B, C" in column FieldValueValue in table EcomProductCategoryFieldValue for a specific FieldValueFieldId that I use to populate a facet for filtering in UI. I can control the formatting of how the values are stored, but I can't split them to different id:s. I saw somewhere that if the type for the facet field is array - e.g. string[] - it should be possible to populate it with multiple values. From what I understood format "[A][B][C]" should work, but I've tried it and it didn't. Have also tried "[A,B,C]" and just "A,B,C".

Does anyone know if this is possible or other ideas on how to solve it?

What I want to achieve is that if a product has value "A, B, C" there should be separate filter values for A and B and C, and this product should be matched by all.


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Jens,

I believe the issue is related to "Analyzed" option on the field.

Suppose you have the setting "DoNotAnalyzeDefaultFields" set to False in the index settings. In that case, you should create a new field for this Facet, based on your ProductCategoryField and don't check the "Analyzed" option.

The field should be defined as String array.

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

Analyzed will do similar thnigs as indexing a string value as a string array.

I think what Jens Peter is looking for is to take the value of the string field in PIM and index it as a String array in the lucene index. The result would be almost similar.

But consider these values instead: 'Value 1', 'Other 2', 'third 3' - indexing that string as a string array, woulfd give 3 terms in facets - one for each value. Using the analyzer would give 6 values as it would be analyzed into the 6 different terms in the entire string.

But if the values are just single words in PIM, analyzed can be used.

So if the source field in PIM is string and you create the field in the index as String[], this is the code that should parse your original string into an array of values. But be sure to NOT analyze the index field:

 private static string[] GetArray(string value)
 {
     if (value.Contains("]["))
     {
         return value.Split(new string[] { "][" }, StringSplitOptions.RemoveEmptyEntries).Select(v => v.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' })).ToArray();
     }
     else if (value.Contains("],["))
     {
         return value.Split(new string[] { "],[" }, StringSplitOptions.RemoveEmptyEntries).Select(v => v.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' })).ToArray();
     }
     else if (value.StartsWith("[") || value.EndsWith("]"))
     {
         return new string[] { value.TrimStart(new char[] { '[' }).TrimEnd(new char[] { ']' }) };
     }
     else
     {
         return value.Split(new char[] { ',' });
     }
 }
 
Jens Peter Olsson
Reply

Thanks for the responses!

So I have to implement that code myself, there is no standard implementation for this?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Jens Peter

What exact data do you have in the database? Not just conceptually - but do you have multiple words in each string of your array or how does it look?

And exactly how did you setup the field in indexing? If you can show us your mapping of the field in the index that would be great.

Thanks

 

You must be logged in to post in the forum