0

I'm using several multi-list fields in my searches, and they work great to say "field = value" and it finds a matching value in the list. What I need now, though, is to check if the value I'm looking for is the only one in the list.

Example: a multi-list of states. In the usual scenario, I want to check if Virginia has been selected. In this new scenario, I want to check if the list contains Virginia ONLY...if Maryland is also selected, for example, then the result would not be returned.

Is there a length value that could be checked to find out how many selections are in the field? Then it'd be easy to say "AND length = 1" in addition to my standard query.

1

There is no search operator to query the number of values in a multi value field in a Coveo index.

If your query only contains one value for a given multi value field, it would be possible to achieve your goal with another field containing the same values but not configured as a multi value field.

Exemple for a query @multivaluefield=="virginia" AND @normalfield=="virginia". If @multivaluefield and @normalfield values are "virginia", the document will be returned. However, if their values are "virginia;maryland", the query on @multivaluefield will return the document but the query on @normalfield will filter it out as the field doesn't contain only "virginia".

| improve this answer | |
  • Since I've already designated my actual multi-value field as such in Coveo, I assume I'd need to create a new computed field to bring in the same field result, mark it as not multi-value, and then I can do the comparison you're talking about? (This would make a good feature request potentially too... :) ) – Ken McAndrew Jan 12 '17 at 2:44
  • 1
    Exactly. Use the same computed field class with a different field name and configuration for the @normalfield of my example. – Jean-François L'Heureux Jan 12 '17 at 2:57
  • Checking the SearchProvider.Custom.config, I see an example of how this could work built in...would this do it? <field fieldName="normalFieldName" sourceField="multivalueFieldName" referencedFieldName="ID">Coveo.SearchProvider.ComputedFields.ReferencedFieldComputedField, Coveo.SearchProviderBase</field> --- then I don't need to program anything, this would just read it in? Or is it better to just build a computed field in code? – Ken McAndrew Jan 12 '17 at 3:32
  • The referencefielscomputedfield is only used when the original itel field contains IDs linking to other items in the content tree. How do you index the multivaluefield originally? – Jean-François L'Heureux Jan 12 '17 at 11:11
  • It's a multi-list, so it's just storing IDs. Originally it was just doing it as text, until you reminded me I had to declare the fields as multiValue=true. So if I got back to the original version of the field handling, I'd have a list of IDs as a string and could do the comparison that you suggest. I'll play around with it but I think I've got a path forward. – Ken McAndrew Jan 13 '17 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.