If your rules have (almost) identical LHSs, node sharing should help reduce the impact on performance.
So, this indeed becomes a conflict resolution problem in presence of multiple versions of the "same" rule.
This is a very common problem with rules derived from norms/laws.
Unfortunately there is no way to filter rules before matching (there are many ways to filter rules before FIRING, though), especially
if your filter criteria depend on a flag/field that is part of your fact. The simplest solution I can think of is to use meta-rules, as
previously suggested. Have your temporally constrained facts implement some interface that exposes the temporal flag and
annotate your rules, something along these lines:
rule "Calculate some stuff"
@Temporal( from="2015-05-01", until="2015-08-01" )
when
$d : Document()
...
then .... end
rule "Check"
@Direct
when
$m : Match( $f : from, $u : until, $facts : objects )
Timed( flag < $f || > $u ) from $objects
// assuming Document implements this interface. Also use date, timestamp or temporal operators as needed
// also having the Timed fact always in the same position, e.g. as the first fact, allows to replace "from" with an array index
then
$m.cancel();
end
Assume a given document matches N temporal rules, and only one needs to ultimately fire.
You get 2*N - 1 matches - the N rules and N - 1 matches of the meta-rule.
You also get N firings : N-1 firings of the meta-rule will cancel the undesired activations, letting
the only one that is appropriate fire and generate the results.
You pay a price in term of matches, but you won't need to process the conflicting calculations.
The alternative is to embed the temporal constraints directly to the rules
rule "Calculate some stuff"
when
$d : Document( flag > "2015-05-01" && < "2015-08-01" )
...
then .... end
This is more efficient: eventually you will get only 1 match and 1 firing, but requires to mix the business
logic with the control logic, which in some cases is unacceptable.
Based on your use case, let me know if you need a more detailed discussion on either solution
Best
Davide