protected internal virtual void AddClause(List<BooleanClause> clauses, int conj, int mods, Query q)
{
bool required, prohibited;
// If this term is introduced by AND, make the preceding term required,
// unless it's already prohibited
if (clauses.Count > 0 && conj == CONJ_AND)
{
BooleanClause c = clauses[clauses.Count - 1];
if (!c.IsProhibited)
c.Occur = Occur.MUST;
}
if (clauses.Count > 0 && operator_Renamed == AND_OPERATOR && conj == CONJ_OR)
{
// If this term is introduced by OR, make the preceding term optional,
// unless it's prohibited (that means we leave -a OR b but +a OR b-->a OR b)
// notice if the input is a OR b, first term is parsed as required; without
// this modification a OR b would parsed as +a OR b
BooleanClause c = clauses[clauses.Count - 1];
if (!c.IsProhibited)
c.Occur = Occur.SHOULD;
}
// We might have been passed a null query; the term might have been
// filtered away by the analyzer.
if (q == null)
return;
if (operator_Renamed == OR_OPERATOR)
{
// We set REQUIRED if we're introduced by AND or +; PROHIBITED if
// introduced by NOT or -; make sure not to set both.
prohibited = (mods == MOD_NOT);
required = (mods == MOD_REQ);
if (conj == CONJ_AND && !prohibited)
{
required = true;
}
}
else
{
// We set PROHIBITED if we're introduced by NOT or -; We set REQUIRED
// if not PROHIBITED and not introduced by OR
prohibited = (mods == MOD_NOT);
required = (!prohibited && conj != CONJ_OR);
}
if (required && !prohibited)
clauses.Add(NewBooleanClause(q, Occur.MUST));
else if (!required && !prohibited)
clauses.Add(NewBooleanClause(q, Occur.SHOULD));
else if (!required && prohibited)
clauses.Add(NewBooleanClause(q, Occur.MUST_NOT));
else
throw new SystemException("Clause cannot be both required and prohibited");
}