org.apache.lucene.index.DocValues#isCacheable ( )源码实例Demo

下面列出了org.apache.lucene.index.DocValues#isCacheable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lucene-solr   文件: DocValuesFieldExistsQuery.java
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) {
  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      DocIdSetIterator iterator = getDocValuesDocIdSetIterator(field, context.reader());
      if (iterator == null) {
        return null;
      }
      return new ConstantScoreScorer(this, score(), scoreMode, iterator);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
源代码2 项目: lucene-solr   文件: TestLRUQueryCache.java
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, 1) {

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      scorerCreatedCount.incrementAndGet();
      return new ConstantScoreScorer(this, 1, scoreMode, DocIdSetIterator.all(context.reader().maxDoc()));
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
源代码3 项目: lucene-solr   文件: BBoxValueSource.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx,
      strategy.field_minX, strategy.field_minY, strategy.field_maxX, strategy.field_maxY);
}
 
源代码4 项目: lucene-solr   文件: DistanceValueSource.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx, strategy.getFieldNameX(), strategy.getFieldNameY());
}
 
源代码5 项目: lucene-solr   文件: SerializedDVStrategy.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx, fieldName);
}
 
源代码6 项目: lucene-solr   文件: DocValuesTermsQuery.java
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, boost) {

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final SortedSetDocValues values = DocValues.getSortedSet(context.reader(), field);
      final LongBitSet bits = new LongBitSet(values.getValueCount());
      boolean matchesAtLeastOneTerm = false;
      TermIterator iterator = termData.iterator();
      for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
        final long ord = values.lookupTerm(term);
        if (ord >= 0) {
          matchesAtLeastOneTerm = true;
          bits.set(ord);
        }
      }
      if (matchesAtLeastOneTerm == false) {
        return null;
      }
      return new ConstantScoreScorer(this, score(), scoreMode, new TwoPhaseIterator(values) {

        @Override
        public boolean matches() throws IOException {
          for (long ord = values.nextOrd(); ord != SortedSetDocValues.NO_MORE_ORDS; ord = values.nextOrd()) {
            if (bits.get(ord)) {
              return true;
            }
          }
          return false;
        }

        @Override
        public float matchCost() {
          return 3; // lookup in a bitset
        }

      });
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
源代码7 项目: lucene-solr   文件: DoubleValuesSource.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx, field);
}
 
源代码8 项目: lucene-solr   文件: LongValuesSource.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx, field);
}
 
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {

  return new ConstantScoreWeight(this, boost) {

    final Component2D tree = LatLonGeometry.create(polygons);
    final GeoEncodingUtils.PolygonPredicate polygonPredicate = GeoEncodingUtils.createComponentPredicate(tree);

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);
      if (values == null) {
        return null;
      }

      final TwoPhaseIterator iterator = new TwoPhaseIterator(values) {

        @Override
        public boolean matches() throws IOException {
          for (int i = 0, count = values.docValueCount(); i < count; ++i) {
            final long value = values.nextValue();
            final int lat = (int) (value >>> 32);
            final int lon = (int) (value & 0xFFFFFFFF);
            if (polygonPredicate.test(lat, lon)) {
              return true;
            }
          }
          return false;
        }

        @Override
        public float matchCost() {
          return 1000f; // TODO: what should it be?
        }
      };
      return new ConstantScoreScorer(this, boost, scoreMode, iterator);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
源代码10 项目: lucene-solr   文件: LatLonDocValuesDistanceQuery.java
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, boost) {

    private final GeoEncodingUtils.DistancePredicate distancePredicate = GeoEncodingUtils.createDistancePredicate(latitude, longitude, radiusMeters);

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);
      if (values == null) {
        return null;
      }

      final TwoPhaseIterator iterator = new TwoPhaseIterator(values) {

        @Override
        public boolean matches() throws IOException {
          for (int i = 0, count = values.docValueCount(); i < count; ++i) {
            final long value = values.nextValue();
            final int lat = (int) (value >>> 32);
            final int lon = (int) (value & 0xFFFFFFFF);
            if (distancePredicate.test(lat, lon)) {
              return true;
            }
          }
          return false;
        }

        @Override
        public float matchCost() {
          return 100f; // TODO: what should it be?
        }

      };
      return new ConstantScoreScorer(this, boost, scoreMode, iterator);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {

  return new ConstantScoreWeight(this, boost) {

    final Component2D component2D = XYGeometry.create(geometries);

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);
      if (values == null) {
        return null;
      }

      final TwoPhaseIterator iterator = new TwoPhaseIterator(values) {

        @Override
        public boolean matches() throws IOException {
          for (int i = 0, count = values.docValueCount(); i < count; ++i) {
            final long value = values.nextValue();
            final double x = XYEncodingUtils.decode((int) (value >>> 32));
            final double y = XYEncodingUtils.decode((int) (value & 0xFFFFFFFF));
            if (component2D.contains(x, y)) {
              return true;
            }
          }
          return false;
        }

        @Override
        public float matchCost() {
          return 1000f; // TODO: what should it be?
        }
      };
      return new ConstantScoreScorer(this, boost, scoreMode, iterator);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }
  };
}
 
源代码12 项目: lucene-solr   文件: LatLonDocValuesBoxQuery.java
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, boost) {
    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);
      if (values == null) {
        return null;
      }

      final TwoPhaseIterator iterator = new TwoPhaseIterator(values) {
        @Override
        public boolean matches() throws IOException {
          for (int i = 0, count = values.docValueCount(); i < count; ++i) {
            final long value = values.nextValue();
            final int lat = (int) (value >>> 32);
            if (lat < minLatitude || lat > maxLatitude) {
              // not within latitude range
              continue;
            }

            final int lon = (int) (value & 0xFFFFFFFF);
            if (crossesDateline) {
              if (lon > maxLongitude && lon < minLongitude) {
                // not within longitude range
                continue;
              }
            } else {
              if (lon < minLongitude || lon > maxLongitude) {
                // not within longitude range
                continue;
              }
            }

            return true;
          }
          return false;
        }

        @Override
        public float matchCost() {
          return 5; // 5 comparisons
        }
      };
      return new ConstantScoreScorer(this, boost, scoreMode, iterator);
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
源代码13 项目: lucene-solr   文件: DistanceValueSource.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx, strategy.getFieldNameX(), strategy.getFieldNameY());
}
 
源代码14 项目: lucene-solr   文件: BBoxValueSource.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx,
      strategy.field_maxX, strategy.field_maxY, strategy.field_minX, strategy.field_minY);
}
 
源代码15 项目: lucene-solr   文件: TermsQParserPlugin.java
public Weight createWeight(IndexSearcher searcher, final ScoreMode scoreMode, float boost) throws IOException {
  if (! (searcher instanceof SolrIndexSearcher)) {
    log.debug("Falling back to DocValuesTermsQuery because searcher [{}] is not the required SolrIndexSearcher", searcher);
    return super.createWeight(searcher, scoreMode, boost);
  }

  topLevelDocValues = DocValues.getSortedSet(((SolrIndexSearcher)searcher).getSlowAtomicReader(), fieldName);
  topLevelTermOrdinals = new LongBitSet(topLevelDocValues.getValueCount());
  PrefixCodedTerms.TermIterator iterator = getTerms().iterator();

  long lastTermOrdFound = 0;
  for(BytesRef term = iterator.next(); term != null; term = iterator.next()) {
    long currentTermOrd = lookupTerm(topLevelDocValues, term, lastTermOrdFound);
    if (currentTermOrd >= 0L) {
      matchesAtLeastOneTerm = true;
      topLevelTermOrdinals.set(currentTermOrd);
      lastTermOrdFound = currentTermOrd;
    }
  }

  return new ConstantScoreWeight(this, boost) {
    public Scorer scorer(LeafReaderContext context) throws IOException {
      if (! matchesAtLeastOneTerm) {
        return null;
      }
      
      SortedSetDocValues segmentDocValues = context.reader().getSortedSetDocValues(fieldName);
      if (segmentDocValues == null) {
        return null;
      }

      final int docBase = context.docBase;
      return new ConstantScoreScorer(this, this.score(), scoreMode, new TwoPhaseIterator(segmentDocValues) {
        public boolean matches() throws IOException {
          topLevelDocValues.advanceExact(docBase + approximation.docID());
          for(long ord = topLevelDocValues.nextOrd(); ord != -1L; ord = topLevelDocValues.nextOrd()) {
            if (topLevelTermOrdinals.get(ord)) {
              return true;
            }
          }

          return false;
        }

        public float matchCost() {
          return 10.0F;
        }
      });

    }

    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, new String[]{fieldName});
    }
  };
}
 
源代码16 项目: lucene-solr   文件: LatLonPointSpatialField.java
@Override
public boolean isCacheable(LeafReaderContext ctx) {
  return DocValues.isCacheable(ctx, fieldName);
}