Java Code Examples for org.apache.lucene.search.FilteredQuery

The following examples show how to use org.apache.lucene.search.FilteredQuery. These examples are extracted from open source projects. 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
/**
 * 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 Project: netbeans   Source File: Queries.java    License: 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 Project: incubator-retired-blur   Source File: QueryParserUtil.java    License: 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
@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 Project: netbeans   Source File: Queries.java    License: 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 Project: linden   Source File: FilteredQueryConstructor.java    License: 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 Project: incubator-retired-blur   Source File: SuperParser.java    License: 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);
}