0

I have the following information structure that the client wants to store in the xDb user custom profile facets, it concerns the "specialty" attribute i.e:

Person 1
Gardener: oranges, apples

Person 2:
Gardener: oranges, plums, grapes
Eater: oranges

Person 3:
Eater: apples, grapes

Person 4:
-

They expect to have another "professions" which deal with fruit i.e. cook etc to be added later on. They want to be able to segment these contact lists in the following way:

  • select all contacts who are gardeners/eaters
  • select all gardeners/eaters that grow/eat apples
  • select all ppl (both gardeners and eaters) that deal with apples in some way

That would seem easy if I could use "contains" within the condition class, but it is not supported. Would really appreciate an idea on which facet structure could I use for this to work. Thank you!

1 Answer 1

1

From what I remember, Any works fine.

So if you store your specialties in List<string> or List<Guid>, you should be able to use something like:

public class SpecialtyCondition : ICondition, IContactSearchQueryFactory
{
    public string Specialty { get; set; }

    public bool Evaluate(IRuleExecutionContext context)
    {
        Contact contact = context.Fact<Contact>();

        return contact.GetFacet<SpecialtyFacet>().Specialties.Any(s => s == Specialty);
    }

    public Expression<Func<Contact, bool>> CreateContactSearchQuery(IContactSearchQueryContext context)
    {
        return contact => contact.GetFacet<SpecialtyFacet>().Specialties.Any(s => s == Specialty);
    }
}

public class SpecialtyFacet : Facet
{
    public List<string> Specialties { get; set; }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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