(index) Add origin trace information for index readers

This used to be supported by the system but got lost in refactoring at some point.
This commit is contained in:
Viktor Lofgren 2024-04-06 13:28:14 +02:00
parent 7f7021ce64
commit ef25d60666
4 changed files with 14 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import nu.marginalia.index.query.EntrySource;
import static java.lang.Math.min;
public class ReverseIndexEntrySource implements EntrySource {
private final String name;
private final BTreeReader reader;
int pos;
@ -15,9 +16,11 @@ public class ReverseIndexEntrySource implements EntrySource {
final int entrySize;
private final long wordId;
public ReverseIndexEntrySource(BTreeReader reader,
public ReverseIndexEntrySource(String name,
BTreeReader reader,
int entrySize,
long wordId) {
this.name = name;
this.reader = reader;
this.entrySize = entrySize;
this.wordId = wordId;
@ -60,6 +63,6 @@ public class ReverseIndexEntrySource implements EntrySource {
@Override
public String indexName() {
return "Full:" + Long.toHexString(wordId);
return name + ":" + Long.toHexString(wordId);
}
}

View File

@ -25,8 +25,11 @@ public class ReverseIndexReader {
private final long wordsDataOffset;
private final Logger logger = LoggerFactory.getLogger(getClass());
private final BTreeReader wordsBTreeReader;
private final String name;
public ReverseIndexReader(String name, Path words, Path documents) throws IOException {
this.name = name;
public ReverseIndexReader(Path words, Path documents) throws IOException {
if (!Files.exists(words) || !Files.exists(documents)) {
this.words = null;
this.documents = null;
@ -84,7 +87,7 @@ public class ReverseIndexReader {
if (offset < 0) return new EmptyEntrySource();
return new ReverseIndexEntrySource(createReaderNew(offset), 2, wordId);
return new ReverseIndexEntrySource(name, createReaderNew(offset), 2, wordId);
}
public QueryFilterStepIf also(long wordId) {
@ -92,7 +95,7 @@ public class ReverseIndexReader {
if (offset < 0) return new QueryFilterNoPass();
return new ReverseIndexRetainFilter(createReaderNew(offset), "full", wordId);
return new ReverseIndexRetainFilter(createReaderNew(offset), name, wordId);
}
public QueryFilterStepIf not(long wordId) {

View File

@ -102,7 +102,7 @@ class ReverseIndexReaderTest {
preindex.finalizeIndex(docsFile, wordsFile);
preindex.delete();
return new ReverseIndexReader(wordsFile, docsFile);
return new ReverseIndexReader("test", wordsFile, docsFile);
}
}

View File

@ -41,14 +41,14 @@ public class IndexFactory {
public ReverseIndexReader getReverseIndexReader() throws IOException {
return new ReverseIndexReader(
return new ReverseIndexReader("full",
ReverseIndexFullFileNames.resolve(liveStorage, ReverseIndexFullFileNames.FileIdentifier.WORDS, ReverseIndexFullFileNames.FileVersion.CURRENT),
ReverseIndexFullFileNames.resolve(liveStorage, ReverseIndexFullFileNames.FileIdentifier.DOCS, ReverseIndexFullFileNames.FileVersion.CURRENT)
);
}
public ReverseIndexReader getReverseIndexPrioReader() throws IOException {
return new ReverseIndexReader(
return new ReverseIndexReader("prio",
ReverseIndexPrioFileNames.resolve(liveStorage, ReverseIndexPrioFileNames.FileIdentifier.WORDS, ReverseIndexPrioFileNames.FileVersion.CURRENT),
ReverseIndexPrioFileNames.resolve(liveStorage, ReverseIndexPrioFileNames.FileIdentifier.DOCS, ReverseIndexPrioFileNames.FileVersion.CURRENT)
);