Disable scoring option in morelikethis

This commit is contained in:
Andrea Cavalli 2021-02-28 16:11:50 +01:00
parent 96a908b833
commit 0ee1193632
4 changed files with 19 additions and 9 deletions

View File

@ -122,12 +122,13 @@ public class LuceneIndex<T, U> implements LLSnapshottable {
U mltDocumentValue, U mltDocumentValue,
@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) {
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, indicizer.getKeyFieldName()) minCompetitiveScore, enableScoring, indicizer.getKeyFieldName())
.map(llSearchResult -> this.transformLuceneResult(llSearchResult, null, LLScoreMode.TOP_SCORES, limit)); .map(llSearchResult -> this.transformLuceneResult(llSearchResult, null, LLScoreMode.TOP_SCORES, limit));
} }
@ -145,12 +146,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,
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, indicizer.getKeyFieldName()) minCompetitiveScore, enableScoring, indicizer.getKeyFieldName())
.map(llSearchResult -> .map(llSearchResult ->
this.transformLuceneResultWithValues(llSearchResult, null, LLScoreMode.TOP_SCORES, limit, valueGetter)); this.transformLuceneResultWithValues(llSearchResult, null, LLScoreMode.TOP_SCORES, limit, valueGetter));
} }

View File

@ -36,6 +36,7 @@ public interface LLLuceneIndex extends 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,
String keyFieldName); String keyFieldName);
/** /**

View File

@ -366,8 +366,9 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
@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,
String keyFieldName) { String keyFieldName) {
return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, limit, minCompetitiveScore, keyFieldName, false, 0, 1); return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, limit, minCompetitiveScore, enableScoring, keyFieldName, false, 0, 1);
} }
public Mono<LLSearchResult> distributedMoreLikeThis(@Nullable LLSnapshot snapshot, public Mono<LLSearchResult> distributedMoreLikeThis(@Nullable LLSnapshot snapshot,
@ -375,18 +376,20 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
@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,
String keyFieldName, String keyFieldName,
long actionId, long actionId,
int scoreDivisor) { int scoreDivisor) {
return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, limit, minCompetitiveScore, keyFieldName, false, actionId, scoreDivisor); return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, limit, minCompetitiveScore, enableScoring, keyFieldName, false, actionId, scoreDivisor);
} }
public Mono<Void> distributedPreMoreLikeThis(@Nullable LLSnapshot snapshot, public Mono<Void> distributedPreMoreLikeThis(@Nullable LLSnapshot snapshot,
Flux<Tuple2<String, Set<String>>> mltDocumentFieldsFlux, Flux<Tuple2<String, Set<String>>> mltDocumentFieldsFlux,
@Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery,
@Nullable Float minCompetitiveScore, @Nullable Float minCompetitiveScore,
boolean enableScoring,
String keyFieldName, long actionId) { String keyFieldName, long actionId) {
return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, -1, minCompetitiveScore, keyFieldName, true, actionId, 1) return moreLikeThis(snapshot, mltDocumentFieldsFlux, additionalQuery, -1, minCompetitiveScore, enableScoring, keyFieldName, true, actionId, 1)
.flatMap(LLSearchResult::completion); .flatMap(LLSearchResult::completion);
} }
@ -396,6 +399,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
@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,
String keyFieldName, String keyFieldName,
boolean doDistributedPre, boolean doDistributedPre,
long actionId, long actionId,
@ -422,7 +426,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
mlt.setMinTermFreq(1); mlt.setMinTermFreq(1);
mlt.setMinDocFreq(3); mlt.setMinDocFreq(3);
mlt.setMaxDocFreqPct(20); mlt.setMaxDocFreqPct(20);
mlt.setBoost(true); mlt.setBoost(enableScoring);
mlt.setStopWords(EnglishItalianStopFilter.getStopWordsString()); mlt.setStopWords(EnglishItalianStopFilter.getStopWordsString());
var similarity = getSimilarity(); var similarity = getSimilarity();
if (similarity instanceof TFIDFSimilarity) { if (similarity instanceof TFIDFSimilarity) {
@ -451,8 +455,8 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
keyFieldName, keyFieldName,
scoreDivisor, scoreDivisor,
luceneQuery, luceneQuery,
new Sort(SortField.FIELD_SCORE), enableScoring ? new Sort(SortField.FIELD_SCORE) : null,
ScoreMode.TOP_SCORES enableScoring ? ScoreMode.TOP_SCORES : ScoreMode.COMPLETE_NO_SCORES
); );
}) })
.subscribeOn(luceneQueryScheduler) .subscribeOn(luceneQueryScheduler)

View File

@ -206,6 +206,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
@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,
String keyFieldName) { String keyFieldName) {
long actionId; long actionId;
int scoreDivisor; int scoreDivisor;
@ -228,6 +229,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
mltDocumentFieldsShared, mltDocumentFieldsShared,
additionalQuery, additionalQuery,
minCompetitiveScore, minCompetitiveScore,
enableScoring,
keyFieldName, keyFieldName,
actionId actionId
) )
@ -253,6 +255,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex {
additionalQuery, additionalQuery,
limit, limit,
minCompetitiveScore, minCompetitiveScore,
enableScoring,
keyFieldName, keyFieldName,
actionId, actionId,
scoreDivisor scoreDivisor