Developer forum

Forum » Development » Combined AND and OR RuleGroupCombineMethod

Combined AND and OR RuleGroupCombineMethod

Peter Terkildsen
Reply

I have the following code:

            var rules = new RulesGroup()
            {
                CombineMethod = RuleGroupCombineMethod.And
            };

            if (createdByAccessUserId != null && createdByAccessUserId != "-1")
            {
                rules.Add(new Rule(new RuleField()
                {
                    ID = "CreatedByAccessUserId",
                    Name = "CreatedByAccessUserId",
                    TypeName = typeof(String).FullName
                }, RuleOperator.Equals, createdByAccessUserId));   
            }

            if (category != null && category != "-1")
            {
                rules.Add(new Rule(new RuleField()
                {
                    ID = "Category",
                    Name = "Category",
                    TypeName = typeof(String).FullName
                }, RuleOperator.Equals, category));
            }

Now I would like to add an OR RuleGroupCombineMethod in order to add a free-text query that will search in multiple fields. Is this possible?

Regards,

Peter


Replies

 
Vladimir
Reply
This post has been marked as an answer

Hi Peter,

it is not clearly for me what you do -  do you override  ItemPublisher.Frontend.GetQuery()  function?

if I'm right you will create a query object to use it in  repository.SelectBy....(..Query..) functions

Query object has a Where property with is a collection of RulesGroup.

So your code should be:

            query.add(rules);

            var freeSearchRules = new RulesGroup() { CombineMethod = RuleGroupCombineMethod.Or };
            freeSearchRules.Add(new Rule(new RuleField()
                {
                    ID = "field1",
                    Name = "field1",
                    TypeName = typeof(string).FullName
                }, RuleOperator.Contains, "searchedvalue"));
            freeSearchRules.Add(new Rule(new RuleField()
            {
                ID = "field2",
                Name = "field2",
                TypeName = typeof(string).FullName
            }, RuleOperator.Contains, "searchedvalue"));
            freeSearchRules.Add(new Rule(new RuleField()
            {
                ID = "fieldN",
                Name = "fieldN",
                TypeName = typeof(string).FullName
            }, RuleOperator.Contains, "searchedvalue"));

            query.Add(freeSearchRules);


Best regards,

Vladimir

 

 

 

 

 

 

 

 

 

 

 

 

 

Votes for this answer: 1
 
Peter Terkildsen
Reply

Hi Vladimir,

This works perfectly! Thanks :-)

Peter

 

You must be logged in to post in the forum