mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
(valuation) Impose stronger constraints on locality of terms
This commit is contained in:
parent
cfd9a7187f
commit
2dc77a0638
@ -97,12 +97,13 @@ public class IndexResultValuationContext {
|
||||
boolean allSynthetic = !CompiledQueryAggregates.booleanAggregate(wordMetasQuery, WordFlags.Synthetic::isAbsent);
|
||||
int flagsCount = CompiledQueryAggregates.intMaxMinAggregate(wordMetasQuery, wordMeta -> Long.bitCount(wordMeta & flagsFilterMask));
|
||||
int positionsCount = CompiledQueryAggregates.intMaxMinAggregate(wordMetasQuery, wordMeta -> Long.bitCount(WordMetadata.decodePositions(wordMeta)));
|
||||
boolean noneOverlap = wordMetasQuery.root.visit(new PositionOverlapOperator(wordMetasQuery.data)) != 0;
|
||||
|
||||
if (!meetsQueryStrategyRequirements(wordMetasQuery, queryParams.queryStrategy())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (flagsCount == 0 && !allSynthetic && positionsCount == 0)
|
||||
if (flagsCount == 0 && !allSynthetic && (positionsCount == 0 || noneOverlap))
|
||||
return null;
|
||||
|
||||
double score = searchResultValuator.calculateSearchResultValue(
|
||||
@ -165,6 +166,46 @@ public class IndexResultValuationContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class PositionOverlapOperator implements CqExpression.LongVisitor {
|
||||
private final CqDataLong wordMetaData;
|
||||
|
||||
PositionOverlapOperator(CqDataLong wordMetaData) {
|
||||
this.wordMetaData = wordMetaData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onAnd(List<? extends CqExpression> parts) {
|
||||
long positions = ~0;
|
||||
long flags = 0;
|
||||
|
||||
for (var part : parts) {
|
||||
long pv = part.visit(this);
|
||||
if ((pv & WordMetadata.FLAGS_MASK) != 0) {
|
||||
flags |= (pv & WordMetadata.FLAGS_MASK);
|
||||
}
|
||||
else {
|
||||
positions &= pv;
|
||||
}
|
||||
}
|
||||
|
||||
return positions | flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onOr(List<? extends CqExpression> parts) {
|
||||
long ret = 0;
|
||||
|
||||
for (var part : parts) {
|
||||
ret |= part.visit(this);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onLeaf(int idx) {
|
||||
return wordMetaData.get(idx);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user