Space-separated values in Uni Selector

Tom Troughton asked on May 9, 2016 11:13

I'm using a Uni Selector to select multiple pages of a specific type. I need to save the value as a list of NodeIDs separated by spaces. This is essential due to how we're using this field within a custom Lucene search handler. However, when I put a space in the 'values separator' property of the Uni Selector it gets replaced with an empty string when saved. Presumably Kentico internally is doing a trim on this field.

Does anyone have a solution? I've even tried creating my own implementation of Uni Selector and added the following code, but values are still being saved separated by the default semi-colon.

public override char ValuesSeparator
{
    get { return ' '; }
    set { }
}

Your help would be very appreciated.

Recent Answers


Joshua Adams answered on May 9, 2016 15:27

What if you keep a character in the value separator, and then when using it or when retrieving the value, just do a replace for that character in the string? This way Kentico can handle it as it wants to, and you can just control it after kentico is finished. Just clone the control and put your code in the values separator, and replace the "/" or whatever value you use for the separator value with your space. Unless that is happening later on, I believe that should work.

0 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on May 9, 2016 16:28

Thanks for your answer. But this field is being indexed by Smart Search so it's important that it contains the spaces at the point it is indexed. So I don't have a replace option sadly.

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on May 9, 2016 17:10

What if you allow Kentico to save data as it wants to and modify it (replace separator) when indexing content? See how you can implement this here.

2 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on May 9, 2016 18:15

Thanks Roman. But this is a Searchable field so indexing its data as part of the indexed document's _content field is not an option. Ultimately I need to run Lucene queries such as myfield:5 or myfield:555. This is why I need the values to be space-spearated because Lucene treats space-separated integers as a special case. Unfortunately it appears Kentico's default treatment for multiple value fields isn't compatible with this Lucene feature.

I think my best option will be to handle the document save event an re-format this field into another hidden field then index that one. Shame, because if I could just use a space separator this would be much easier!

0 votesVote for this answer Mark as a Correct answer

Matthew Henninger answered on June 9, 2017 01:13 (last edited on June 9, 2017 01:16)

I know you can select to use a macro in value separator field the multi-selector web-part and use this macro {% return " " %} and Kentico will create a space separated value in the db. Not sure if this works in a uni-selector. Will test and reply Later.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.