Java源码示例:org.apache.lucene.search.FilteredQuery
示例1
/**
* This method is very important!!! It handles rewriting the real query (which
* can be a {@link SuperQuery} to have document (record) level filtering or
* access control.
*/
@Override
protected Query wrapFilter(Query query, Filter filter) {
if (filter == null) {
return query;
} else if (query instanceof SuperQuery) {
SuperQuery superQuery = (SuperQuery) query;
Query innerQuery = superQuery.getQuery();
Term primeDocTerm = superQuery.getPrimeDocTerm();
ScoreType scoreType = superQuery.getScoreType();
return new SuperQuery(wrapFilter(innerQuery, filter), scoreType, primeDocTerm);
} else if (query instanceof BooleanQuery) {
BooleanQuery booleanQuery = (BooleanQuery) query;
List<BooleanClause> clauses = booleanQuery.clauses();
for (BooleanClause booleanClause : clauses) {
booleanClause.setQuery(wrapFilter(booleanClause.getQuery(), filter));
}
return booleanQuery;
} else {
return new FilteredQuery(query, filter);
}
}
示例2
@Override
public Query createAllDocsQuery(final @NonNull String name) {
if (name.length() == 0) {
return new MatchAllDocsQuery();
} else {
return new FilteredQuery(new MatchAllDocsQuery(), new HasFieldFilter(name));
}
}
示例3
public static Query parseQuery(String query, boolean superQueryOn, FieldManager fieldManager, Filter postFilter,
Filter preFilter, ScoreType scoreType, TableContext tableContext) throws ParseException {
Query result = new SuperParser(LUCENE_VERSION, fieldManager, superQueryOn, preFilter, scoreType,
tableContext.getDefaultPrimeDocTerm()).parse(query);
if (postFilter == null) {
return result;
}
return new FilteredQuery(result, postFilter);
}
示例4
@Test
public void testQueryFilterWrap1() throws IOException {
IndexReader r = getIndexReader();
AccessControlFactory accessControlFactory = new FilterAccessControlFactory();
Collection<String> readAuthorizations = new ArrayList<String>();
Collection<String> discoverAuthorizations = new ArrayList<String>();
Set<String> discoverableFields = new HashSet<String>(Arrays.asList("rowid"));
BlurSecureIndexSearcher blurSecureIndexSearcher = new BlurSecureIndexSearcher(r, null, accessControlFactory,
readAuthorizations, discoverAuthorizations, discoverableFields, null);
Query wrapFilter;
Query query = new TermQuery(new Term("a", "b"));
Filter filter = new Filter() {
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
throw new RuntimeException("Not implemented.");
}
};
{
Term primeDocTerm = new Term(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE);
ScoreType scoreType = ScoreType.SUPER;
SuperQuery superQuery = new SuperQuery(query, scoreType, primeDocTerm);
wrapFilter = blurSecureIndexSearcher.wrapFilter(superQuery, filter);
System.out.println(wrapFilter);
}
{
assertTrue(wrapFilter instanceof SuperQuery);
SuperQuery sq = (SuperQuery) wrapFilter;
Query inner = sq.getQuery();
assertTrue(inner instanceof FilteredQuery);
FilteredQuery filteredQuery = (FilteredQuery) inner;
Query innerFilteredQuery = filteredQuery.getQuery();
assertEquals(innerFilteredQuery, query);
assertTrue(filteredQuery.getFilter() == filter);
}
}
示例5
@Override
public Query createRegExpQuery(final @NonNull String name, final @NonNull String value, final boolean caseSensitive) {
return new FilteredQuery(new MatchAllDocsQuery(), new RegexpFilter(name, value, caseSensitive));
}
示例6
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws Exception {
Query query = QueryConstructor.constructQuery(lindenQuery.getFilteredQuery().getLindenQuery(), config);
Filter filter = FilterConstructor.constructFilter(lindenQuery.getFilteredQuery().getLindenFilter(), config);
return new FilteredQuery(query, filter);
}
示例7
private Query wrapFilter(Query query) {
if (_queryFilter == null) {
return query;
}
return new FilteredQuery(query, _queryFilter, FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY);
}