|
16 | 16 | */
|
17 | 17 | package org.apache.lucene.sandbox.search;
|
18 | 18 |
|
| 19 | +import static com.carrotsearch.randomizedtesting.RandomizedTest.atMost; |
| 20 | +import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean; |
| 21 | +import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; |
| 22 | + |
19 | 23 | import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
20 | 24 | import java.io.IOException;
|
21 | 25 | import java.util.Arrays;
|
@@ -165,6 +169,80 @@ public void testSameScore() throws IOException {
|
165 | 169 | dir.close();
|
166 | 170 | }
|
167 | 171 |
|
| 172 | + public void testScoringWithMultipleFieldTermsMatch() throws IOException { |
| 173 | + int numMatchDoc = randomIntBetween(100, 500); |
| 174 | + int numHits = atMost(100); |
| 175 | + int boost1 = Math.max(1, random().nextInt(5)); |
| 176 | + int boost2 = Math.max(1, random().nextInt(5)); |
| 177 | + |
| 178 | + Directory dir = newDirectory(); |
| 179 | + Similarity similarity = randomCompatibleSimilarity(); |
| 180 | + |
| 181 | + IndexWriterConfig iwc = new IndexWriterConfig(); |
| 182 | + iwc.setSimilarity(similarity); |
| 183 | + RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc); |
| 184 | + |
| 185 | + // adding potentially matching doc |
| 186 | + for (int i = 0; i < numMatchDoc; i++) { |
| 187 | + Document doc = new Document(); |
| 188 | + |
| 189 | + int freqA = random().nextInt(20) + 1; |
| 190 | + for (int j = 0; j < freqA; j++) { |
| 191 | + doc.add(new TextField("a", "foo", Store.NO)); |
| 192 | + } |
| 193 | + |
| 194 | + freqA = random().nextInt(20) + 1; |
| 195 | + if (randomBoolean()) { |
| 196 | + for (int j = 0; j < freqA; j++) { |
| 197 | + doc.add(new TextField("a", "foo" + j, Store.NO)); |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + freqA = random().nextInt(20) + 1; |
| 202 | + for (int j = 0; j < freqA; j++) { |
| 203 | + doc.add(new TextField("a", "zoo", Store.NO)); |
| 204 | + } |
| 205 | + |
| 206 | + int freqB = random().nextInt(20) + 1; |
| 207 | + for (int j = 0; j < freqB; j++) { |
| 208 | + doc.add(new TextField("b", "zoo", Store.NO)); |
| 209 | + } |
| 210 | + |
| 211 | + freqB = random().nextInt(20) + 1; |
| 212 | + if (randomBoolean()) { |
| 213 | + for (int j = 0; j < freqB; j++) { |
| 214 | + doc.add(new TextField("b", "zoo" + j, Store.NO)); |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + int freqC = random().nextInt(20) + 1; |
| 219 | + for (int j = 0; j < freqC; j++) { |
| 220 | + doc.add(new TextField("c", "bla" + j, Store.NO)); |
| 221 | + } |
| 222 | + w.addDocument(doc); |
| 223 | + } |
| 224 | + |
| 225 | + IndexReader reader = w.getReader(); |
| 226 | + IndexSearcher searcher = newSearcher(reader); |
| 227 | + searcher.setSimilarity(similarity); |
| 228 | + |
| 229 | + CombinedFieldQuery query = |
| 230 | + new CombinedFieldQuery.Builder() |
| 231 | + .addField("a", (float) boost1) |
| 232 | + .addField("b", (float) boost2) |
| 233 | + .addTerm(new BytesRef("foo")) |
| 234 | + .addTerm(new BytesRef("zoo")) |
| 235 | + .build(); |
| 236 | + |
| 237 | + TopScoreDocCollector completeCollector = |
| 238 | + TopScoreDocCollector.create(numHits, null, Integer.MAX_VALUE); |
| 239 | + searcher.search(query, completeCollector); |
| 240 | + |
| 241 | + reader.close(); |
| 242 | + w.close(); |
| 243 | + dir.close(); |
| 244 | + } |
| 245 | + |
168 | 246 | public void testNormsDisabled() throws IOException {
|
169 | 247 | Directory dir = newDirectory();
|
170 | 248 | Similarity similarity = randomCompatibleSimilarity();
|
|
0 commit comments