use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilderTest method testGetArticleSubsRestrictions_undecided_unsubscribed.
@Test
public void testGetArticleSubsRestrictions_undecided_unsubscribed() {
Set<SubscriptionMode> modes = new HashSet<>(Arrays.asList(SubscriptionMode.UNDECIDED, SubscriptionMode.UNSUBSCRIBED));
boolean hasEditRights = true;
QueryRestrictionGroup ret = builder.getArticleSubsRestrictions(modes, docRef, hasEditRights);
assertEquals(getSubsQuery(true), ret.getQueryString());
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilderTest method testGetArticleSubsRestrictions_unsubscribed_noEditRights.
@Test
public void testGetArticleSubsRestrictions_unsubscribed_noEditRights() {
Set<SubscriptionMode> modes = new HashSet<>(Arrays.asList(SubscriptionMode.UNSUBSCRIBED));
boolean hasEditRights = false;
QueryRestrictionGroup ret = builder.getArticleSubsRestrictions(modes, docRef, hasEditRights);
assertNull(ret);
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getBlogSearchTermRestriction.
IQueryRestriction getBlogSearchTermRestriction(ArticleLoadParameter param) throws XWikiException {
QueryRestrictionGroup restr = null;
if (param.isWithBlogArticles() && (param.getSearchTerm() != null)) {
restr = searchService.createRestrictionGroup(Type.OR);
restr.add(new QueryRestriction("XWiki.ArticleClass.extract", param.getSearchTerm()));
restr.add(new QueryRestriction("XWiki.ArticleClass.title", param.getSearchTerm()));
restr.add(new QueryRestriction("XWiki.ArticleClass.content", param.getSearchTerm()));
}
LOGGER.trace("got blog restriction " + restr + "' for '" + param + "'");
return restr;
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getArticleSubsRestrictions.
QueryRestrictionGroup getArticleSubsRestrictions(Set<SubscriptionMode> modes, DocumentReference blogConfDocRef, boolean hasEditRights) {
QueryRestrictionGroup ret = null;
if ((modes.size() < SubscriptionMode.values().length) || !hasEditRights) {
QueryRestrictionGroup artSubsRestrs = searchService.createRestrictionGroup(Type.OR);
DocumentReference classRef = getBlogClasses().getBlogArticleSubscriptionClassRef(blogConfDocRef.getWikiReference().getName());
boolean undecided = modes.contains(SubscriptionMode.UNDECIDED) && hasEditRights;
if (modes.contains(SubscriptionMode.SUBSCRIBED) != undecided) {
artSubsRestrs.add(searchService.createFieldRestriction(classRef, BlogClasses.PROPERTY_ARTICLE_SUBSCRIPTION_DO_SUBSCRIBE, "\"1\""));
}
if ((modes.contains(SubscriptionMode.UNSUBSCRIBED) != undecided) && hasEditRights) {
artSubsRestrs.add(searchService.createFieldRestriction(classRef, BlogClasses.PROPERTY_ARTICLE_SUBSCRIPTION_DO_SUBSCRIBE, "\"0\""));
}
if (!artSubsRestrs.isEmpty()) {
ret = searchService.createRestrictionGroup(Type.AND);
ret.add(searchService.createObjectRestriction(classRef));
ret.add(artSubsRestrs);
ret.add(searchService.createFieldRefRestriction(classRef, BlogClasses.PROPERTY_ARTICLE_SUBSCRIPTION_SUBSCRIBER, blogConfDocRef));
ret.setNegate(undecided);
}
LOGGER.trace("getArticleSubsRestrictions: for modes '{}', hasEditRights '{}', " + "undecided '{}' returns '{}'", modes, hasEditRights, undecided, ret);
} else {
ret = searchService.createRestrictionGroup(Type.AND);
}
return ret;
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getDateRestrictions.
QueryRestrictionGroup getDateRestrictions(Set<DateMode> modes, Date date, boolean hasEditRights) {
QueryRestrictionGroup ret = null;
if ((modes.size() < DateMode.values().length) || !hasEditRights) {
// TODO not-restrictions shouldn't be inclusive of date but rather
// {date TO highdate]). this doesn't work for now, see Ticket #7245
IQueryRestriction publishRestr = searchService.createFromToDateRestriction(ARTICLE_FIELD_PUBLISH, null, date, true);
IQueryRestriction notPublishRestr = searchService.createFromToDateRestriction(ARTICLE_FIELD_PUBLISH, date, null, true);
IQueryRestriction archiveRestr = searchService.createFromToDateRestriction(ARTICLE_FIELD_ARCHIVE, null, date, true);
IQueryRestriction notArchiveRestr = searchService.createFromToDateRestriction(ARTICLE_FIELD_ARCHIVE, date, null, true);
if (modes.contains(DateMode.PUBLISHED)) {
QueryRestrictionGroup restrs = searchService.createRestrictionGroup(Type.AND);
restrs.add(publishRestr);
restrs.add(notArchiveRestr);
ret = addRestrToGrp(ret, restrs);
}
if (modes.contains(DateMode.FUTURE) && hasEditRights) {
ret = addRestrToGrp(ret, notPublishRestr);
}
if (modes.contains(DateMode.ARCHIVED)) {
ret = addRestrToGrp(ret, archiveRestr);
}
} else {
ret = searchService.createRestrictionGroup(Type.OR);
}
return ret;
}
Aggregations