Search in sources :

Example 1 with PostFilter

use of org.apache.solr.search.PostFilter in project SearchServices by Alfresco.

the class PostFilterQuery method getPostFilters.

private void getPostFilters(Query q, List<PostFilter> postFilters) {
    if (q instanceof BooleanQuery) {
        BooleanQuery bq = (BooleanQuery) q;
        List<BooleanClause> clauses = bq.clauses();
        for (BooleanClause clause : clauses) {
            Query q1 = clause.getQuery();
            getPostFilters(q1, postFilters);
        }
    } else if (q instanceof ContextAwareQuery) {
        ContextAwareQuery cq = (ContextAwareQuery) q;
        getPostFilters(cq.getLuceneQuery(), postFilters);
    } else if (q instanceof PostFilter) {
        postFilters.add((PostFilter) q);
    } else if (q instanceof BoostQuery) {
        BoostQuery bq = (BoostQuery) q;
        getPostFilters(bq.getQuery(), postFilters);
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ContextAwareQuery(org.alfresco.solr.ContextAwareQuery) BoostQuery(org.apache.lucene.search.BoostQuery) ContextAwareQuery(org.alfresco.solr.ContextAwareQuery) PostFilter(org.apache.solr.search.PostFilter)

Example 2 with PostFilter

use of org.apache.solr.search.PostFilter in project SearchServices by Alfresco.

the class PostFilterQuery method getFilterCollector.

public DelegatingCollector getFilterCollector(IndexSearcher searcher) {
    List<PostFilter> postFilters = new ArrayList<PostFilter>();
    getPostFilters(query, postFilters);
    Collections.sort(postFilters, new PostFilterComp());
    List<DelegatingCollector> delegatingCollectors = new ArrayList<DelegatingCollector>();
    for (PostFilter postFilter : postFilters) {
        DelegatingCollector delegatingCollector = postFilter.getFilterCollector(searcher);
        if (!(delegatingCollector instanceof AllAccessCollector)) {
            delegatingCollectors.add(delegatingCollector);
        }
    }
    if (delegatingCollectors.size() == 0) {
        return new AllAccessCollector();
    } else if (delegatingCollectors.size() == 1) {
        return delegatingCollectors.get(0);
    } else {
        return new WrapperCollector(delegatingCollectors);
    }
}
Also used : DelegatingCollector(org.apache.solr.search.DelegatingCollector) ArrayList(java.util.ArrayList) PostFilter(org.apache.solr.search.PostFilter)

Aggregations

PostFilter (org.apache.solr.search.PostFilter)2 ArrayList (java.util.ArrayList)1 ContextAwareQuery (org.alfresco.solr.ContextAwareQuery)1 BooleanClause (org.apache.lucene.search.BooleanClause)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 Query (org.apache.lucene.search.Query)1 DelegatingCollector (org.apache.solr.search.DelegatingCollector)1