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

项目:elasticsearch_my    文件:DocValuesSliceQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    return new RandomAccessWeight(this) {
        @Override
        protected Bits getMatchingDocs(final LeafReaderContext context) throws IOException {
            final SortedNumericDocValues values = DocValues.getSortedNumeric(context.reader(), getField());
            return new Bits() {
                @Override
                public boolean get(int doc) {
                    values.setDocument(doc);
                    for (int i = 0; i < values.count(); i++) {
                        return contains(BitMixer.mix(values.valueAt(i)));
                    }
                    return contains(0);
                }

                @Override
                public int length() {
                    return context.reader().maxDoc();
                }
            };
        }
    };
}
项目:Elasticsearch    文件:InMemoryGeoBoundingBoxQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    return new RandomAccessWeight(this) {
        @Override
        protected Bits getMatchingDocs(LeafReaderContext context) throws IOException {
            final int maxDoc = context.reader().maxDoc();
            final MultiGeoPointValues values = indexFieldData.load(context).getGeoPointValues();
            // checks to see if bounding box crosses 180 degrees
            if (topLeft.lon() > bottomRight.lon()) {
                return new Meridian180GeoBoundingBoxBits(maxDoc, values, topLeft, bottomRight);
            } else {
                return new GeoBoundingBoxBits(maxDoc, values, topLeft, bottomRight);
            }
        }
    };
}
项目:clue    文件:MatchSomeDocsQuery.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) {
  return new RandomAccessWeight(this) {
    @Override
    protected Bits getMatchingDocs(LeafReaderContext context) throws IOException {
      final int maxDoc = context.reader().maxDoc();
      return new Bits() {

        @Override
        public boolean get(int index) {
          return match(index);
        }

        @Override
        public int length() {
          return maxDoc;
        }          
      };
    }   
  };
}
项目:elasticsearch_my    文件:ScriptQueryBuilder.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    return new RandomAccessWeight(this) {
        @Override
        protected Bits getMatchingDocs(final LeafReaderContext context) throws IOException {
            final LeafSearchScript leafScript = searchScript.getLeafSearchScript(context);
            return new Bits() {

                @Override
                public boolean get(int doc) {
                    leafScript.setDocument(doc);
                    Object val = leafScript.run();
                    if (val == null) {
                        return false;
                    }
                    if (val instanceof Boolean) {
                        return (Boolean) val;
                    }
                    if (val instanceof Number) {
                        return ((Number) val).longValue() != 0;
                    }
                    throw new IllegalArgumentException("Can't handle type [" + val + "] in script filter");
                }

                @Override
                public int length() {
                    return context.reader().maxDoc();
                }

            };
        }
    };
}
项目:Elasticsearch    文件:ScriptQueryParser.java   
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    return new RandomAccessWeight(this) {
        @Override
        protected Bits getMatchingDocs(final LeafReaderContext context) throws IOException {
            final LeafSearchScript leafScript = searchScript.getLeafSearchScript(context);
            return new Bits() {

                @Override
                public boolean get(int doc) {
                    leafScript.setDocument(doc);
                    Object val = leafScript.run();
                    if (val == null) {
                        return false;
                    }
                    if (val instanceof Boolean) {
                        return (Boolean) val;
                    }
                    if (val instanceof Number) {
                        return ((Number) val).longValue() != 0;
                    }
                    throw new IllegalArgumentException("Can't handle type [" + val + "] in script filter");
                }

                @Override
                public int length() {
                    return context.reader().maxDoc();
                }

            };
        }
    };
}