More helpful descriptions of index queries.

This commit is contained in:
Viktor Lofgren 2023-04-02 12:03:58 +02:00
parent 5fb75adaae
commit 1e4157017d
9 changed files with 37 additions and 18 deletions

View File

@ -16,4 +16,10 @@ public class EmptyEntrySource implements EntrySource {
public boolean hasMore() {
return false;
}
@Override
public String indexName() {
return "Empty";
}
}

View File

@ -7,4 +7,6 @@ public interface EntrySource {
void read(LongQueryBuffer buffer);
boolean hasMore();
String indexName();
}

View File

@ -5,6 +5,7 @@ import nu.marginalia.array.buffer.LongQueryBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class IndexQuery {
private final List<EntrySource> sources;
@ -66,14 +67,10 @@ public class IndexQuery {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Sources:\n");
for (var source : sources) {
sb.append(source).append('\n');
}
sb.append("Includes:\n");
for (var include : inclusionFilter) {
sb.append("\t").append(include.describe()).append("\n");
}
sb.append(sources.stream().map(EntrySource::indexName).collect(Collectors.joining(", ", "[", "]")));
sb.append(" -> ");
sb.append(inclusionFilter.stream().map(QueryFilterStepIf::describe).collect(Collectors.joining(", ", "[", "]")));
return sb.toString();
}

View File

@ -14,14 +14,17 @@ public class ReverseIndexFullEntrySource implements EntrySource {
int endOffset;
final int entrySize;
private final int wordId;
private final ReverseIndexEntrySourceBehavior behavior;
public ReverseIndexFullEntrySource(BTreeReader reader,
int entrySize,
ReverseIndexEntrySourceBehavior behavior) {
ReverseIndexEntrySourceBehavior behavior,
int wordId) {
this.reader = reader;
this.behavior = behavior;
this.entrySize = entrySize;
this.wordId = wordId;
pos = 0;
endOffset = pos + entrySize * reader.numEntries();
@ -65,4 +68,9 @@ public class ReverseIndexFullEntrySource implements EntrySource {
return pos < endOffset;
}
@Override
public String indexName() {
return "Priority:" + wordId;
}
}

View File

@ -63,7 +63,7 @@ public class ReverseIndexFullReader {
if (offset < 0) return new EmptyEntrySource();
return new ReverseIndexFullEntrySource(createReaderNew(offset), ReverseIndexFullParameters.ENTRY_SIZE, behavior);
return new ReverseIndexFullEntrySource(createReaderNew(offset), ReverseIndexFullParameters.ENTRY_SIZE, behavior, wordId);
}
public QueryFilterStepIf also(int wordId) {
@ -73,7 +73,7 @@ public class ReverseIndexFullReader {
if (offset < 0) return new QueryFilterNoPass();
return new ReverseIndexRetainFilter(createReaderNew(offset));
return new ReverseIndexRetainFilter(createReaderNew(offset), "full", wordId);
}
public QueryFilterStepIf not(int wordId) {

View File

@ -14,10 +14,12 @@ public class ReverseIndexPriorityEntrySource implements EntrySource {
int endOffset;
private final ReverseIndexEntrySourceBehavior behavior;
private final int wordId;
public ReverseIndexPriorityEntrySource(BTreeReader reader, ReverseIndexEntrySourceBehavior behavior) {
public ReverseIndexPriorityEntrySource(BTreeReader reader, ReverseIndexEntrySourceBehavior behavior, int wordId) {
this.reader = reader;
this.behavior = behavior;
this.wordId = wordId;
pos = 0;
endOffset = pos + reader.numEntries();
@ -49,4 +51,8 @@ public class ReverseIndexPriorityEntrySource implements EntrySource {
return pos < endOffset;
}
@Override
public String indexName() {
return "Priority:" + wordId;
}
}

View File

@ -46,7 +46,7 @@ public class ReverseIndexPriorityReader {
if (offset < 0) return new EmptyEntrySource();
return new ReverseIndexPriorityEntrySource(createReaderNew(offset), ReverseIndexEntrySourceBehavior.DO_PREFER);
return new ReverseIndexPriorityEntrySource(createReaderNew(offset), ReverseIndexEntrySourceBehavior.DO_PREFER, wordId);
}
private BTreeReader createReaderNew(long offset) {
@ -60,7 +60,7 @@ public class ReverseIndexPriorityReader {
if (offset < 0) return new QueryFilterNoPass();
return new ReverseIndexRetainFilter(createReaderNew(offset));
return new ReverseIndexRetainFilter(createReaderNew(offset), "priority", wordId);
}
}

View File

@ -4,7 +4,7 @@ import nu.marginalia.array.buffer.LongQueryBuffer;
import nu.marginalia.btree.BTreeReader;
import nu.marginalia.index.query.filter.QueryFilterStepIf;
public record ReverseIndexRetainFilter(BTreeReader range) implements QueryFilterStepIf {
public record ReverseIndexRetainFilter(BTreeReader range, String name, int wordId) implements QueryFilterStepIf {
@Override
public void apply(LongQueryBuffer buffer) {
@ -23,6 +23,6 @@ public record ReverseIndexRetainFilter(BTreeReader range) implements QueryFilter
@Override
public String describe() {
return "ReverseIndexRetainFilter";
return "Retain:" + name + "/" + wordId;
}
}

View File

@ -33,12 +33,12 @@ public class SearchIndexReader {
public IndexQueryBuilder findPriorityWord(int wordId) {
return new SearchIndexQueryBuilder(reverseIndexFullReader, reverseIndexPriorityReader, new IndexQuery(
List.of(reverseIndexPriorityReader.priorityDocuments(wordId))));
List.of(reverseIndexPriorityReader.priorityDocuments(wordId))), wordId);
}
public IndexQueryBuilder findFullWord(int wordId, ReverseIndexEntrySourceBehavior behavior) {
return new SearchIndexQueryBuilder(reverseIndexFullReader, reverseIndexPriorityReader, new IndexQuery(
List.of(reverseIndexFullReader.documents(wordId, behavior))));
List.of(reverseIndexFullReader.documents(wordId, behavior))), wordId);
}
QueryFilterStepIf filterForParams(IndexQueryParams params) {