Search in sources :

Example 1 with QueryRestrictionGroup

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;
}
Also used : IQueryRestriction(com.celements.search.lucene.query.IQueryRestriction) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Example 2 with QueryRestrictionGroup

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Example 3 with QueryRestrictionGroup

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;
}
Also used : LuceneQuery(com.celements.search.lucene.query.LuceneQuery) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Example 4 with QueryRestrictionGroup

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;
}
Also used : IQueryRestriction(com.celements.search.lucene.query.IQueryRestriction) SpaceReference(org.xwiki.model.reference.SpaceReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Example 5 with QueryRestrictionGroup

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;
}
Also used : QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Aggregations

QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)45 Test (org.junit.Test)37 HashSet (java.util.HashSet)28 DateMode (com.celements.blog.article.ArticleLoadParameter.DateMode)15 SubscriptionMode (com.celements.blog.article.ArticleLoadParameter.SubscriptionMode)15 Date (java.util.Date)15 SpaceReference (org.xwiki.model.reference.SpaceReference)8 DocumentReference (org.xwiki.model.reference.DocumentReference)7 IQueryRestriction (com.celements.search.lucene.query.IQueryRestriction)4 LuceneQuery (com.celements.search.lucene.query.LuceneQuery)1 QueryRestriction (com.celements.search.lucene.query.QueryRestriction)1 WikiReference (org.xwiki.model.reference.WikiReference)1