Sort by score option, bugfixes
This commit is contained in:
parent
0ee1193632
commit
36a0812237
@ -123,12 +123,13 @@ public class LuceneIndex<T, U> implements LLSnapshottable {
|
|||||||
@Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery,
|
@Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery,
|
||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring) {
|
boolean enableScoring,
|
||||||
|
boolean sortByScore) {
|
||||||
Flux<Tuple2<String, Set<String>>> mltDocumentFields
|
Flux<Tuple2<String, Set<String>>> mltDocumentFields
|
||||||
= indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue);
|
= indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue);
|
||||||
return luceneIndex
|
return luceneIndex
|
||||||
.moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit,
|
.moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit,
|
||||||
minCompetitiveScore, enableScoring, indicizer.getKeyFieldName())
|
minCompetitiveScore, enableScoring, sortByScore, indicizer.getKeyFieldName())
|
||||||
.map(llSearchResult -> this.transformLuceneResult(llSearchResult, null, LLScoreMode.TOP_SCORES, limit));
|
.map(llSearchResult -> this.transformLuceneResult(llSearchResult, null, LLScoreMode.TOP_SCORES, limit));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -147,12 +148,13 @@ public class LuceneIndex<T, U> implements LLSnapshottable {
|
|||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
ValueGetter<T, U> valueGetter) {
|
ValueGetter<T, U> valueGetter) {
|
||||||
Flux<Tuple2<String, Set<String>>> mltDocumentFields
|
Flux<Tuple2<String, Set<String>>> mltDocumentFields
|
||||||
= indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue);
|
= indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue);
|
||||||
return luceneIndex
|
return luceneIndex
|
||||||
.moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit,
|
.moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit,
|
||||||
minCompetitiveScore, enableScoring, indicizer.getKeyFieldName())
|
minCompetitiveScore, enableScoring, sortByScore, indicizer.getKeyFieldName())
|
||||||
.map(llSearchResult ->
|
.map(llSearchResult ->
|
||||||
this.transformLuceneResultWithValues(llSearchResult, null, LLScoreMode.TOP_SCORES, limit, valueGetter));
|
this.transformLuceneResultWithValues(llSearchResult, null, LLScoreMode.TOP_SCORES, limit, valueGetter));
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ public interface LLLuceneIndex extends LLSnapshottable {
|
|||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
String keyFieldName);
|
String keyFieldName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,8 +367,20 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
|
|||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
String keyFieldName) {
|
String keyFieldName) {
|
||||||
return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, limit, minCompetitiveScore, enableScoring, keyFieldName, false, 0, 1);
|
return moreLikeThis(snapshot,
|
||||||
|
mltDocumentFieldsFlux,
|
||||||
|
additionalQuery,
|
||||||
|
limit,
|
||||||
|
minCompetitiveScore,
|
||||||
|
enableScoring,
|
||||||
|
sortByScore,
|
||||||
|
keyFieldName,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<LLSearchResult> distributedMoreLikeThis(@Nullable LLSnapshot snapshot,
|
public Mono<LLSearchResult> distributedMoreLikeThis(@Nullable LLSnapshot snapshot,
|
||||||
@ -377,10 +389,22 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
|
|||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
String keyFieldName,
|
String keyFieldName,
|
||||||
long actionId,
|
long actionId,
|
||||||
int scoreDivisor) {
|
int scoreDivisor) {
|
||||||
return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, limit, minCompetitiveScore, enableScoring, keyFieldName, false, actionId, scoreDivisor);
|
return moreLikeThis(snapshot,
|
||||||
|
mltDocumentFieldsFlux,
|
||||||
|
additionalQuery,
|
||||||
|
limit,
|
||||||
|
minCompetitiveScore,
|
||||||
|
enableScoring,
|
||||||
|
sortByScore,
|
||||||
|
keyFieldName,
|
||||||
|
false,
|
||||||
|
actionId,
|
||||||
|
scoreDivisor
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<Void> distributedPreMoreLikeThis(@Nullable LLSnapshot snapshot,
|
public Mono<Void> distributedPreMoreLikeThis(@Nullable LLSnapshot snapshot,
|
||||||
@ -388,8 +412,20 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
|
|||||||
@Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery,
|
@Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
String keyFieldName, long actionId) {
|
String keyFieldName, long actionId) {
|
||||||
return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, -1, minCompetitiveScore, enableScoring, keyFieldName, true, actionId, 1)
|
return moreLikeThis(snapshot,
|
||||||
|
mltDocumentFieldsFlux,
|
||||||
|
additionalQuery,
|
||||||
|
-1,
|
||||||
|
minCompetitiveScore,
|
||||||
|
enableScoring,
|
||||||
|
sortByScore,
|
||||||
|
keyFieldName,
|
||||||
|
true,
|
||||||
|
actionId,
|
||||||
|
1
|
||||||
|
)
|
||||||
.flatMap(LLSearchResult::completion);
|
.flatMap(LLSearchResult::completion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,6 +436,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
|
|||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
String keyFieldName,
|
String keyFieldName,
|
||||||
boolean doDistributedPre,
|
boolean doDistributedPre,
|
||||||
long actionId,
|
long actionId,
|
||||||
@ -455,8 +492,10 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
|
|||||||
keyFieldName,
|
keyFieldName,
|
||||||
scoreDivisor,
|
scoreDivisor,
|
||||||
luceneQuery,
|
luceneQuery,
|
||||||
enableScoring ? new Sort(SortField.FIELD_SCORE) : null,
|
(enableScoring && sortByScore) ? new Sort(SortField.FIELD_SCORE) : null,
|
||||||
enableScoring ? ScoreMode.TOP_SCORES : ScoreMode.COMPLETE_NO_SCORES
|
(enableScoring && minCompetitiveScore != null) ?
|
||||||
|
ScoreMode.TOP_SCORES :
|
||||||
|
(enableScoring ? ScoreMode.COMPLETE : ScoreMode.COMPLETE_NO_SCORES)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.subscribeOn(luceneQueryScheduler)
|
.subscribeOn(luceneQueryScheduler)
|
||||||
|
@ -207,6 +207,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
|
|||||||
long limit,
|
long limit,
|
||||||
@Nullable Float minCompetitiveScore,
|
@Nullable Float minCompetitiveScore,
|
||||||
boolean enableScoring,
|
boolean enableScoring,
|
||||||
|
boolean sortByScore,
|
||||||
String keyFieldName) {
|
String keyFieldName) {
|
||||||
long actionId;
|
long actionId;
|
||||||
int scoreDivisor;
|
int scoreDivisor;
|
||||||
@ -230,6 +231,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
|
|||||||
additionalQuery,
|
additionalQuery,
|
||||||
minCompetitiveScore,
|
minCompetitiveScore,
|
||||||
enableScoring,
|
enableScoring,
|
||||||
|
sortByScore,
|
||||||
keyFieldName,
|
keyFieldName,
|
||||||
actionId
|
actionId
|
||||||
)
|
)
|
||||||
@ -256,6 +258,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
|
|||||||
limit,
|
limit,
|
||||||
minCompetitiveScore,
|
minCompetitiveScore,
|
||||||
enableScoring,
|
enableScoring,
|
||||||
|
sortByScore,
|
||||||
keyFieldName,
|
keyFieldName,
|
||||||
actionId,
|
actionId,
|
||||||
scoreDivisor
|
scoreDivisor
|
||||||
|
@ -59,8 +59,11 @@ public class LuceneParallelStreamCollector implements Collector, LeafCollector {
|
|||||||
doc += base;
|
doc += base;
|
||||||
totalHitsCounter.incrementAndGet();
|
totalHitsCounter.incrementAndGet();
|
||||||
if (!stopped.get()) {
|
if (!stopped.get()) {
|
||||||
if (!streamConsumer.consume(doc, scorer == null ? 0 : scorer.score())) {
|
var score = scorer == null ? 0 : scorer.score();
|
||||||
stopped.set(true);
|
if (minCompetitiveScore == null || score >= minCompetitiveScore) {
|
||||||
|
if (!streamConsumer.consume(doc, score)) {
|
||||||
|
stopped.set(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user