Reading it back over, I can simplify this a bit if we're solely dealing with strings...

...

public class Transaction {

        private String field;

        // ... getter and setter for field, as well as all your other methods in transaction, just showing this to say I'm assuming 'field' to be of type String
}

rule "find value substring match"
when
    $s : String ( )
    $t : Transaction( field.contains($s) )
then
    sendAlert("Transaction " + $t.getName() + "matches criteria: " + $s);
end

...

session.insert(transaction);
for (int i = 0; i < listOfUserValueStrings.length; i++) {
     session.insert(listOfUserValueStrings[i];
}



On Sat, Jan 5, 2013 at 1:29 PM, Jeremy Ary <jeremy.ary@gmail.com> wrote:
If your matcher doesn't equate to a boolean value, I don't think that condition will evaluate as you suspect it will. Functions in your conditions isn't going to be as clean or easy as you suspect. Consider inserting the user-supplied values into your session and matching with a rule:

...
public class Transaction {

        private String field;

        // ... getter and setter for field, as well as all your other methods in transaction, just showing this to say I'm assuming 'field' to be of type String
}

...

public class Value {

private String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}

...

rule "find value substring match"
when
    Value ( $v : value )
    $t : Transaction( field.contains($v) )
then
    sendAlert("Transaction " + $t.getName() + "matches criteria: " + $v);
end

...

session.insert(transaction);
for (int i = 0; i < listOfUserValues.length; i++) {
     session.insert(listOfUserValues[i];
}


On Sat, Jan 5, 2013 at 12:29 PM, bdolbeare <bdolbeare@yahoo.com> wrote:
Suppose we have a Transaction object with a String field.  Users want to
create a rule through our application that says alert me whenever the value
of that field contains a value in a list of values provided in the rule.
It's easy enough to write this type of rule and send an alert; however, it
would be helpful to include the value from the list that matched.

The only way I can think to do this type of thing is to create a function
somewhere that checks if the field contains any of the values in the user
list and if so return that value.  Then call that function in the rule
condition and bind the result.  Something like what follows:


public class ExternalMatcher
{
  public static String contains(String field, String...list)
  {
  // return the first string that satisfies the contains logic or null if no
strings succeed
  }
}

rule "test"
when
Transaction( $matchedValue : ExternalMatcher.contains(field, "value1",
"value2", "value3") != null)
then
sendAlert("I found a transaction that matched your criteria because field
foo equals: " + $matchedValue);
end





--
View this message in context: http://drools.46999.n3.nabble.com/Finding-matching-values-in-composite-constraint-tp4021343p4021346.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users