You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/09/14 03:30:22 UTC
[05/43] lucene-solr:jira/http2: [LUCENE-8343] weight long overflow
fix + test
[LUCENE-8343] weight long overflow fix + test
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e0232f10
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e0232f10
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e0232f10
Branch: refs/heads/jira/http2
Commit: e0232f104509f28126d9ce060663f87508366338
Parents: 2b636e8
Author: Alessandro Benedetti <a....@sease.io>
Authored: Thu Jun 7 18:57:30 2018 +0100
Committer: Alessandro Benedetti <a....@sease.io>
Committed: Thu Jun 7 18:57:30 2018 +0100
----------------------------------------------------------------------
.../analyzing/BlendedInfixSuggester.java | 6 ++--
.../analyzing/BlendedInfixSuggesterTest.java | 32 ++++++++++++++------
2 files changed, 27 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e0232f10/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggester.java
----------------------------------------------------------------------
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggester.java
index dc65f7a..63f432f 100644
--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggester.java
+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggester.java
@@ -227,8 +227,10 @@ public class BlendedInfixSuggester extends AnalyzingInfixSuggester {
if (weight == 0) {
weight = 1;
}
- long scaledCoefficient = (long) (coefficient * 10);
- long score = weight * scaledCoefficient;
+ if (weight < 1 / LINEAR_COEF && weight > -1 / LINEAR_COEF) {
+ weight *= 1 / LINEAR_COEF;
+ }
+ long score = (long) (weight * coefficient);
LookupResult result;
if (doHighlight) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e0232f10/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
----------------------------------------------------------------------
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
index 1e5a5da..296e404 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
@@ -81,6 +81,20 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
assertSuggestionsRanking(payload, suggester);
}
+ /**
+ * Test to validate the suggestions ranking according to the position coefficient,
+ * even if the weight associated to the suggestion is very big, no overflow should happen.
+ */
+ public void testBlendedSort_fieldWeightLongMax_shouldRankSuggestionsByPositionMatchWithNoOverflow() throws IOException {
+ BytesRef payload = new BytesRef("star");
+ Input keys[] = new Input[]{
+ new Input("star wars: episode v - the empire strikes back", Long.MAX_VALUE, payload)
+ };
+ BlendedInfixSuggester suggester = getBlendedInfixSuggester(keys);
+
+ assertSuggestionsRanking(payload, suggester);
+ }
+
private void assertSuggestionsRanking(BytesRef payload, BlendedInfixSuggester suggester) throws IOException {
// we query for star wars and check that the weight
// is smaller when we search for tokens that are far from the beginning
@@ -131,9 +145,9 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
BlendedInfixSuggester suggester = new BlendedInfixSuggester(newFSDirectory(tempDir), a);
suggester.build(new InputArrayIterator(keys));
- assertEquals(10 * w, getInResults(suggester, "top", pl, 1));
- assertEquals(w * (long) (10 * (1 - 0.10 * 2)), getInResults(suggester, "the", pl, 1));
- assertEquals(w * (long) (10 * (1 - 0.10 * 3)), getInResults(suggester, "lake", pl, 1));
+ assertEquals(w, getInResults(suggester, "top", pl, 1));
+ assertEquals((int) (w * (1 - 0.10 * 2)), getInResults(suggester, "the", pl, 1));
+ assertEquals((int) (w * (1 - 0.10 * 3)), getInResults(suggester, "lake", pl, 1));
suggester.close();
@@ -143,9 +157,9 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
BlendedInfixSuggester.BlenderType.POSITION_RECIPROCAL, 1, false);
suggester.build(new InputArrayIterator(keys));
- assertEquals(10 * w, getInResults(suggester, "top", pl, 1));
- assertEquals(w * (long) (10 * 1 / (1 + 2)), getInResults(suggester, "the", pl, 1));
- assertEquals(w * (long) (10 * 1 / (1 + 3)), getInResults(suggester, "lake", pl, 1));
+ assertEquals(w, getInResults(suggester, "top", pl, 1));
+ assertEquals((int) (w * 1 / (1 + 2)), getInResults(suggester, "the", pl, 1));
+ assertEquals((int) (w * 1 / (1 + 3)), getInResults(suggester, "lake", pl, 1));
suggester.close();
// BlenderType.EXPONENTIAL_RECIPROCAL is using 1/(pow(1+p, exponent)) * w where w is weight and p the position of the word
@@ -155,9 +169,9 @@ public class BlendedInfixSuggesterTest extends LuceneTestCase {
suggester.build(new InputArrayIterator(keys));
- assertEquals(10 * w, getInResults(suggester, "top", pl, 1));
- assertEquals(w * (long) (10 * 1 / (Math.pow(1 + 2, 4.0))), getInResults(suggester, "the", pl, 1));
- assertEquals(w * (long) (10 * 1 / (Math.pow(1 + 3, 4.0))), getInResults(suggester, "lake", pl, 1));
+ assertEquals(w, getInResults(suggester, "top", pl, 1));
+ assertEquals((int) (w * 1 / (Math.pow(1 + 2, 4.0))), getInResults(suggester, "the", pl, 1));
+ assertEquals((int) (w * 1 / (Math.pow(1 + 3, 4.0))), getInResults(suggester, "lake", pl, 1));
suggester.close();
}