tokenConditions.add(tokenCondition);
}
/* Build custom Query out of Conditions */
for (ISearchCondition tokenCondition : tokenConditions) {
BooleanClause tokenClause = createAllNewsFieldsClause(analyzer, tokenCondition, matchAllConditions);
/* Ignore empty clauses (e.g. due to Stop Words) */
if (tokenClause.getQuery() instanceof BooleanQuery && ((BooleanQuery) tokenClause.getQuery()).getClauses().length == 0)
continue;
tokenClause.setOccur(Occur.MUST);
allFieldsQuery.add(tokenClause);
}
}
/* Require any word to be contained or not contained */
else {
List<ISearchCondition> allFieldsConditions = new ArrayList<ISearchCondition>(5);
/* Title */
ISearchField field = factory.createSearchField(INews.TITLE, condition.getField().getEntityName());
allFieldsConditions.add(factory.createSearchCondition(field, condition.getSpecifier(), condition.getValue()));
/* Description */
field = factory.createSearchField(INews.DESCRIPTION, condition.getField().getEntityName());
allFieldsConditions.add(factory.createSearchCondition(field, condition.getSpecifier(), condition.getValue()));
/* Author */
field = factory.createSearchField(INews.AUTHOR, condition.getField().getEntityName());
allFieldsConditions.add(factory.createSearchCondition(field, condition.getSpecifier(), condition.getValue()));
/* Category */
field = factory.createSearchField(INews.CATEGORIES, condition.getField().getEntityName());
List<String> tokens = StringUtils.tokenizePhraseAware(condition.getValue().toString());
if (!tokens.contains(condition.getValue().toString()))
tokens.add(condition.getValue().toString());
for (String token : tokens) {
allFieldsConditions.add(factory.createSearchCondition(field, condition.getSpecifier().isNegation() ? SearchSpecifier.IS_NOT : SearchSpecifier.IS, token));
}
/* Attachment Content */
field = factory.createSearchField(INews.ATTACHMENTS_CONTENT, condition.getField().getEntityName());
allFieldsConditions.add(factory.createSearchCondition(field, condition.getSpecifier(), condition.getValue()));
/* Create Clauses out of Conditions */
boolean anyClauseIsEmpty = false;
List<BooleanClause> clauses = new ArrayList<BooleanClause>();
for (ISearchCondition allFieldCondition : allFieldsConditions) {
BooleanClause clause = createBooleanClause(analyzer, allFieldCondition, matchAllConditions);
clause.setOccur(Occur.SHOULD);
clauses.add(clause);
/* Ignore empty clauses (e.g. due to Stop Words) */
if (clause.getQuery() instanceof BooleanQuery && ((BooleanQuery) clause.getQuery()).getClauses().length == 0)
anyClauseIsEmpty = true;
}
/* Only add if none of the clauses is empty */
if (!anyClauseIsEmpty) {
for (BooleanClause clause : clauses) {
allFieldsQuery.add(clause);
}
}
}
/* Determine Occur (MUST, SHOULD, MUST NOT) */
Occur occur = getOccur(condition.getSpecifier(), matchAllConditions);
return new BooleanClause(allFieldsQuery, occur);
}