private static void addToBooleanWithOccur( final QueryFactoryResult result, final BooleanQuery booleanQuery, final BooleanClause.Occur occur) { if (result.mustNotOccur()) { booleanQuery.add(result.getLuceneQuery(), BooleanClause.Occur.MUST_NOT); } else { booleanQuery.add(result.getLuceneQuery(), occur); } }
/** * @param results a list of results you want to merge; must not be null or contain nulls * @return non-false results merged in a new boolean query with SHOULD. The result should never * need negation, i.e. {@link #mustNotOccur()} will always be false. */ public static QueryFactoryResult mergeResultsWithShould(final List<QueryFactoryResult> results) { containsNoNulls("results", results); final BooleanQuery finalQuery = new BooleanQuery(); for (QueryFactoryResult result : results) { if (!FALSE_RESULT.equals(result)) { addToBooleanWithShould(result, finalQuery); } } return new QueryFactoryResult(finalQuery); }
/** * @param fieldName the field to be visible * @param result the result to wrap * @return a new {@link com.atlassian.jira.jql.query.QueryFactoryResult} that combines the * visibility query with the input result, and that always has mustNotOccur() == false */ static QueryFactoryResult wrapWithVisibilityQuery( final String fieldName, final QueryFactoryResult result) { // don't bother wrapping a false result because it will return nothing anyway if (FALSE_RESULT.equals(result)) { return result; } final BooleanQuery finalQuery = new BooleanQuery(); addToBooleanWithMust(result, finalQuery); finalQuery.add(TermQueryFactory.visibilityQuery(fieldName), BooleanClause.Occur.MUST); return new QueryFactoryResult(finalQuery); }