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