List of usage examples for org.apache.lucene.search Weight getQuery
public final Query getQuery()
From source file:org.elasticsearch.common.lucene.search.function.CustomBoostFactorScorer.java
License:Apache License
CustomBoostFactorScorer(Weight w, Scorer scorer, float maxBoost, CombineFunction scoreCombiner, Float minScore) throws IOException { super(w);/* w w w . j a va 2 s . c o m*/ if (minScore == null) { nextDoc = new AnyNextDoc(); } else { nextDoc = new MinScoreNextDoc(); } this.subQueryBoost = w.getQuery().getBoost(); this.scorer = scorer; this.maxBoost = maxBoost; this.scoreCombiner = scoreCombiner; this.minScore = minScore; }
From source file:org.elasticsearch.xpack.security.authz.accesscontrol.OptOutQueryCache.java
License:Open Source License
/** * Returns true if its safe to use the query cache for this query. *///from w w w . java 2 s . c om static boolean cachingIsSafe(Weight weight, IndicesAccessControl.IndexAccessControl permissions) { // support caching for common queries, by inspecting the field // TODO: If in the future there is a Query#extractFields() then we can do a better job Set<String> fields = new HashSet<>(); try { FieldExtractor.extractFields(weight.getQuery(), fields); } catch (UnsupportedOperationException ok) { // we don't know how to safely extract the fields of this query, don't cache. return false; } // we successfully extracted the set of fields: check each one for (String field : fields) { // don't cache any internal fields (e.g. _field_names), these are complicated. if (field.startsWith("_") || permissions.getFieldPermissions().grantsAccessTo(field) == false) { return false; } } // we can cache, all fields are ok return true; }
From source file:org.hibernate.search.filter.impl.CachingWrapperQuery.java
License:LGPL
@Override public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { final Weight weight = query.createWeight(searcher, needsScores); if (needsScores) { // our cache is not sufficient, we need scores too return weight; }/*from w w w . ja v a2s. c o m*/ return new ConstantScoreWeight(weight.getQuery()) { @Override public void extractTerms(Set<Term> terms) { weight.extractTerms(terms); } @Override public Scorer scorer(LeafReaderContext context) throws IOException { DocIdSet docIdSet = getDocIdSet(context); assert docIdSet != null; if (docIdSet == DocIdSet.EMPTY) { return null; } final DocIdSetIterator disi = docIdSet.iterator(); if (disi == null) { return null; } return new ConstantScoreScorer(this, 0f, disi); } private DocIdSet getDocIdSet(LeafReaderContext context) throws IOException { final LeafReader reader = context.reader(); final Object key = reader.getCoreCacheKey(); Object cached = cache.get(key); if (cached != null) { return (DocIdSet) cached; } synchronized (cache) { cached = cache.get(key); if (cached != null) { return (DocIdSet) cached; } final DocIdSet docIdSet; final Scorer scorer = weight.scorer(context); if (scorer == null) { docIdSet = DocIdSet.EMPTY; } else { docIdSet = cacheImpl(scorer.iterator(), reader); } cache.put(key, docIdSet); return docIdSet; } } }; }