use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getSubsSpaceRestriction.
QueryRestrictionGroup getSubsSpaceRestriction(ArticleLoadParameter param, SpaceReference spaceRef) throws XWikiException {
QueryRestrictionGroup subsSpaceGrp = null;
boolean hasEditRights = rightsAccess.hasAccessLevel(spaceRef, EAccessLevel.EDIT);
IQueryRestriction dateRestr = getDateRestrictions(param.getDateModes(), param.getExecutionDate(), hasEditRights);
IQueryRestriction artSubsRestr = getArticleSubsRestrictions(param.getSubscriptionModes(), param.getBlogDocRef(), hasEditRights);
if ((artSubsRestr != null) && (dateRestr != null)) {
subsSpaceGrp = searchService.createRestrictionGroup(Type.AND);
subsSpaceGrp.add(searchService.createSpaceRestriction(spaceRef));
subsSpaceGrp.add(dateRestr);
subsSpaceGrp.add(artSubsRestr);
} else {
LOGGER.debug("no date restriction '" + dateRestr + "' or article subs " + "restriction '" + artSubsRestr + "' for space '" + spaceRef + "' with edit righs '" + hasEditRights + "'");
}
LOGGER.trace("got space restriction '" + subsSpaceGrp + "' for space: " + spaceRef);
return subsSpaceGrp;
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getSubsRestrictions.
QueryRestrictionGroup getSubsRestrictions(ArticleLoadParameter param) throws XWikiException {
QueryRestrictionGroup ret = null;
QueryRestrictionGroup subsOrGrp = searchService.createRestrictionGroup(Type.OR);
for (DocumentReference docRef : param.getSubscribedToBlogs()) {
SpaceReference spaceRef = blogService.getBlogSpaceRef(docRef);
if (rightsAccess.hasAccessLevel(spaceRef, EAccessLevel.VIEW)) {
subsOrGrp.add(getSubsSpaceRestriction(param, spaceRef));
}
}
if (!subsOrGrp.isEmpty()) {
ret = searchService.createRestrictionGroup(Type.AND);
DocumentReference articleClassRef = getBlogClasses().getArticleClassRef(param.getBlogDocRef().getWikiReference().getName());
ret.add(searchService.createFieldRestriction(articleClassRef, BlogClasses.PROPERTY_ARTICLE_IS_SUBSCRIBABLE, "\"1\""));
ret.add(subsOrGrp);
}
LOGGER.trace("got subs restriction " + ret + "' for '" + param + "'");
return ret;
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method build.
@Override
public LuceneQuery build(ArticleLoadParameter param) throws XWikiException {
LuceneQuery query = null;
if (param.getBlogDocRef() != null) {
QueryRestrictionGroup blogOrSubsGrp = searchService.createRestrictionGroup(Type.OR);
blogOrSubsGrp.add(getBlogRestriction(param));
blogOrSubsGrp.add(getSubsRestrictions(param));
if (!blogOrSubsGrp.isEmpty()) {
WikiReference wikiRef = param.getBlogDocRef().getWikiReference();
query = searchService.createQuery();
query.setWiki(wikiRef);
query.add(getBlogSearchTermRestriction(param));
DocumentReference articleClassRef = getBlogClasses().getArticleClassRef(wikiRef.getName());
query.add(searchService.createObjectRestriction(articleClassRef));
if (StringUtils.isNotBlank(param.getLanguage())) {
query.add(searchService.createFieldRestriction(articleClassRef, BlogClasses.PROPERTY_ARTICLE_LANG, "\"" + param.getLanguage() + "\""));
}
query.add(blogOrSubsGrp);
}
}
LOGGER.info("Built '" + query + "' for '" + param + "'");
return query;
}
use of com.celements.search.lucene.query.QueryRestrictionGroup in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getBlogRestriction.
IQueryRestriction getBlogRestriction(ArticleLoadParameter param) throws XWikiException {
QueryRestrictionGroup restr = null;
SpaceReference blogSpaceRef = blogService.getBlogSpaceRef(param.getBlogDocRef());
if (param.isWithBlogArticles() && rightsAccess.hasAccessLevel(blogSpaceRef, EAccessLevel.VIEW)) {
IQueryRestriction dateRestr = getDateRestrictions(param.getDateModes(), param.getExecutionDate(), rightsAccess.hasAccessLevel(blogSpaceRef, EAccessLevel.EDIT));
if (dateRestr != null) {
restr = searchService.createRestrictionGroup(Type.AND);
restr.add(searchService.createSpaceRestriction(blogSpaceRef));
restr.add(dateRestr);
}
}
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 BlogWebSearchPackage method getQueryRestriction.
@Override
public IQueryRestriction getQueryRestriction(XWikiDocument cfgDoc, String searchTerm) {
QueryRestrictionGroup grp = searchService.createRestrictionGroup(Type.AND);
grp.add(searchService.createFieldRestriction(getArticleClassDocRef(), BlogClasses.PROPERTY_ARTICLE_LANG, context.getXWikiContext().getLanguage()));
if (LuceneSearchService.DATE_PATTERN.matcher(searchTerm).matches()) {
grp.add(searchService.createFieldRestriction(getArticleClassDocRef(), BlogClasses.PROPERTY_ARTICLE_PUBLISH_DATE, searchTerm, false));
} else {
QueryRestrictionGroup orGrp = searchService.createRestrictionGroup(Type.OR);
orGrp.add(searchService.createFieldRestriction(getArticleClassDocRef(), "title", searchTerm));
orGrp.add(searchService.createFieldRestriction(getArticleClassDocRef(), "extract", searchTerm));
orGrp.add(searchService.createFieldRestriction(getArticleClassDocRef(), "content", searchTerm));
grp.add(orGrp);
}
return grp;
}
Aggregations