From 0ee11936321f23ffb24f7fc44e6f1407c930d41f Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 28 Feb 2021 16:11:50 +0100 Subject: [PATCH] Disable scoring option in morelikethis --- .../cavallium/dbengine/client/LuceneIndex.java | 8 +++++--- .../dbengine/database/LLLuceneIndex.java | 1 + .../database/disk/LLLocalLuceneIndex.java | 16 ++++++++++------ .../database/disk/LLLocalMultiLuceneIndex.java | 3 +++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java b/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java index dd29b1b..7a8214f 100644 --- a/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/client/LuceneIndex.java @@ -122,12 +122,13 @@ public class LuceneIndex implements LLSnapshottable { U mltDocumentValue, @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, - @Nullable Float minCompetitiveScore) { + @Nullable Float minCompetitiveScore, + boolean enableScoring) { Flux>> mltDocumentFields = indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue); return luceneIndex .moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit, - minCompetitiveScore, indicizer.getKeyFieldName()) + minCompetitiveScore, enableScoring, indicizer.getKeyFieldName()) .map(llSearchResult -> this.transformLuceneResult(llSearchResult, null, LLScoreMode.TOP_SCORES, limit)); } @@ -145,12 +146,13 @@ public class LuceneIndex implements LLSnapshottable { @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, @Nullable Float minCompetitiveScore, + boolean enableScoring, ValueGetter valueGetter) { Flux>> mltDocumentFields = indicizer.getMoreLikeThisDocumentFields(key, mltDocumentValue); return luceneIndex .moreLikeThis(resolveSnapshot(snapshot), mltDocumentFields, additionalQuery, limit, - minCompetitiveScore, indicizer.getKeyFieldName()) + minCompetitiveScore, enableScoring, indicizer.getKeyFieldName()) .map(llSearchResult -> this.transformLuceneResultWithValues(llSearchResult, null, LLScoreMode.TOP_SCORES, limit, valueGetter)); } diff --git a/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java index 2fd20d2..c4a5345 100644 --- a/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/LLLuceneIndex.java @@ -36,6 +36,7 @@ public interface LLLuceneIndex extends LLSnapshottable { @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, @Nullable Float minCompetitiveScore, + boolean enableScoring, String keyFieldName); /** diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java index 0c72358..dcf0444 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java @@ -366,8 +366,9 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, @Nullable Float minCompetitiveScore, + boolean enableScoring, 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 distributedMoreLikeThis(@Nullable LLSnapshot snapshot, @@ -375,18 +376,20 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, @Nullable Float minCompetitiveScore, + boolean enableScoring, String keyFieldName, long actionId, 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 distributedPreMoreLikeThis(@Nullable LLSnapshot snapshot, Flux>> mltDocumentFieldsFlux, @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, @Nullable Float minCompetitiveScore, + boolean enableScoring, 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); } @@ -396,6 +399,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, @Nullable Float minCompetitiveScore, + boolean enableScoring, String keyFieldName, boolean doDistributedPre, long actionId, @@ -422,7 +426,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { mlt.setMinTermFreq(1); mlt.setMinDocFreq(3); mlt.setMaxDocFreqPct(20); - mlt.setBoost(true); + mlt.setBoost(enableScoring); mlt.setStopWords(EnglishItalianStopFilter.getStopWordsString()); var similarity = getSimilarity(); if (similarity instanceof TFIDFSimilarity) { @@ -451,8 +455,8 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { keyFieldName, scoreDivisor, luceneQuery, - new Sort(SortField.FIELD_SCORE), - ScoreMode.TOP_SCORES + enableScoring ? new Sort(SortField.FIELD_SCORE) : null, + enableScoring ? ScoreMode.TOP_SCORES : ScoreMode.COMPLETE_NO_SCORES ); }) .subscribeOn(luceneQueryScheduler) diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java index 691cc5e..d4474e8 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalMultiLuceneIndex.java @@ -206,6 +206,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { @Nullable it.cavallium.dbengine.lucene.serializer.Query additionalQuery, long limit, @Nullable Float minCompetitiveScore, + boolean enableScoring, String keyFieldName) { long actionId; int scoreDivisor; @@ -228,6 +229,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { mltDocumentFieldsShared, additionalQuery, minCompetitiveScore, + enableScoring, keyFieldName, actionId ) @@ -253,6 +255,7 @@ public class LLLocalMultiLuceneIndex implements LLLuceneIndex { additionalQuery, limit, minCompetitiveScore, + enableScoring, keyFieldName, actionId, scoreDivisor