Skip to content
Permalink
Browse files
Fixing OAK-9767 - Only checking if the count is >0 for including a te…
…rm in getFieldTerms
  • Loading branch information
klcodanr committed May 24, 2022
1 parent f702077 commit ecf02615c92fc89197fd936482da266bf0c0f7ba
Showing 8 changed files with 290 additions and 35 deletions.
@@ -523,7 +523,7 @@ public int compareTo(Entry o) {
}
e.count = iterator.docFreq();
totalCount += e.count;
if (e.count > 1) {
if (e.count > 0) {
list.add(e);
}
if (max > 0 && list.size() > 2 * max) {
@@ -17,6 +17,7 @@
package org.apache.jackrabbit.oak.plugins.index.lucene;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -91,7 +92,6 @@ public void testGetFieldTermsInfo_withType() throws IOException {
doc.add(new LongField("long", (long) i, Store.NO));
doc.add(new IntField("int", i, Store.NO));
indexWriter.addDocument(doc);
indexWriter.addDocument(doc);
}
indexWriter.close();
String[] stringValues = luceneIndexMBean.getFieldTermsInfo(INDEX_PATH, "string",
@@ -113,4 +113,46 @@ public void testGetFieldTermsInfo_withType() throws IOException {
assertTermsMatch("LuceneIndexMBeanImplTest-expected-long-field.txt", longValues);
}

@Test
public void testGetUniqueTerm() throws IOException {
String INDEX_PATH = "/oak:index/test-index";
IndexWriter indexWriter = addNodeIndex(INDEX_PATH);
for (int i = 0; i < 100; i++) {
Document doc = new Document();
doc.add(new StringField("unique", "value-" + i, Store.NO));
doc.add(new StringField("notunique", String.valueOf(i / 10), Store.NO));
indexWriter.addDocument(doc);
}
indexWriter.close();
String[] uniqueValues = luceneIndexMBean.getFieldTermsInfo(INDEX_PATH, "unique",
"java.lang.String", 100);
assertTermsMatch("LuceneIndexMBeanImplTest-expected-unique.txt", uniqueValues);

String[] notUniqueValues = luceneIndexMBean.getFieldTermsInfo(INDEX_PATH, "notunique",
"java.lang.String", 100);
assertTermsMatch("LuceneIndexMBeanImplTest-expected-notunique.txt", notUniqueValues);
}

@Test
public void testSortsWithSingleTerms() throws IOException {
String INDEX_PATH = "/oak:index/test-index";
IndexWriter indexWriter = addNodeIndex(INDEX_PATH);
for (int i = 0; i < 100000; i++) {
Document doc = new Document();
if (i % 2 == 0) {
doc.add(new StringField("term", "value-" + i, Store.NO));
} else {
doc.add(new StringField("term", String.valueOf(i / 10), Store.NO));
}

indexWriter.addDocument(doc);
}
indexWriter.close();
String[] topValues = luceneIndexMBean.getFieldTermsInfo(INDEX_PATH, "term",
"java.lang.String", 100);
assertTermsMatch("LuceneIndexMBeanImplTest-expected-top-terms.txt", topValues);
assertEquals(60001, luceneIndexMBean.getFieldTermsInfo(INDEX_PATH, "term",
"java.lang.String", 1000000).length);
}

}
@@ -1,11 +1,11 @@
160 (total for field int)
20 0
20 0
20 0
20 0
20 0
20 0
20 0
2 9
2 8
2 7
80 (total for field int)
10 0
10 0
10 0
10 0
10 0
10 0
10 0
1 9
1 8
1 7
@@ -1,11 +1,11 @@
320 (total for field long)
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
20 0
160 (total for field long)
10 0
10 0
10 0
10 0
10 0
10 0
10 0
10 0
10 0
10 0
@@ -0,0 +1,11 @@
100 (total for field notunique)
10 9
10 8
10 7
10 6
10 5
10 4
10 3
10 2
10 1
10 0
@@ -1,11 +1,11 @@
20 (total for field string)
2 value-9
2 value-8
2 value-7
2 value-6
2 value-5
2 value-4
2 value-3
2 value-2
2 value-1
2 value-0
10 (total for field string)
1 value-9
1 value-8
1 value-7
1 value-6
1 value-5
1 value-4
1 value-3
1 value-2
1 value-1
1 value-0
@@ -0,0 +1,101 @@
100000 (total for field term)
5 9999
5 9998
5 9997
5 9996
5 9995
5 9994
5 9993
5 9992
5 9991
5 9990
5 999
5 9989
5 9988
5 9987
5 9986
5 9985
5 9984
5 9983
5 9982
5 9981
5 9980
5 998
5 9979
5 9978
5 9977
5 9976
5 9975
5 9974
5 9973
5 9972
5 9971
5 9970
5 997
5 9969
5 9968
5 9967
5 9966
5 9965
5 9964
5 9963
5 9962
5 9961
5 9960
5 996
5 9959
5 9958
5 9957
5 9956
5 9955
5 9954
5 9953
5 9952
5 9951
5 9950
5 995
5 9949
5 9948
5 9947
5 9946
5 9945
5 9944
5 9943
5 9942
5 9941
5 9940
5 994
5 9939
5 9938
5 9937
5 9936
5 9935
5 9934
5 9933
5 9932
5 9931
5 9930
5 993
5 9929
5 9928
5 9927
5 9926
5 9925
5 9924
5 9923
5 9922
5 9921
5 9920
5 992
5 9919
5 9918
5 9917
5 9916
5 9915
5 9914
5 9913
5 9912
5 9911
5 9910
5 991
5 9909
@@ -0,0 +1,101 @@
100 (total for field unique)
1 value-99
1 value-98
1 value-97
1 value-96
1 value-95
1 value-94
1 value-93
1 value-92
1 value-91
1 value-90
1 value-9
1 value-89
1 value-88
1 value-87
1 value-86
1 value-85
1 value-84
1 value-83
1 value-82
1 value-81
1 value-80
1 value-8
1 value-79
1 value-78
1 value-77
1 value-76
1 value-75
1 value-74
1 value-73
1 value-72
1 value-71
1 value-70
1 value-7
1 value-69
1 value-68
1 value-67
1 value-66
1 value-65
1 value-64
1 value-63
1 value-62
1 value-61
1 value-60
1 value-6
1 value-59
1 value-58
1 value-57
1 value-56
1 value-55
1 value-54
1 value-53
1 value-52
1 value-51
1 value-50
1 value-5
1 value-49
1 value-48
1 value-47
1 value-46
1 value-45
1 value-44
1 value-43
1 value-42
1 value-41
1 value-40
1 value-4
1 value-39
1 value-38
1 value-37
1 value-36
1 value-35
1 value-34
1 value-33
1 value-32
1 value-31
1 value-30
1 value-3
1 value-29
1 value-28
1 value-27
1 value-26
1 value-25
1 value-24
1 value-23
1 value-22
1 value-21
1 value-20
1 value-2
1 value-19
1 value-18
1 value-17
1 value-16
1 value-15
1 value-14
1 value-13
1 value-12
1 value-11
1 value-10
1 value-1
1 value-0

0 comments on commit ecf0261

Please sign in to comment.