private static boolean isLocationScopeCondition(ISearchCondition condition) {
return condition.getSpecifier() == SearchSpecifier.SCOPE;
}
private static BooleanClause createAllNewsFieldsClause(Analyzer analyzer, ISearchCondition condition, boolean matchAllConditions) throws IOException {
IModelFactory factory = Owl.getModelFactory();
BooleanQuery allFieldsQuery = new BooleanQuery();
/* Require all words to be contained or not contained */
if (condition.getSpecifier() == SearchSpecifier.CONTAINS_ALL) {
List<ISearchCondition> tokenConditions = new ArrayList<ISearchCondition>();
List<String> tokens = StringUtils.tokenizePhraseAware((String) condition.getValue(), true);
for (String token : tokens) {
ISearchCondition tokenCondition = factory.createSearchCondition(condition.getField(), condition.getSpecifier(), token);
/* Rewrite Specifier */
if (condition.getSpecifier() == SearchSpecifier.CONTAINS_ALL)
tokenCondition.setSpecifier(SearchSpecifier.CONTAINS);
else
tokenCondition.setSpecifier(SearchSpecifier.CONTAINS_NOT);
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 (Phrase search stripped because unsupported */
field = factory.createSearchField(INews.CATEGORIES, condition.getField().getEntityName());
List<String> tokens = StringUtils.tokenizePhraseAware(condition.getValue().toString(), false);
if (!tokens.contains(condition.getValue().toString()))
tokens.add(condition.getValue().toString());
for (String token : tokens) {
if (token.length() != 0)
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) {