本文整理汇总了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
}
}
示例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;
}
}
示例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);
}
示例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
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
示例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));
}
}
示例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;
}
示例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" ) );
}
示例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" ) );
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}