Search in sources :

Example 41 with QueryRestrictionGroup

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());
}
Also used : SubscriptionMode(com.celements.blog.article.ArticleLoadParameter.SubscriptionMode) HashSet(java.util.HashSet) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Example 42 with QueryRestrictionGroup

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);
}
Also used : SubscriptionMode(com.celements.blog.article.ArticleLoadParameter.SubscriptionMode) HashSet(java.util.HashSet) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup) Test(org.junit.Test)

Example 43 with QueryRestrictionGroup

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

Example 44 with QueryRestrictionGroup

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

Example 45 with QueryRestrictionGroup

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