Guest User

Untitled

a guest
Aug 12th, 2012
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.54 KB | None | 0 0
  1. Index: lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java
  2. ===================================================================
  3. --- lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java (revision 1372047)
  4. +++ lucene/test-framework/src/java/org/apache/lucene/codecs/ramonly/RAMOnlyPostingsFormat.java (working copy)
  5. @@ -524,13 +524,12 @@
  6. }
  7.  
  8. @Override
  9. - public boolean hasPayload() {
  10. - return current.payloads != null && current.payloads[posUpto-1] != null;
  11. - }
  12. -
  13. - @Override
  14. public BytesRef getPayload() {
  15. - return new BytesRef(current.payloads[posUpto-1]);
  16. + if (current.payloads != null && current.payloads[posUpto-1] != null) {
  17. + return new BytesRef(current.payloads[posUpto-1]);
  18. + } else {
  19. + return null;
  20. + }
  21. }
  22. }
  23.  
  24. Index: lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java
  25. ===================================================================
  26. --- lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java (revision 1372047)
  27. +++ lucene/test-framework/src/java/org/apache/lucene/index/AssertingAtomicReader.java (working copy)
  28. @@ -365,16 +365,10 @@
  29. assert state != DocsEnumState.START : "getPayload() called before nextDoc()/advance()";
  30. assert state != DocsEnumState.FINISHED : "getPayload() called after NO_MORE_DOCS";
  31. assert positionCount > 0 : "getPayload() called before nextPosition()!";
  32. - return super.getPayload();
  33. + BytesRef payload = super.getPayload();
  34. + assert payload == null || payload.length > 0 : "getPayload() returned payload with invalid length!";
  35. + return payload;
  36. }
  37. -
  38. - @Override
  39. - public boolean hasPayload() {
  40. - assert state != DocsEnumState.START : "hasPayload() called before nextDoc()/advance()";
  41. - assert state != DocsEnumState.FINISHED : "hasPayload() called after NO_MORE_DOCS";
  42. - assert positionCount > 0 : "hasPayload() called before nextPosition()!";
  43. - return super.hasPayload();
  44. - }
  45. }
  46.  
  47. // this is the same hack as FCInvisible
  48. Index: lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java
  49. ===================================================================
  50. --- lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java (revision 1372047)
  51. +++ lucene/facet/src/java/org/apache/lucene/facet/search/PayloadIterator.java (working copy)
  52. @@ -100,15 +100,13 @@
  53. tp.nextPosition();
  54.  
  55. // TODO: fix bug in SepCodec and then remove this check (the null check should be enough)
  56. - if (!tp.hasPayload()) {
  57. - return false;
  58. - }
  59. -
  60. BytesRef br = tp.getPayload();
  61. -
  62. - if (br == null || br.length == 0) {
  63. +
  64. + if (br == null) {
  65. return false;
  66. }
  67. +
  68. + assert br.length > 0;
  69.  
  70. this.payloadLength = br.length;
  71.  
  72. Index: lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java
  73. ===================================================================
  74. --- lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java (revision 1372049)
  75. +++ lucene/core/src/test/org/apache/lucene/search/spans/MultiSpansWrapper.java (working copy)
  76. @@ -160,7 +160,7 @@
  77. }
  78.  
  79. @Override
  80. - public boolean isPayloadAvailable() {
  81. + public boolean isPayloadAvailable() throws IOException {
  82. if (current == null) {
  83. return false;
  84. }
  85. Index: lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java
  86. ===================================================================
  87. --- lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java (revision 1372047)
  88. +++ lucene/core/src/test/org/apache/lucene/index/TestPostingsFormat.java (working copy)
  89. @@ -731,20 +731,21 @@
  90. System.out.println(" now check payload length=" + (position.payload == null ? 0 : position.payload.length));
  91. }
  92. if (position.payload == null || position.payload.length == 0) {
  93. - assertFalse("should not have payload", docsAndPositionsEnum.hasPayload());
  94. + assertNull("should not have payload", docsAndPositionsEnum.getPayload());
  95. } else {
  96. - assertTrue("should have payload but doesn't", docsAndPositionsEnum.hasPayload());
  97. -
  98. BytesRef payload = docsAndPositionsEnum.getPayload();
  99. - assertFalse("2nd call to hasPayload should be false", docsAndPositionsEnum.hasPayload());
  100. + assertNotNull("should have payload but doesn't", payload);
  101.  
  102. - assertNotNull("payload should not be null", payload);
  103. assertEquals("payload length is wrong", position.payload.length, payload.length);
  104. for(int byteUpto=0;byteUpto<position.payload.length;byteUpto++) {
  105. assertEquals("payload bytes are wrong",
  106. position.payload[byteUpto],
  107. payload.bytes[payload.offset+byteUpto]);
  108. }
  109. +
  110. + // make a deep copy
  111. + payload = BytesRef.deepCopyOf(payload);
  112. + assertEquals("2nd call to getPayload returns something different!", payload, docsAndPositionsEnum.getPayload());
  113. }
  114. } else {
  115. if (VERBOSE) {
  116. Index: lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
  117. ===================================================================
  118. --- lucene/core/src/test/org/apache/lucene/index/TestCodecs.java (revision 1372047)
  119. +++ lucene/core/src/test/org/apache/lucene/index/TestCodecs.java (working copy)
  120. @@ -436,14 +436,14 @@
  121. final int pos = posEnum.nextPosition();
  122. assertEquals(positions[i].pos, pos);
  123. if (positions[i].payload != null) {
  124. - assertTrue(posEnum.hasPayload());
  125. + assertNotNull(posEnum.getPayload());
  126. if (random().nextInt(3) < 2) {
  127. // Verify the payload bytes
  128. final BytesRef otherPayload = posEnum.getPayload();
  129. assertTrue("expected=" + positions[i].payload.toString() + " got=" + otherPayload.toString(), positions[i].payload.equals(otherPayload));
  130. }
  131. } else {
  132. - assertFalse(posEnum.hasPayload());
  133. + assertNull(posEnum.getPayload());
  134. }
  135. }
  136. }
  137. Index: lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java
  138. ===================================================================
  139. --- lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java (revision 1372047)
  140. +++ lucene/core/src/test/org/apache/lucene/index/TestLongPostings.java (working copy)
  141. @@ -205,8 +205,11 @@
  142. assertTrue(freq >=1 && freq <= 4);
  143. for(int pos=0;pos<freq;pos++) {
  144. assertEquals(pos, postings.nextPosition());
  145. - if (random().nextBoolean() && postings.hasPayload()) {
  146. + if (random().nextBoolean()) {
  147. postings.getPayload();
  148. + if (random().nextBoolean()) {
  149. + postings.getPayload(); // get it again
  150. + }
  151. }
  152. }
  153. }
  154. @@ -247,8 +250,11 @@
  155. assertTrue(freq >=1 && freq <= 4);
  156. for(int pos=0;pos<freq;pos++) {
  157. assertEquals(pos, postings.nextPosition());
  158. - if (random().nextBoolean() && postings.hasPayload()) {
  159. + if (random().nextBoolean()) {
  160. postings.getPayload();
  161. + if (random().nextBoolean()) {
  162. + postings.getPayload(); // get it again
  163. + }
  164. }
  165. }
  166. }
  167. Index: lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java
  168. ===================================================================
  169. --- lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java (revision 1372047)
  170. +++ lucene/core/src/test/org/apache/lucene/index/TestDocumentWriter.java (working copy)
  171. @@ -205,11 +205,11 @@
  172. int freq = termPositions.freq();
  173. assertEquals(3, freq);
  174. assertEquals(0, termPositions.nextPosition());
  175. - assertEquals(true, termPositions.hasPayload());
  176. + assertNotNull(termPositions.getPayload());
  177. assertEquals(6, termPositions.nextPosition());
  178. - assertEquals(false, termPositions.hasPayload());
  179. + assertNull(termPositions.getPayload());
  180. assertEquals(7, termPositions.nextPosition());
  181. - assertEquals(false, termPositions.hasPayload());
  182. + assertNull(termPositions.getPayload());
  183. reader.close();
  184. }
  185.  
  186. Index: lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java
  187. ===================================================================
  188. --- lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java (revision 1372047)
  189. +++ lucene/core/src/test/org/apache/lucene/index/TestPayloadsOnVectors.java (working copy)
  190. @@ -74,7 +74,6 @@
  191. DocsAndPositionsEnum de = termsEnum.docsAndPositions(null, null);
  192. assertEquals(0, de.nextDoc());
  193. assertEquals(0, de.nextPosition());
  194. - assertTrue(de.hasPayload());
  195. assertEquals(new BytesRef("test"), de.getPayload());
  196. writer.close();
  197. reader.close();
  198. @@ -117,7 +116,6 @@
  199. DocsAndPositionsEnum de = termsEnum.docsAndPositions(null, null);
  200. assertEquals(0, de.nextDoc());
  201. assertEquals(3, de.nextPosition());
  202. - assertTrue(de.hasPayload());
  203. assertEquals(new BytesRef("test"), de.getPayload());
  204. writer.close();
  205. reader.close();
  206. Index: lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java
  207. ===================================================================
  208. --- lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java (revision 1372047)
  209. +++ lucene/core/src/test/org/apache/lucene/index/TestPostingsOffsets.java (working copy)
  210. @@ -170,7 +170,7 @@
  211. assertTrue(storedNumbers.substring(start, end).equals(term));
  212. if (withPayloads) {
  213. // check that we have a payload and it starts with "pos"
  214. - assertTrue(dp.hasPayload());
  215. + assertNotNull(dp.getPayload());
  216. BytesRef payload = dp.getPayload();
  217. assertTrue(payload.utf8ToString().startsWith("pos:"));
  218. } // note: withPayloads=false doesnt necessarily mean we dont have them from MockAnalyzer!
  219. @@ -198,7 +198,7 @@
  220. assertTrue(storedNumbers.substring(start, end).equals("hundred"));
  221. if (withPayloads) {
  222. // check that we have a payload and it starts with "pos"
  223. - assertTrue(dp.hasPayload());
  224. + assertNotNull(dp.getPayload());
  225. BytesRef payload = dp.getPayload();
  226. assertTrue(payload.utf8ToString().startsWith("pos:"));
  227. } // note: withPayloads=false doesnt necessarily mean we dont have them from MockAnalyzer!
  228. Index: lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java
  229. ===================================================================
  230. --- lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java (revision 1372047)
  231. +++ lucene/core/src/test/org/apache/lucene/index/TestPayloadProcessorProvider.java (working copy)
  232. @@ -173,8 +173,8 @@
  233. DocsAndPositionsEnum tpe = MultiFields.getTermPositionsEnum(reader, null, field, text);
  234. while (tpe.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
  235. tpe.nextPosition();
  236. - if (tpe.hasPayload()) {
  237. - BytesRef payload = tpe.getPayload();
  238. + BytesRef payload = tpe.getPayload();
  239. + if (payload != null) {
  240. assertEquals(1, payload.length);
  241. assertEquals(1, payload.bytes[0]);
  242. ++numPayloads;
  243. Index: lucene/core/src/test/org/apache/lucene/index/TestPayloads.java
  244. ===================================================================
  245. --- lucene/core/src/test/org/apache/lucene/index/TestPayloads.java (revision 1372047)
  246. +++ lucene/core/src/test/org/apache/lucene/index/TestPayloads.java (working copy)
  247. @@ -201,18 +201,10 @@
  248. for (int i = 0; i < freq; i++) {
  249. for (int j = 0; j < numTerms; j++) {
  250. tps[j].nextPosition();
  251. - if (tps[j].hasPayload()) {
  252. - BytesRef br = tps[j].getPayload();
  253. + BytesRef br = tps[j].getPayload();
  254. + if (br != null) {
  255. System.arraycopy(br.bytes, br.offset, verifyPayloadData, offset, br.length);
  256. offset += br.length;
  257. - // Just to ensure all codecs can
  258. - // handle a caller that mucks with the
  259. - // returned payload:
  260. - if (rarely()) {
  261. - br.bytes = new byte[random().nextInt(5)];
  262. - }
  263. - br.length = 0;
  264. - br.offset = 0;
  265. }
  266. }
  267. }
  268. @@ -268,11 +260,6 @@
  269. tp.nextPosition();
  270. assertEquals("Wrong payload length.", 3 * skipInterval - 2 * numDocs - 1, tp.getPayload().length);
  271.  
  272. - /*
  273. - * Test multiple call of getPayload()
  274. - */
  275. - assertFalse(tp.hasPayload());
  276. -
  277. reader.close();
  278.  
  279. // test long payload
  280. @@ -619,7 +606,6 @@
  281. DocsAndPositionsEnum de = sr.termPositionsEnum(null, "field", new BytesRef("withPayload"));
  282. de.nextDoc();
  283. de.nextPosition();
  284. - assertTrue(de.hasPayload());
  285. assertEquals(new BytesRef("test"), de.getPayload());
  286. writer.close();
  287. reader.close();
  288. @@ -654,7 +640,6 @@
  289. DocsAndPositionsEnum de = sr.termPositionsEnum(null, "field", new BytesRef("withPayload"));
  290. de.nextDoc();
  291. de.nextPosition();
  292. - assertTrue(de.hasPayload());
  293. assertEquals(new BytesRef("test"), de.getPayload());
  294. writer.close();
  295. reader.close();
  296. Index: lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java
  297. ===================================================================
  298. --- lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java (revision 1372047)
  299. +++ lucene/core/src/test/org/apache/lucene/index/TestDuelingCodecs.java (working copy)
  300. @@ -412,12 +412,9 @@
  301. assertEquals(info, freq, rightDocs.freq());
  302. for (int i = 0; i < freq; i++) {
  303. assertEquals(info, leftDocs.nextPosition(), rightDocs.nextPosition());
  304. - assertEquals(info, leftDocs.hasPayload(), rightDocs.hasPayload());
  305. + assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
  306. assertEquals(info, leftDocs.startOffset(), rightDocs.startOffset());
  307. assertEquals(info, leftDocs.endOffset(), rightDocs.endOffset());
  308. - if (leftDocs.hasPayload()) {
  309. - assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
  310. - }
  311. }
  312. }
  313. assertEquals(info, DocIdSetIterator.NO_MORE_DOCS, rightDocs.nextDoc());
  314. @@ -509,10 +506,7 @@
  315. assertEquals(info, freq, rightDocs.freq());
  316. for (int i = 0; i < freq; i++) {
  317. assertEquals(info, leftDocs.nextPosition(), rightDocs.nextPosition());
  318. - assertEquals(info, leftDocs.hasPayload(), rightDocs.hasPayload());
  319. - if (leftDocs.hasPayload()) {
  320. - assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
  321. - }
  322. + assertEquals(info, leftDocs.getPayload(), rightDocs.getPayload());
  323. }
  324. }
  325. }
  326. Index: lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java
  327. ===================================================================
  328. --- lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java (revision 1372047)
  329. +++ lucene/core/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java (working copy)
  330. @@ -446,7 +446,6 @@
  331. private int numDocs;
  332. private int posPending;
  333. private int payloadLength;
  334. - private boolean payloadRetrieved;
  335. final boolean storeOffsets;
  336. int offsetLength;
  337. int startOffset;
  338. @@ -484,7 +483,6 @@
  339. payloadLength = 0;
  340. this.numDocs = numDocs;
  341. posPending = 0;
  342. - payloadRetrieved = false;
  343. startOffset = storeOffsets ? 0 : -1; // always return -1 if no offsets are stored
  344. offsetLength = 0;
  345. return this;
  346. @@ -577,10 +575,6 @@
  347. payload.offset = in.getPosition();
  348. in.skipBytes(payloadLength);
  349. payload.length = payloadLength;
  350. - // Necessary, in case caller changed the
  351. - // payload.bytes from prior call:
  352. - payload.bytes = buffer;
  353. - payloadRetrieved = false;
  354. }
  355.  
  356. //System.out.println(" pos=" + pos + " payload=" + payload + " fp=" + in.getPosition());
  357. @@ -599,16 +593,10 @@
  358.  
  359. @Override
  360. public BytesRef getPayload() {
  361. - payloadRetrieved = true;
  362. - return payload;
  363. + return payload.length > 0 ? payload : null;
  364. }
  365.  
  366. @Override
  367. - public boolean hasPayload() {
  368. - return !payloadRetrieved && payload.length > 0;
  369. - }
  370. -
  371. - @Override
  372. public int docID() {
  373. return docID;
  374. }
  375. Index: lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java
  376. ===================================================================
  377. --- lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java (revision 1372047)
  378. +++ lucene/core/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java (working copy)
  379. @@ -348,9 +348,8 @@
  380. scratch.add(docsAndPositionsEnum.endOffset());
  381. }
  382. if (hasPayloads) {
  383. - final BytesRef payload;
  384. - if (docsAndPositionsEnum.hasPayload()) {
  385. - payload = docsAndPositionsEnum.getPayload();
  386. + final BytesRef payload = docsAndPositionsEnum.getPayload();
  387. + if (payload != null) {
  388. scratch.add(payload.length);
  389. ros.writeBytes(payload.bytes, payload.offset, payload.length);
  390. } else {
  391. @@ -421,9 +420,8 @@
  392. for(int pos=0;pos<freq;pos++) {
  393. positions[upto][posUpto] = docsAndPositionsEnum.nextPosition();
  394. if (hasPayloads) {
  395. - if (docsAndPositionsEnum.hasPayload()) {
  396. - BytesRef payload = docsAndPositionsEnum.getPayload();
  397. - assert payload != null;
  398. + BytesRef payload = docsAndPositionsEnum.getPayload();
  399. + if (payload != null) {
  400. byte[] payloadBytes = new byte[payload.length];
  401. System.arraycopy(payload.bytes, payload.offset, payloadBytes, 0, payload.length);
  402. payloads[upto][pos] = payloadBytes;
  403. @@ -1807,17 +1805,11 @@
  404. }
  405.  
  406. @Override
  407. - public boolean hasPayload() {
  408. - return payloadLength > 0;
  409. - }
  410. -
  411. - @Override
  412. public BytesRef getPayload() {
  413. if (payloadLength > 0) {
  414. payload.bytes = payloadBytes;
  415. payload.offset = lastPayloadOffset;
  416. payload.length = payloadLength;
  417. - payloadLength = 0;
  418. return payload;
  419. } else {
  420. return null;
  421. @@ -2010,7 +2002,6 @@
  422. private int upto;
  423. private int docID = -1;
  424. private int posUpto;
  425. - private boolean gotPayload;
  426. private int[] curPositions;
  427.  
  428. public HighFreqDocsAndPositionsEnum(Bits liveDocs, boolean hasOffsets) {
  429. @@ -2080,7 +2071,6 @@
  430. @Override
  431. public int nextPosition() {
  432. posUpto += posJump;
  433. - gotPayload = false;
  434. return curPositions[posUpto];
  435. }
  436.  
  437. @@ -2214,21 +2204,22 @@
  438. }
  439. }
  440.  
  441. - @Override
  442. - public boolean hasPayload() {
  443. - return !gotPayload && payloads != null && payloads[upto][posUpto/(hasOffsets ? 3 : 1)] != null;
  444. - }
  445. -
  446. private final BytesRef payload = new BytesRef();
  447.  
  448. @Override
  449. public BytesRef getPayload() {
  450. - final byte[] payloadBytes = payloads[upto][posUpto/(hasOffsets ? 3:1)];
  451. - payload.bytes = payloadBytes;
  452. - payload.length = payloadBytes.length;
  453. - payload.offset = 0;
  454. - gotPayload = true;
  455. - return payload;
  456. + if (payloads == null) {
  457. + return null;
  458. + } else {
  459. + final byte[] payloadBytes = payloads[upto][posUpto/(hasOffsets ? 3:1)];
  460. + if (payloadBytes == null) {
  461. + return null;
  462. + }
  463. + payload.bytes = payloadBytes;
  464. + payload.length = payloadBytes.length;
  465. + payload.offset = 0;
  466. + return payload;
  467. + }
  468. }
  469. }
  470. }
  471. Index: lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java
  472. ===================================================================
  473. --- lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java (revision 1372047)
  474. +++ lucene/core/src/java/org/apache/lucene/codecs/PostingsConsumer.java (working copy)
  475. @@ -112,12 +112,7 @@
  476. totTF += freq;
  477. for(int i=0;i<freq;i++) {
  478. final int position = postingsEnum.nextPosition();
  479. - final BytesRef payload;
  480. - if (postingsEnum.hasPayload()) {
  481. - payload = postingsEnum.getPayload();
  482. - } else {
  483. - payload = null;
  484. - }
  485. + final BytesRef payload = postingsEnum.getPayload();
  486. this.addPosition(position, payload, -1, -1);
  487. }
  488. this.finishDoc();
  489. @@ -137,12 +132,7 @@
  490. totTF += freq;
  491. for(int i=0;i<freq;i++) {
  492. final int position = postingsEnum.nextPosition();
  493. - final BytesRef payload;
  494. - if (postingsEnum.hasPayload()) {
  495. - payload = postingsEnum.getPayload();
  496. - } else {
  497. - payload = null;
  498. - }
  499. + final BytesRef payload = postingsEnum.getPayload();
  500. this.addPosition(position, payload, postingsEnum.startOffset(), postingsEnum.endOffset());
  501. }
  502. this.finishDoc();
  503. Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java
  504. ===================================================================
  505. --- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java (revision 1372047)
  506. +++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java (working copy)
  507. @@ -671,7 +671,6 @@
  508.  
  509. @Override
  510. public BytesRef getPayload() {
  511. - // TODO: dumb that we have to duplicate hasPayload
  512. if (payloadOffsets == null) {
  513. return null;
  514. } else {
  515. @@ -688,17 +687,6 @@
  516. }
  517.  
  518. @Override
  519. - public boolean hasPayload() {
  520. - if (payloadOffsets == null) {
  521. - return false;
  522. - } else {
  523. - int off = payloadOffsets[nextPos-1];
  524. - int end = nextPos == payloadOffsets.length ? payloadBytes.length : payloadOffsets[nextPos];
  525. - return end - off > 0;
  526. - }
  527. - }
  528. -
  529. - @Override
  530. public int nextPosition() {
  531. assert (positions != null && nextPos < positions.length) ||
  532. startOffsets != null && nextPos < startOffsets.length;
  533. Index: lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java
  534. ===================================================================
  535. --- lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java (revision 1372047)
  536. +++ lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsReader.java (working copy)
  537. @@ -873,13 +873,8 @@
  538. * payload was indexed. */
  539. @Override
  540. public BytesRef getPayload() throws IOException {
  541. - throw new IOException("No payloads exist for this field!");
  542. + return null;
  543. }
  544. -
  545. - @Override
  546. - public boolean hasPayload() {
  547. - return false;
  548. - }
  549. }
  550.  
  551. // Decodes docs & positions & (payloads and/or offsets)
  552. @@ -1152,28 +1147,26 @@
  553. @Override
  554. public BytesRef getPayload() throws IOException {
  555. if (storePayloads) {
  556. + if (payloadLength <= 0) {
  557. + return null;
  558. + }
  559. assert lazyProxPointer == -1;
  560. assert posPendingCount < freq;
  561. - if (!payloadPending) {
  562. - throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
  563. +
  564. + if (payloadPending) {
  565. + if (payloadLength > payload.bytes.length) {
  566. + payload.grow(payloadLength);
  567. + }
  568. +
  569. + proxIn.readBytes(payload.bytes, 0, payloadLength);
  570. + payload.length = payloadLength;
  571. + payloadPending = false;
  572. }
  573. - if (payloadLength > payload.bytes.length) {
  574. - payload.grow(payloadLength);
  575. - }
  576.  
  577. - proxIn.readBytes(payload.bytes, 0, payloadLength);
  578. - payload.length = payloadLength;
  579. - payloadPending = false;
  580. -
  581. return payload;
  582. } else {
  583. - throw new IOException("No payloads exist for this field!");
  584. + return null;
  585. }
  586. }
  587. -
  588. - @Override
  589. - public boolean hasPayload() {
  590. - return payloadPending && payloadLength > 0;
  591. - }
  592. }
  593. }
  594. Index: lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java
  595. ===================================================================
  596. --- lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java (revision 1372047)
  597. +++ lucene/core/src/java/org/apache/lucene/codecs/sep/SepPostingsReader.java (working copy)
  598. @@ -714,8 +714,12 @@
  599. @Override
  600. public BytesRef getPayload() throws IOException {
  601. if (!payloadPending) {
  602. - throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
  603. + return null;
  604. }
  605. +
  606. + if (pendingPayloadBytes == 0) {
  607. + return payload;
  608. + }
  609.  
  610. assert pendingPayloadBytes >= payloadLength;
  611.  
  612. @@ -731,15 +735,9 @@
  613. }
  614.  
  615. payloadIn.readBytes(payload.bytes, 0, payloadLength);
  616. - payloadPending = false;
  617. payload.length = payloadLength;
  618. pendingPayloadBytes = 0;
  619. return payload;
  620. }
  621. -
  622. - @Override
  623. - public boolean hasPayload() {
  624. - return payloadPending && payloadLength > 0;
  625. - }
  626. }
  627. }
  628. Index: lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java
  629. ===================================================================
  630. --- lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java (revision 1372047)
  631. +++ lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java (working copy)
  632. @@ -472,19 +472,8 @@
  633.  
  634. @Override
  635. public BytesRef getPayload() {
  636. - // Some tests rely on only being able to retrieve the
  637. - // payload once
  638. - try {
  639. - return payload;
  640. - } finally {
  641. - payload = null;
  642. - }
  643. + return payload;
  644. }
  645. -
  646. - @Override
  647. - public boolean hasPayload() {
  648. - return payload != null;
  649. - }
  650. }
  651.  
  652. static class TermData {
  653. Index: lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java
  654. ===================================================================
  655. --- lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java (revision 1372047)
  656. +++ lucene/core/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java (working copy)
  657. @@ -524,16 +524,10 @@
  658.  
  659. @Override
  660. public BytesRef getPayload() {
  661. - // assert hasPayload(); // you should have called this
  662. return payloads == null ? null : payloads[nextPos-1];
  663. }
  664.  
  665. @Override
  666. - public boolean hasPayload() {
  667. - return payloads != null && payloads[nextPos-1] != null;
  668. - }
  669. -
  670. - @Override
  671. public int nextPosition() {
  672. assert (positions != null && nextPos < positions.length) ||
  673. startOffsets != null && nextPos < startOffsets.length;
  674. Index: lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java
  675. ===================================================================
  676. --- lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java (revision 1372047)
  677. +++ lucene/core/src/java/org/apache/lucene/codecs/MappingMultiDocsAndPositionsEnum.java (working copy)
  678. @@ -126,6 +126,7 @@
  679. BytesRef payload = current.getPayload();
  680. if (mergeState.currentPayloadProcessor[upto] != null && payload != null) {
  681. // to not violate the D&P api, we must give the processor a private copy
  682. + // TODO: reuse a BytesRef if there is a PPP
  683. payload = BytesRef.deepCopyOf(payload);
  684. mergeState.currentPayloadProcessor[upto].processPayload(payload);
  685. if (payload.length == 0) {
  686. @@ -135,12 +136,5 @@
  687. }
  688. return payload;
  689. }
  690. -
  691. - @Override
  692. - public boolean hasPayload() {
  693. - // TODO: note this is actually bogus if there is a payloadProcessor,
  694. - // because it might remove it: but lets just remove this method completely
  695. - return current.hasPayload();
  696. - }
  697. }
  698.  
  699. Index: lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java
  700. ===================================================================
  701. --- lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java (revision 1372047)
  702. +++ lucene/core/src/java/org/apache/lucene/codecs/pulsing/PulsingPostingsReader.java (working copy)
  703. @@ -533,18 +533,12 @@
  704. }
  705.  
  706. @Override
  707. - public boolean hasPayload() {
  708. - return storePayloads && !payloadRetrieved && payloadLength > 0;
  709. - }
  710. -
  711. - @Override
  712. public BytesRef getPayload() throws IOException {
  713. //System.out.println("PR getPayload payloadLength=" + payloadLength + " this=" + this);
  714. if (payloadRetrieved) {
  715. - throw new IOException("Either no payload exists at this term position or an attempt was made to load it more than once.");
  716. - }
  717. - payloadRetrieved = true;
  718. - if (payloadLength > 0) {
  719. + return payload;
  720. + } else if (storePayloads && payloadLength > 0) {
  721. + payloadRetrieved = true;
  722. if (payload == null) {
  723. payload = new BytesRef(payloadLength);
  724. } else {
  725. Index: lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java
  726. ===================================================================
  727. --- lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java (revision 1372047)
  728. +++ lucene/core/src/java/org/apache/lucene/codecs/TermVectorsWriter.java (working copy)
  729. @@ -271,8 +271,7 @@
  730. final int startOffset = docsAndPositionsEnum.startOffset();
  731. final int endOffset = docsAndPositionsEnum.endOffset();
  732.  
  733. - BytesRef payload = docsAndPositionsEnum.hasPayload() ?
  734. - docsAndPositionsEnum.getPayload() : null;
  735. + BytesRef payload = docsAndPositionsEnum.getPayload();
  736.  
  737. if (payloadProcessor != null && payload != null) {
  738. // to not violate the D&P api, we must give the processor a private copy
  739. Index: lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
  740. ===================================================================
  741. --- lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (revision 1372049)
  742. +++ lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (working copy)
  743. @@ -126,7 +126,7 @@
  744.  
  745. // TODO: Remove warning after API has been finalized
  746. @Override
  747. - public boolean isPayloadAvailable() {
  748. + public boolean isPayloadAvailable() throws IOException {
  749. return spans.isPayloadAvailable();
  750. }
  751.  
  752. @@ -256,7 +256,7 @@
  753.  
  754. // TODO: Remove warning after API has been finalized
  755. @Override
  756. - public boolean isPayloadAvailable() {
  757. + public boolean isPayloadAvailable() throws IOException {
  758. SpansCell pointer = min();
  759. while (pointer != null) {
  760. if (pointer.isPayloadAvailable()) {
  761. Index: lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
  762. ===================================================================
  763. --- lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (revision 1372049)
  764. +++ lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (working copy)
  765. @@ -157,7 +157,7 @@
  766.  
  767. // TODO: Remove warning after API has been finalized
  768. @Override
  769. - public boolean isPayloadAvailable() {
  770. + public boolean isPayloadAvailable() throws IOException {
  771. return includeSpans.isPayloadAvailable();
  772. }
  773.  
  774. Index: lucene/core/src/java/org/apache/lucene/search/spans/Spans.java
  775. ===================================================================
  776. --- lucene/core/src/java/org/apache/lucene/search/spans/Spans.java (revision 1372049)
  777. +++ lucene/core/src/java/org/apache/lucene/search/spans/Spans.java (working copy)
  778. @@ -82,6 +82,6 @@
  779. *
  780. * @return true if there is a payload available at this position that can be loaded
  781. */
  782. - public abstract boolean isPayloadAvailable();
  783. + public abstract boolean isPayloadAvailable() throws IOException;
  784.  
  785. }
  786. Index: lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
  787. ===================================================================
  788. --- lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (revision 1372049)
  789. +++ lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (working copy)
  790. @@ -247,7 +247,7 @@
  791. }
  792.  
  793. @Override
  794. - public boolean isPayloadAvailable() {
  795. + public boolean isPayloadAvailable() throws IOException {
  796. Spans top = top();
  797. return top != null && top.isPayloadAvailable();
  798. }
  799. Index: lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
  800. ===================================================================
  801. --- lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java (revision 1372049)
  802. +++ lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java (working copy)
  803. @@ -176,7 +176,7 @@
  804. // TODO: Remove warning after API has been finalized
  805.  
  806. @Override
  807. - public boolean isPayloadAvailable() {
  808. + public boolean isPayloadAvailable() throws IOException {
  809. return spans.isPayloadAvailable();
  810. }
  811.  
  812. Index: lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java
  813. ===================================================================
  814. --- lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java (revision 1372049)
  815. +++ lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java (working copy)
  816. @@ -36,6 +36,7 @@
  817. protected int freq;
  818. protected int count;
  819. protected int position;
  820. + protected boolean readPayload;
  821.  
  822. public TermSpans(DocsAndPositionsEnum postings, Term term) {
  823. this.postings = postings;
  824. @@ -64,6 +65,7 @@
  825. }
  826. position = postings.nextPosition();
  827. count++;
  828. + readPayload = false;
  829. return true;
  830. }
  831.  
  832. @@ -78,7 +80,7 @@
  833. count = 0;
  834. position = postings.nextPosition();
  835. count++;
  836. -
  837. + readPayload = false;
  838. return true;
  839. }
  840.  
  841. @@ -101,6 +103,7 @@
  842. @Override
  843. public Collection<byte[]> getPayload() throws IOException {
  844. final BytesRef payload = postings.getPayload();
  845. + readPayload = true;
  846. final byte[] bytes;
  847. if (payload != null) {
  848. bytes = new byte[payload.length];
  849. @@ -113,8 +116,8 @@
  850.  
  851. // TODO: Remove warning after API has been finalized
  852. @Override
  853. - public boolean isPayloadAvailable() {
  854. - return postings.hasPayload();
  855. + public boolean isPayloadAvailable() throws IOException {
  856. + return readPayload == false && postings.getPayload() != null;
  857. }
  858.  
  859. @Override
  860. Index: lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
  861. ===================================================================
  862. --- lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (revision 1372047)
  863. +++ lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (working copy)
  864. @@ -548,15 +548,10 @@
  865.  
  866. @Override
  867. public BytesRef getPayload() {
  868. - throw new UnsupportedOperationException();
  869. + return null;
  870. }
  871.  
  872. @Override
  873. - public boolean hasPayload() {
  874. - throw new UnsupportedOperationException();
  875. - }
  876. -
  877. - @Override
  878. public final int advance(int target) throws IOException {
  879. while (_queue.top() != null && target > _queue.top().docID()) {
  880. DocsAndPositionsEnum postings = _queue.pop();
  881. Index: lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
  882. ===================================================================
  883. --- lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (revision 1372047)
  884. +++ lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (working copy)
  885. @@ -118,8 +118,8 @@
  886. }
  887.  
  888. protected void processPayload(Similarity similarity) throws IOException {
  889. - final DocsAndPositionsEnum postings = termSpans.getPostings();
  890. - if (postings.hasPayload()) {
  891. + if (termSpans.isPayloadAvailable()) {
  892. + final DocsAndPositionsEnum postings = termSpans.getPostings();
  893. payload = postings.getPayload();
  894. if (payload != null) {
  895. payloadScore = function.currentScore(doc, term.field(),
  896. Index: lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java
  897. ===================================================================
  898. --- lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java (revision 1372047)
  899. +++ lucene/core/src/java/org/apache/lucene/index/FilterAtomicReader.java (working copy)
  900. @@ -307,11 +307,6 @@
  901. public BytesRef getPayload() throws IOException {
  902. return in.getPayload();
  903. }
  904. -
  905. - @Override
  906. - public boolean hasPayload() {
  907. - return in.hasPayload();
  908. - }
  909.  
  910. @Override
  911. public AttributeSource attributes() {
  912. Index: lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java
  913. ===================================================================
  914. --- lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java (revision 1372047)
  915. +++ lucene/core/src/java/org/apache/lucene/index/DocsAndPositionsEnum.java (working copy)
  916. @@ -48,11 +48,8 @@
  917. public abstract int endOffset() throws IOException;
  918.  
  919. /** Returns the payload at this position, or null if no
  920. - * payload was indexed. Only call this once per
  921. - * position. You should not modify anything (neither
  922. - * members of the returned BytesRef nor bytes in the
  923. - * byte[]). */
  924. + * payload was indexed. You should not modify anything
  925. + * (neither members of the returned BytesRef nor bytes
  926. + * in the byte[]). */
  927. public abstract BytesRef getPayload() throws IOException;
  928. -
  929. - public abstract boolean hasPayload();
  930. }
  931. Index: lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java
  932. ===================================================================
  933. --- lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java (revision 1372047)
  934. +++ lucene/core/src/java/org/apache/lucene/index/MultiDocsAndPositionsEnum.java (working copy)
  935. @@ -138,11 +138,6 @@
  936. }
  937.  
  938. @Override
  939. - public boolean hasPayload() {
  940. - return current.hasPayload();
  941. - }
  942. -
  943. - @Override
  944. public BytesRef getPayload() throws IOException {
  945. return current.getPayload();
  946. }
  947. Index: lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
  948. ===================================================================
  949. --- lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (revision 1372047)
  950. +++ lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (working copy)
  951. @@ -830,11 +830,9 @@
  952. throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " < lastPos " + lastPos);
  953. }
  954. lastPos = pos;
  955. - if (postings.hasPayload()) {
  956. - BytesRef payload = postings.getPayload();
  957. - if (payload.length < 1) {
  958. - throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " payload length is out of bounds " + payload.length);
  959. - }
  960. + BytesRef payload = postings.getPayload();
  961. + if (payload != null && payload.length < 1) {
  962. + throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " payload length is out of bounds " + payload.length);
  963. }
  964. if (hasOffsets) {
  965. int startOffset = postings.startOffset();
  966. @@ -1526,10 +1524,10 @@
  967. }
  968. }
  969.  
  970. - BytesRef payload = null;
  971. - if (postings.hasPayload()) {
  972. + BytesRef payload = postings.getPayload();
  973. +
  974. + if (payload != null) {
  975. assert vectorsHasPayload;
  976. - payload = postings.getPayload();
  977. }
  978.  
  979. if (postingsHasPayload && vectorsHasPayload) {
  980. @@ -1538,13 +1536,13 @@
  981. if (payload == null) {
  982. // we have payloads, but not at this position.
  983. // postings has payloads too, it should not have one at this position
  984. - if (postingsPostings.hasPayload()) {
  985. + if (postingsPostings.getPayload() != null) {
  986. throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has no payload but postings does: " + postingsPostings.getPayload());
  987. }
  988. } else {
  989. // we have payloads, and one at this position
  990. // postings should also have one at this position, with the same bytes.
  991. - if (!postingsPostings.hasPayload()) {
  992. + if (postingsPostings.getPayload() == null) {
  993. throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + " has payload=" + payload + " but postings does not.");
  994. }
  995. BytesRef postingsPayload = postingsPostings.getPayload();
  996. Index: lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
  997. ===================================================================
  998. --- lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (revision 1372047)
  999. +++ lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (working copy)
  1000. @@ -1016,11 +1016,6 @@
  1001. }
  1002.  
  1003. @Override
  1004. - public boolean hasPayload() {
  1005. - return false;
  1006. - }
  1007. -
  1008. - @Override
  1009. public BytesRef getPayload() {
  1010. return null;
  1011. }
Advertisement
Add Comment
Please, Sign In to add comment