Java 类org.apache.lucene.search.ChainedFilter 实例源码

项目:open-cyclos    文件:Filters.java   
/**
 * Returns all filters in a OR operation
 */
private static Filter chain(final int logic, Filter... filters) {
    filters = normalize(filters);
    if (ArrayUtils.isEmpty(filters)) {
        return null;
    }
    return new ChainedFilter(filters, logic);
}
项目:Equella    文件:ItemIndex.java   
public String suggestTerm(final Search request, final String prefix, final boolean isSearchAttachment)
{
    return search(new Searcher<String>()
    {
        @Override
        public String search(IndexSearcher searcher) throws IOException
        {
            // Get the reader
            IndexReader reader = searcher.getIndexReader();

            // Get all the docs from the filters
            Collection<Filter> filters = getFilters(request);
            Query query = getQuery(request, reader, isSearchAttachment);
            filters.add(new QueryWrapperFilter(query));
            ChainedFilter chain = new ChainedFilter(filters.toArray(new Filter[filters.size()]), ChainedFilter.AND);
            DocIdSetIterator iterator = chain.getDocIdSet(reader).iterator();

            // Get docs that contain terms that begin with the prefix
            List<Term> termList = Lists.newArrayList();
            termList.add(new Term(FreeTextQuery.FIELD_BODY_NOSTEM, prefix));
            termList.add(new Term(FreeTextQuery.FIELD_ATTACHMENT_VECTORED_NOSTEM, prefix));

            for( Term term : termList )
            {
                TermDocs termDocs = reader.termDocs(term);
                TermEnum terms = reader.terms(term);

                // Check if doc is in the filter and return the term
                Term t;
                for( t = terms.term(); t != null && t.text().startsWith(prefix); t = terms.term() )
                {
                    termDocs.seek(t);
                    while( termDocs.next() )
                    {
                        int docId = termDocs.doc();
                        if( docId == iterator.advance(docId) )
                        {
                            return t.text();
                        }
                    }
                    terms.next();
                }
            }
            return "";
        }
    });
}
项目:Equella    文件:ItemIndex.java   
protected Filter getFilter(Search request)
{
    Collection<Filter> filters = getFilters(request);
    return new ChainedFilter(filters.toArray(new Filter[filters.size()]), ChainedFilter.AND);
}
项目:open-cyclos    文件:Filters.java   
/**
 * Returns all filters in a AND operation
 */
public static Filter and(final Filter... filters) {
    return chain(ChainedFilter.AND, filters);
}
项目:open-cyclos    文件:Filters.java   
/**
 * Returns all filters in a ANDNOT operation
 */
public static Filter andNot(final Filter... filters) {
    return chain(ChainedFilter.ANDNOT, filters);
}
项目:open-cyclos    文件:Filters.java   
/**
 * Returns all filters in a OR operation
 */
public static Filter or(final Filter... filters) {
    return chain(ChainedFilter.OR, filters);
}