Search in sources :

Example 11 with IQueryRestriction

use of com.celements.search.lucene.query.IQueryRestriction in project celements-blog by celements.

the class BlogWebSearchPackageTest method test_getQueryRestriction_text_tokenized.

@Test
public void test_getQueryRestriction_text_tokenized() {
    String searchTerm1 = "find";
    String searchTerm2 = "us";
    IQueryRestriction restriction = webSearchPackage.getQueryRestriction(null, Joiner.on(' ').join(searchTerm1, searchTerm2));
    assertNotNull(restriction);
    assertEquals(String.format("(XWiki.ArticleClass.lang:(+%s*) AND " + "(XWiki.ArticleClass.title:(+%s* +%s*) OR XWiki.ArticleClass.extract:(+%s* +%s*) OR " + "XWiki.ArticleClass.content:(+%s* +%s*)))", getContext().getLanguage(), searchTerm1, searchTerm2, searchTerm1, searchTerm2, searchTerm1, searchTerm2), restriction.getQueryString());
}
Also used : IQueryRestriction(com.celements.search.lucene.query.IQueryRestriction) AbstractComponentTest(com.celements.common.test.AbstractComponentTest) Test(org.junit.Test)

Example 12 with IQueryRestriction

use of com.celements.search.lucene.query.IQueryRestriction 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 13 with IQueryRestriction

use of com.celements.search.lucene.query.IQueryRestriction 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

IQueryRestriction (com.celements.search.lucene.query.IQueryRestriction)13 Test (org.junit.Test)9 SpaceReference (org.xwiki.model.reference.SpaceReference)6 AbstractComponentTest (com.celements.common.test.AbstractComponentTest)4 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)4 QueryRestriction (com.celements.search.lucene.query.QueryRestriction)1