org.apache.lucene.search.FilteredQuery Java Examples

The following examples show how to use org.apache.lucene.search.FilteredQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlurSecureIndexSearcher.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example #2
Source File: Queries.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Query createAllDocsQuery(final @NonNull String name) {
    if (name.length() == 0) {
        return new MatchAllDocsQuery();
    } else {
        return new FilteredQuery(new MatchAllDocsQuery(), new HasFieldFilter(name));
    }
}
 
Example #3
Source File: QueryParserUtil.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #4
Source File: BlurSecureIndexSearcherTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #5
Source File: Queries.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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));
}
 
Example #6
Source File: FilteredQueryConstructor.java    From linden with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #7
Source File: SuperParser.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
private Query wrapFilter(Query query) {
  if (_queryFilter == null) {
    return query;
  }
  return new FilteredQuery(query, _queryFilter, FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY);
}