/** * 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); }
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 ""; } }); }
protected Filter getFilter(Search request) { Collection<Filter> filters = getFilters(request); return new ChainedFilter(filters.toArray(new Filter[filters.size()]), ChainedFilter.AND); }
/** * Returns all filters in a AND operation */ public static Filter and(final Filter... filters) { return chain(ChainedFilter.AND, filters); }
/** * Returns all filters in a ANDNOT operation */ public static Filter andNot(final Filter... filters) { return chain(ChainedFilter.ANDNOT, filters); }
/** * Returns all filters in a OR operation */ public static Filter or(final Filter... filters) { return chain(ChainedFilter.OR, filters); }