private static LuceneQuery GetLuceneBoostQuery(this CommutativeExpression expression, string fieldName, Analyzer analyzer) { var query = new BooleanQuery(); foreach (var innerQuery in expression.Terms.Select(t => t.GetLuceneBoostQuery(fieldName, analyzer))) { if (innerQuery != null) { query.add(innerQuery, BooleanClause.Occur.SHOULD); } } return(query); }
private static LuceneQuery GetLuceneQuery(this CommutativeExpression expression, string fieldName, Analyzer analyzer) { BooleanClause.Occur defaultOp; switch (expression.Operator) { case BinaryOperator.And: defaultOp = BooleanClause.Occur.MUST; break; case BinaryOperator.Or: defaultOp = BooleanClause.Occur.SHOULD; break; default: throw new InvalidOperationException(); } var query = new BooleanQuery(); foreach (var term in expression.Terms) { var op = defaultOp; var innerExpr = term; var unaryTerm = term as UnaryExpression; if (unaryTerm != null) { if (expression.Operator != BinaryOperator.And) { continue; } op = BooleanClause.Occur.MUST_NOT; innerExpr = unaryTerm.Term; } var innerQuery = innerExpr.GetLuceneQuery(fieldName, analyzer); if (innerQuery != null) { query.add(innerQuery, op); } } return(query); }