当前位置: 首页>>代码示例>>Java>>正文


Java FilteredQuery类代码示例

本文整理汇总了Java中org.apache.lucene.search.FilteredQuery的典型用法代码示例。如果您正苦于以下问题:Java FilteredQuery类的具体用法?Java FilteredQuery怎么用?Java FilteredQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FilteredQuery类属于org.apache.lucene.search包,在下文中一共展示了FilteredQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTerms

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
private static final void getTerms(Query query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName) {
  try {
    if (query instanceof BooleanQuery)
      getTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
    else if (query instanceof FilteredQuery)
      getTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
    else {
      HashSet<Term> nonWeightedTerms = new HashSet<>();
      query.extractTerms(nonWeightedTerms);
      for (Iterator<Term> iter = nonWeightedTerms.iterator(); iter.hasNext(); ) {
        Term term = iter.next();
        if ((fieldName == null) || (term.field().equals(fieldName))) {
          terms.add(new WeightedTerm(query.getBoost(), term.text()));
        }
      }
    }
  } catch (UnsupportedOperationException ignore) {
    //this is non-fatal for our purposes
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:QueryTermExtractor.java

示例2: randomFilterStrategy

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
public static final FilterStrategy randomFilterStrategy(final Random random) {
  switch(random.nextInt(6)) {
    case 5:
    case 4:
      return new FilteredQuery.RandomAccessFilterStrategy() {
        @Override
        protected boolean useRandomAccess(Bits bits, int firstFilterDoc) {
          return LuceneTestCase.random().nextBoolean();
        }
      };
    case 3:
      return FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY;
    case 2:
      return FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY;
    case 1:
      return FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY;
    case 0: 
      return FilteredQuery.QUERY_FIRST_FILTER_STRATEGY;
    default:
      return FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:TestUtil.java

示例3: getQueryFromSpatialArgs

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
  T strategy = getStrategy(field.getName());

  SolrParams localParams = parser.getLocalParams();
  String scoreParam = (localParams == null ? null : localParams.get(SCORE_PARAM));

  //We get the valueSource for the score then the filter and combine them.

  ValueSource valueSource = getValueSourceFromSpatialArgs(parser, field, spatialArgs, scoreParam, strategy);
  if (valueSource == null) {
    //FYI Solr FieldType doesn't have a getFilter(). We'll always grab
    // getQuery() but it's possible a strategy has a more efficient getFilter
    // that could be wrapped -- no way to know.
    //See SOLR-2883 needScore
    return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
  }

  FunctionQuery functionQuery = new FunctionQuery(valueSource);

  if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
    return functionQuery;

  Filter filter = strategy.makeFilter(spatialArgs);
  return new FilteredQuery(functionQuery, filter);
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:AbstractSpatialFieldType.java

示例4: getTerms

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
private static final void getTerms(Query query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName) {
  try {
    if (query instanceof BooleanQuery)
      getTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
    else if (query instanceof FilteredQuery)
      getTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
    else {
      HashSet<Term> nonWeightedTerms = new HashSet<Term>();
      query.extractTerms(nonWeightedTerms);
      for (Iterator<Term> iter = nonWeightedTerms.iterator(); iter.hasNext(); ) {
        Term term = iter.next();
        if ((fieldName == null) || (term.field().equals(fieldName))) {
          terms.add(new WeightedTerm(query.getBoost(), term.text()));
        }
      }
    }
  } catch (UnsupportedOperationException ignore) {
    //this is non-fatal for our purposes
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:QueryTermExtractor.java

示例5: wrapFilter

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
/**
 * 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);
  }
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:27,代码来源:BlurSecureIndexSearcher.java

示例6: randomFilterStrategy

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
public static FilteredQuery.FilterStrategy randomFilterStrategy(final Random random) {
    switch (random.nextInt(6)) {
        case 5:
        case 4:
            return new FilteredQuery.RandomAccessFilterStrategy() {
                @Override
                protected boolean useRandomAccess(Bits bits, int firstFilterDoc) {
                    return random.nextBoolean();
                }
            };
        case 3:
            return FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY;
        case 2:
            return FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY;
        case 1:
            return FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY;
        case 0:
            return FilteredQuery.QUERY_FIRST_FILTER_STRATEGY;
        default:
            return FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY;
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-analysis-german,代码行数:23,代码来源:AssertingIndexSearcher.java

示例7: testFilteredQuery

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
public void testFilteredQuery() throws Exception {
    String[] isbns = new String[] { "9780880105118" };

    SpecialsAccessor accessor = new TestSpecialsAccessor(isbns);
    Filter filter = new SpecialsFilter(accessor);

    WildcardQuery educationBooks = new WildcardQuery(new Term("category", "*education*"));
    FilteredQuery edBooksOnSpecial = new FilteredQuery(educationBooks, filter);

    TermQuery logoBooks = new TermQuery(new Term("subject", "logo"));

    BooleanQuery logoOrEdBooks = new BooleanQuery();
    logoOrEdBooks.add(logoBooks, BooleanClause.Occur.SHOULD);
    logoOrEdBooks.add(edBooksOnSpecial, BooleanClause.Occur.SHOULD);

    TopDocs hits = searcher.search(logoOrEdBooks, 10);
    LOGGER.info(logoOrEdBooks.toString());
    assertEquals("Papert and Steiner", 2, hits.totalHits);
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:20,代码来源:SpecialsFilterTest.java

示例8: createAllDocsQuery

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
@Override
public Query createAllDocsQuery(final @NonNull String name) {
    if (name.length() == 0) {
        return new MatchAllDocsQuery();
    } else {
        return new FilteredQuery(new MatchAllDocsQuery(), new HasFieldFilter(name));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:Queries.java

示例9: getQuery

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
@Override
public Query getQuery(Element e) throws ParserException {
  Element filterElement = DOMUtils.getChildByTagOrFail(e, "Filter");
  filterElement = DOMUtils.getFirstChildOrFail(filterElement);
  Filter f = filterFactory.getFilter(filterElement);

  Element queryElement = DOMUtils.getChildByTagOrFail(e, "Query");
  queryElement = DOMUtils.getFirstChildOrFail(queryElement);
  Query q = queryFactory.getQuery(queryElement);

  FilteredQuery fq = new FilteredQuery(q, f);
  fq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
  return fq;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:FilteredQueryBuilder.java

示例10: testFlattenFilteredQuery

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
public void testFlattenFilteredQuery() throws Exception {
  initBoost();
  Query query = new FilteredQuery(pqF( "A" ), new Filter() {
    @Override
    public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs)
        throws IOException {
      return null;
    }
  });
  query.setBoost(boost);
  FieldQuery fq = new FieldQuery( query, true, true );
  Set<Query> flatQueries = new HashSet<>();
  fq.flatten( query, reader, flatQueries );
  assertCollectionQueries( flatQueries, tq( boost, "A" ) );
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:FieldQueryTest.java

示例11: testFlattenFilteredQuery

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
public void testFlattenFilteredQuery() throws Exception {
  Query query = new FilteredQuery(pqF( "A" ), new Filter() {
    @Override
    public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs)
        throws IOException {
      return null;
    }
  });
  FieldQuery fq = new FieldQuery( query, true, true );
  Set<Query> flatQueries = new HashSet<Query>();
  fq.flatten( query, reader, flatQueries );
  assertCollectionQueries( flatQueries, tq( "A" ) );
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:14,代码来源:FieldQueryTest.java

示例12: getQueryFromSpatialArgs

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
  T strategy = getStrategy(field.getName());

  SolrParams localParams = parser.getLocalParams();
  String score = (localParams == null ? null : localParams.get(SCORE_PARAM));
  if (score == null || "none".equals(score) || "".equals(score)) {
    //FYI Solr FieldType doesn't have a getFilter(). We'll always grab
    // getQuery() but it's possible a strategy has a more efficient getFilter
    // that could be wrapped -- no way to know.
    //See SOLR-2883 needScore
    return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
  }

  //We get the valueSource for the score then the filter and combine them.
  ValueSource valueSource;
  if ("distance".equals(score))
    valueSource = strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter());
  else if ("recipDistance".equals(score))
    valueSource = strategy.makeRecipDistanceValueSource(spatialArgs.getShape());
  else
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'");
  FunctionQuery functionQuery = new FunctionQuery(valueSource);

  if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
    return functionQuery;

  Filter filter = strategy.makeFilter(spatialArgs);
  return new FilteredQuery(functionQuery, filter);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:AbstractSpatialFieldType.java

示例13: parseQuery

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:10,代码来源:QueryParserUtil.java

示例14: testQueryFilterWrap1

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:36,代码来源:BlurSecureIndexSearcherTest.java

示例15: getQueryFromSpatialArgs

import org.apache.lucene.search.FilteredQuery; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
  T strategy = getStrategy(field.getName());

  SolrParams localParams = parser.getLocalParams();
  String score = (localParams == null ? null : localParams.get(SCORE_PARAM));
  if (score == null || "none".equals(score) || "".equals(score)) {
    //FYI Solr FieldType doesn't have a getFilter(). We'll always grab
    // getQuery() but it's possible a strategy has a more efficient getFilter
    // that could be wrapped -- no way to know.
    //See SOLR-2883 needScore
    return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
  }

  //We get the valueSource for the score then the filter and combine them.
  ValueSource valueSource;
  if ("distance".equals(score)) {
    double multiplier = 1.0;//TODO support units=kilometers
    valueSource = strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter(), multiplier);
  } else if ("recipDistance".equals(score)) {
    valueSource = strategy.makeRecipDistanceValueSource(spatialArgs.getShape());
  } else {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'score' local-param must be one of 'none', 'distance', or 'recipDistance'");
  }
  FunctionQuery functionQuery = new FunctionQuery(valueSource);

  if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
    return functionQuery;

  Filter filter = strategy.makeFilter(spatialArgs);
  return new FilteredQuery(functionQuery, filter);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:32,代码来源:AbstractSpatialFieldType.java


注:本文中的org.apache.lucene.search.FilteredQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。