|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.index.codec.vectors.es818; |
| 11 | + |
| 12 | +import org.apache.lucene.codecs.hnsw.FlatVectorsReader; |
| 13 | +import org.apache.lucene.index.ByteVectorValues; |
| 14 | +import org.apache.lucene.index.FloatVectorValues; |
| 15 | +import org.apache.lucene.search.KnnCollector; |
| 16 | +import org.apache.lucene.util.Accountable; |
| 17 | +import org.apache.lucene.util.Bits; |
| 18 | +import org.apache.lucene.util.hnsw.RandomVectorScorer; |
| 19 | +import org.elasticsearch.core.IOUtils; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | +import java.util.Collection; |
| 23 | + |
| 24 | +class MergeReaderWrapper extends FlatVectorsReader { |
| 25 | + |
| 26 | + private final FlatVectorsReader mainReader; |
| 27 | + private final FlatVectorsReader mergeReader; |
| 28 | + |
| 29 | + protected MergeReaderWrapper(FlatVectorsReader mainReader, FlatVectorsReader mergeReader) { |
| 30 | + super(mainReader.getFlatVectorScorer()); |
| 31 | + this.mainReader = mainReader; |
| 32 | + this.mergeReader = mergeReader; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public RandomVectorScorer getRandomVectorScorer(String field, float[] target) throws IOException { |
| 37 | + return mainReader.getRandomVectorScorer(field, target); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public RandomVectorScorer getRandomVectorScorer(String field, byte[] target) throws IOException { |
| 42 | + return mainReader.getRandomVectorScorer(field, target); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void checkIntegrity() throws IOException { |
| 47 | + mainReader.checkIntegrity(); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public FloatVectorValues getFloatVectorValues(String field) throws IOException { |
| 52 | + return mainReader.getFloatVectorValues(field); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public ByteVectorValues getByteVectorValues(String field) throws IOException { |
| 57 | + return mainReader.getByteVectorValues(field); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public FlatVectorsReader getMergeInstance() { |
| 62 | + return mergeReader; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public long ramBytesUsed() { |
| 67 | + return mainReader.ramBytesUsed(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public Collection<Accountable> getChildResources() { |
| 72 | + return mainReader.getChildResources(); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public void search(String field, float[] target, KnnCollector knnCollector, Bits acceptDocs) throws IOException { |
| 77 | + mainReader.search(field, target, knnCollector, acceptDocs); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public void search(String field, byte[] target, KnnCollector knnCollector, Bits acceptDocs) throws IOException { |
| 82 | + mainReader.search(field, target, knnCollector, acceptDocs); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public void close() throws IOException { |
| 87 | + IOUtils.close(mainReader, mergeReader); |
| 88 | + } |
| 89 | +} |
0 commit comments