Java 类org.apache.lucene.search.FilteredQuery 实例源码

项目:search    文件:QueryTermExtractor.java   
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
  }
}
项目:search    文件:TestUtil.java   
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;
  }
}
项目:search    文件:AbstractSpatialFieldType.java   
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);
}
项目:NYBC    文件:QueryTermExtractor.java   
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
  }
}
项目:NYBC    文件:_TestUtil.java   
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;
  }
}
项目:incubator-blur    文件:BlurSecureIndexSearcher.java   
/**
 * 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);
  }
}
项目:read-open-source-code    文件:QueryTermExtractor.java   
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
  }
}
项目:read-open-source-code    文件:QueryTermExtractor.java   
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
  }
}
项目:read-open-source-code    文件:QueryTermExtractor.java   
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
  }
}
项目:read-open-source-code    文件:AbstractSpatialFieldType.java   
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);
}
项目:elasticsearch-analysis-german    文件:AssertingIndexSearcher.java   
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;
    }
}
项目:Maskana-Gestor-de-Conocimiento    文件:QueryTermExtractor.java   
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
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:_TestUtil.java   
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;
  }
}
项目:t4f-data    文件:SpecialsFilterTest.java   
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);
}
项目:incubator-netbeans    文件:Queries.java   
@Override
public Query createAllDocsQuery(final @NonNull String name) {
    if (name.length() == 0) {
        return new MatchAllDocsQuery();
    } else {
        return new FilteredQuery(new MatchAllDocsQuery(), new HasFieldFilter(name));
    }
}
项目:lams    文件:FilteredQueryBuilder.java   
@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;
}
项目:search    文件:FieldQueryTest.java   
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" ) );
}
项目:search    文件:FilteredQueryBuilder.java   
@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;
}
项目:NYBC    文件:FieldQueryTest.java   
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" ) );
}
项目:NYBC    文件:FilteredQueryBuilder.java   
@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;
}
项目:NYBC    文件:AbstractSpatialFieldType.java   
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);
}
项目:incubator-blur    文件:QueryParserUtil.java   
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);
}
项目:incubator-blur    文件:BlurSecureIndexSearcherTest.java   
@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);
  }
}
项目:search-core    文件:AbstractSpatialFieldType.java   
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);
}
项目:read-open-source-code    文件:FilteredQueryBuilder.java   
@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;
}
项目:read-open-source-code    文件:AbstractSpatialFieldType.java   
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);
}
项目:read-open-source-code    文件:FilteredQueryBuilder.java   
@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;
}
项目:read-open-source-code    文件:FilteredQueryBuilder.java   
@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;
}
项目:elasticsearch-analysis-german    文件:AssertingIndexSearcher.java   
@Override
protected Query wrapFilter(Query query, Filter filter) {
    if (random.nextBoolean()) {
        return super.wrapFilter(query, filter);
    }
    return (filter == null) ? query : new FilteredQuery(query, filter, randomFilterStrategy(random));
}
项目:Maskana-Gestor-de-Conocimiento    文件:FieldQueryTest.java   
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" ) );
}
项目:Maskana-Gestor-de-Conocimiento    文件:FilteredQueryBuilder.java   
@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;
}
项目:incubator-netbeans    文件:Queries.java   
@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));
}
项目:linden    文件:FilteredQueryConstructor.java   
@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);
}
项目:search    文件:QueryTermExtractor.java   
private static void getTermsFromFilteredQuery(FilteredQuery query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
{
  getTerms(query.getQuery(),terms,prohibited,fieldName);
}
项目:search    文件:TestMultiTermHighlighting.java   
public void testWildcardInFiltered() throws Exception {
  Directory dir = newDirectory();
  // use simpleanalyzer for more natural tokenization (else "test." is a token)
  final Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
  IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
  iwc.setMergePolicy(newLogMergePolicy());
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);

  FieldType offsetsType = new FieldType(TextField.TYPE_STORED);
  offsetsType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  Field body = new Field("body", "", offsetsType);
  Document doc = new Document();
  doc.add(body);

  body.setStringValue("This is a test.");
  iw.addDocument(doc);
  body.setStringValue("Test a one sentence document.");
  iw.addDocument(doc);

  IndexReader ir = iw.getReader();
  iw.close();

  IndexSearcher searcher = newSearcher(ir);
  PostingsHighlighter highlighter = new PostingsHighlighter() {
    @Override
    protected Analyzer getIndexAnalyzer(String field) {
      return analyzer;
    }
  };
  FilteredQuery query = new FilteredQuery(
      new WildcardQuery(new Term("body", "te*")),
      new TermFilter(new Term("body", "test")));
  TopDocs topDocs = searcher.search(query, null, 10, Sort.INDEXORDER);
  assertEquals(2, topDocs.totalHits);
  String snippets[] = highlighter.highlight("body", query, searcher, topDocs);
  assertEquals(2, snippets.length);
  assertEquals("This is a <b>test</b>.", snippets[0]);
  assertEquals("<b>Test</b> a one sentence document.", snippets[1]);

  ir.close();
  dir.close();
}
项目:search    文件:SerializedStrategyTest.java   
@Override
protected Query makeQuery(SpatialTestQuery q) {
  return new FilteredQuery(new MatchAllDocsQuery(), strategy.makeFilter(q.args),
      FilteredQuery.QUERY_FIRST_FILTER_STRATEGY);
}
项目:NYBC    文件:QueryTermExtractor.java   
private static void getTermsFromFilteredQuery(FilteredQuery query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
{
  getTerms(query.getQuery(),terms,prohibited,fieldName);
}
项目:incubator-blur    文件:SuperParser.java   
private Query wrapFilter(Query query) {
  if (_queryFilter == null) {
    return query;
  }
  return new FilteredQuery(query, _queryFilter, FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY);
}
项目:read-open-source-code    文件:QueryTermExtractor.java   
private static void getTermsFromFilteredQuery(FilteredQuery query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
{
  getTerms(query.getQuery(),terms,prohibited,fieldName);
}
项目:read-open-source-code    文件:QueryTermExtractor.java   
private static void getTermsFromFilteredQuery(FilteredQuery query, HashSet<WeightedTerm> terms, boolean prohibited, String fieldName)
{
  getTerms(query.getQuery(),terms,prohibited,fieldName);
}